diff --git a/src/common/datetime/format_date_time.ts b/src/common/datetime/format_date_time.ts index 812e211cfb..3310de0291 100644 --- a/src/common/datetime/format_date_time.ts +++ b/src/common/datetime/format_date_time.ts @@ -13,14 +13,19 @@ export const formatDateTime = (dateObj: Date, locale: FrontendLocaleData) => const formatDateTimeMem = memoizeOne( (locale: FrontendLocaleData) => - new Intl.DateTimeFormat(locale.language, { - year: "numeric", - month: "long", - day: "numeric", - hour: useAmPm(locale) ? "numeric" : "2-digit", - minute: "2-digit", - hour12: useAmPm(locale), - }) + new Intl.DateTimeFormat( + locale.language === "en" && !useAmPm(locale) + ? "en-u-hc-h23" + : locale.language, + { + year: "numeric", + month: "long", + day: "numeric", + hour: useAmPm(locale) ? "numeric" : "2-digit", + minute: "2-digit", + hour12: useAmPm(locale), + } + ) ); // August 9, 2021, 8:23:15 AM @@ -31,15 +36,20 @@ export const formatDateTimeWithSeconds = ( const formatDateTimeWithSecondsMem = memoizeOne( (locale: FrontendLocaleData) => - new Intl.DateTimeFormat(locale.language, { - year: "numeric", - month: "long", - day: "numeric", - hour: useAmPm(locale) ? "numeric" : "2-digit", - minute: "2-digit", - second: "2-digit", - hour12: useAmPm(locale), - }) + new Intl.DateTimeFormat( + locale.language === "en" && !useAmPm(locale) + ? "en-u-hc-h23" + : locale.language, + { + year: "numeric", + month: "long", + day: "numeric", + hour: useAmPm(locale) ? "numeric" : "2-digit", + minute: "2-digit", + second: "2-digit", + hour12: useAmPm(locale), + } + ) ); // 9/8/2021, 8:23 AM @@ -50,12 +60,17 @@ export const formatDateTimeNumeric = ( const formatDateTimeNumericMem = memoizeOne( (locale: FrontendLocaleData) => - new Intl.DateTimeFormat(locale.language, { - year: "numeric", - month: "numeric", - day: "numeric", - hour: "numeric", - minute: "2-digit", - hour12: useAmPm(locale), - }) + new Intl.DateTimeFormat( + locale.language === "en" && !useAmPm(locale) + ? "en-u-hc-h23" + : locale.language, + { + year: "numeric", + month: "numeric", + day: "numeric", + hour: "numeric", + minute: "2-digit", + hour12: useAmPm(locale), + } + ) ); diff --git a/src/common/datetime/format_time.ts b/src/common/datetime/format_time.ts index 3ea3718fba..c49afc7f56 100644 --- a/src/common/datetime/format_time.ts +++ b/src/common/datetime/format_time.ts @@ -13,11 +13,16 @@ export const formatTime = (dateObj: Date, locale: FrontendLocaleData) => const formatTimeMem = memoizeOne( (locale: FrontendLocaleData) => - new Intl.DateTimeFormat(locale.language, { - hour: "numeric", - minute: "2-digit", - hour12: useAmPm(locale), - }) + new Intl.DateTimeFormat( + locale.language === "en" && !useAmPm(locale) + ? "en-u-hc-h23" + : locale.language, + { + hour: "numeric", + minute: "2-digit", + hour12: useAmPm(locale), + } + ) ); // 9:15:24 PM || 21:15:24 @@ -28,12 +33,17 @@ export const formatTimeWithSeconds = ( const formatTimeWithSecondsMem = memoizeOne( (locale: FrontendLocaleData) => - new Intl.DateTimeFormat(locale.language, { - hour: useAmPm(locale) ? "numeric" : "2-digit", - minute: "2-digit", - second: "2-digit", - hour12: useAmPm(locale), - }) + new Intl.DateTimeFormat( + locale.language === "en" && !useAmPm(locale) + ? "en-u-hc-h23" + : locale.language, + { + hour: useAmPm(locale) ? "numeric" : "2-digit", + minute: "2-digit", + second: "2-digit", + hour12: useAmPm(locale), + } + ) ); // Tuesday 7:00 PM || Tuesday 19:00 @@ -42,10 +52,15 @@ export const formatTimeWeekday = (dateObj: Date, locale: FrontendLocaleData) => const formatTimeWeekdayMem = memoizeOne( (locale: FrontendLocaleData) => - new Intl.DateTimeFormat(locale.language, { - weekday: "long", - hour: useAmPm(locale) ? "numeric" : "2-digit", - minute: "2-digit", - hour12: useAmPm(locale), - }) + new Intl.DateTimeFormat( + locale.language === "en" && !useAmPm(locale) + ? "en-u-hc-h23" + : locale.language, + { + weekday: "long", + hour: useAmPm(locale) ? "numeric" : "2-digit", + minute: "2-digit", + hour12: useAmPm(locale), + } + ) );