Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format dates according to user locales, not language #189

Merged
merged 3 commits into from Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions modules/ui/fields/date.js
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
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());
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon code inspection, edtf.js seems to expect a single locale string here, not an array of them like the built-in functions.

} 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