From a90c15f3534e6677edfc7184fa4790b9603379cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Minh=20Nguy=E1=BB=85n?= Date: Fri, 5 Jan 2024 15:31:26 -0800 Subject: [PATCH] Format dates according to user locales, not language --- modules/ui/fields/date.js | 6 +++--- modules/validations/invalid_format.js | 6 +++--- modules/validations/mismatched_dates.js | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/ui/fields/date.js b/modules/ui/fields/date.js index 2032e6ae92..7d431109be 100644 --- a/modules/ui/fields/date.js +++ b/modules/ui/fields/date.js @@ -22,7 +22,7 @@ export function uiFieldDate(field, context) { let edtfKey = field.key + ':edtf'; - let dateTimeFormat = new Intl.DateTimeFormat(localizer.languageCode(), { + let dateTimeFormat = new Intl.DateTimeFormat(localizer.localeCodes(), { year: 'numeric', era: 'short', month: 'long', @@ -37,7 +37,7 @@ export function uiFieldDate(field, context) { * @param year A representative year within the era. */ function getEraName(year, format) { - let longFormat = new Intl.DateTimeFormat(localizer.languageCode(), { + let longFormat = new Intl.DateTimeFormat(localizer.localeCodes(), { year: 'numeric', era: format, timeZone: 'UTC', @@ -76,7 +76,7 @@ export function uiFieldDate(field, context) { /// Returns the localized name of a month in the given format. function getMonthName(month, format) { - let longFormat = new Intl.DateTimeFormat(localizer.languageCode(), { + let longFormat = new Intl.DateTimeFormat(localizer.localeCodes(), { month: format, timeZone: 'UTC', }); diff --git a/modules/validations/invalid_format.js b/modules/validations/invalid_format.js index eaf7c292b4..d567ded123 100644 --- a/modules/validations/invalid_format.js +++ b/modules/validations/invalid_format.js @@ -41,7 +41,7 @@ export function validationFormatting() { let alternatives = []; if (normalized !== null) { - let label = normalized.date.toLocaleDateString(localizer.languageCode(), normalized.localeOptions); + let label = normalized.date.toLocaleDateString(localizer.localeCodes(), normalized.localeOptions); alternatives.push({ date: normalized.value, label: label || normalized.value, @@ -51,7 +51,7 @@ export function validationFormatting() { if (edtfFromOSM) { let label; try { - label = edtf.default(edtfFromOSM).format(localizer.languageCode()); + label = edtf.default(edtfFromOSM).format(localizer.localeCode()); } catch (e) { label = edtfFromOSM; } @@ -105,7 +105,7 @@ export function validationFormatting() { if (parserError.offset && parserError.token) { message = t.append('issues.invalid_format.edtf.reference', { token: parserError.token.value, - position: (parserError.offset + 1).toLocaleString(localizer.languageCode()), + position: (parserError.offset + 1).toLocaleString(localizer.localeCodes()), }); } else if (parserError.message) { message = selection => selection.append('span') diff --git a/modules/validations/mismatched_dates.js b/modules/validations/mismatched_dates.js index 6cd060011a..c050760243 100644 --- a/modules/validations/mismatched_dates.js +++ b/modules/validations/mismatched_dates.js @@ -66,7 +66,7 @@ export function validationMismatchedDates() { sortedDates.sort(); fixes.push(...sortedDates.map(value => { let normalized = utilNormalizeDateString(value); - let localeDateString = normalized.date.toLocaleDateString(localizer.languageCode(), normalized.localeOptions); + let localeDateString = normalized.date.toLocaleDateString(localizer.localeCodes(), normalized.localeOptions); return new validationIssueFix({ title: t.append('issues.fix.reformat_date.title', { date: localeDateString }), onClick: function(context) {