From d42ac60d61701ada80985932316bc04ae720e081 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Fri, 28 Apr 2023 16:29:13 -0700 Subject: [PATCH] scheduled_message: Fix i18n for scheduled time. --- web/src/popover_menus.js | 3 ++- web/src/timerender.ts | 5 +++-- web/tests/timerender.test.js | 3 +++ 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/web/src/popover_menus.js b/web/src/popover_menus.js index 68ca6bc47a..9fd88a4b7f 100644 --- a/web/src/popover_menus.js +++ b/web/src/popover_menus.js @@ -44,6 +44,7 @@ import * as settings_data from "./settings_data"; import * as starred_messages from "./starred_messages"; import * as starred_messages_ui from "./starred_messages_ui"; import * as stream_popover from "./stream_popover"; +import * as timerender from "./timerender"; import {parse_html} from "./ui_util"; import * as unread_ops from "./unread_ops"; import {user_settings} from "./user_settings"; @@ -92,7 +93,7 @@ export function get_formatted_selected_send_later_time() { if (!selected_send_later_time) { return undefined; } - return format(new Date(selected_send_later_time), "MMM d yyyy 'at' h:mm a"); + return timerender.get_full_datetime(selected_send_later_time, "time"); } export function reset_selected_schedule_time() { diff --git a/web/src/timerender.ts b/web/src/timerender.ts index 5e02343a08..b9dca116fe 100644 --- a/web/src/timerender.ts +++ b/web/src/timerender.ts @@ -444,10 +444,11 @@ export function absolute_time(timestamp: number, today = new Date()): string { ); } -export function get_full_datetime(time: Date): string { +// Pass time_format="time" to not include seconds in the time format. +export function get_full_datetime(time: Date, time_format: TimeFormat = "time_sec"): string { const locale = get_user_locale(); const date_string = time.toLocaleDateString(locale); - let time_string = get_localized_date_or_time_for_format(time, "time_sec"); + let time_string = get_localized_date_or_time_for_format(time, time_format); const tz_offset_str = get_tz_with_UTC_offset(time); diff --git a/web/tests/timerender.test.js b/web/tests/timerender.test.js index 6398e8b2b8..55e9d28e88 100644 --- a/web/tests/timerender.test.js +++ b/web/tests/timerender.test.js @@ -448,6 +448,9 @@ run_test("get_full_datetime", () => { let expected = "translated: 5/18/2017 at 9:12:53 PM UTC"; assert.equal(timerender.get_full_datetime(time), expected); + expected = "translated: 5/18/2017 at 9:12 PM UTC"; + assert.equal(timerender.get_full_datetime(time, "time"), expected); + // test 24 hour time setting. user_settings.twenty_four_hour_time = true; expected = "translated: 5/18/2017 at 21:12:53 UTC";