Skip to content

Commit

Permalink
Format dates according to user locales, not language
Browse files Browse the repository at this point in the history
  • Loading branch information
1ec5 committed Jan 5, 2024
1 parent a69476d commit a90c15f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions modules/ui/fields/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down Expand Up @@ -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',
});
Expand Down
6 changes: 3 additions & 3 deletions modules/validations/invalid_format.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion modules/validations/mismatched_dates.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit a90c15f

Please sign in to comment.