Update date formatting to use default locale as specified by Intl browser API rather than navigator language
This commit is contained in:
parent
7c263d940a
commit
67863da655
|
@ -186,30 +186,26 @@ export const stringifyDate = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the correct format for a date in a specific locale
|
// Determine the dayjs-compatible format of the browser's default locale
|
||||||
const getDateFormatPattern = locale => {
|
const getPatternForPart = part => {
|
||||||
const getPatternForPart = part => {
|
switch (part.type) {
|
||||||
switch (part.type) {
|
case "day":
|
||||||
case "day":
|
return "D".repeat(part.value.length)
|
||||||
return "D".repeat(part.value.length)
|
case "month":
|
||||||
case "month":
|
return "M".repeat(part.value.length)
|
||||||
return "M".repeat(part.value.length)
|
case "year":
|
||||||
case "year":
|
return "Y".repeat(part.value.length)
|
||||||
return "Y".repeat(part.value.length)
|
case "literal":
|
||||||
case "literal":
|
return part.value
|
||||||
return part.value
|
default:
|
||||||
default:
|
console.log("Unsupported date part", part)
|
||||||
console.log("Unsupported date part", part)
|
return ""
|
||||||
return ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return new Intl.DateTimeFormat(locale)
|
|
||||||
.formatToParts(new Date("2021-01-01"))
|
|
||||||
.map(getPatternForPart)
|
|
||||||
.join("")
|
|
||||||
}
|
}
|
||||||
|
const localeDateFormat = new Intl.DateTimeFormat()
|
||||||
const localeDateFormat = getDateFormatPattern(navigator.language || "en-US")
|
.formatToParts(new Date("2021-01-01"))
|
||||||
|
.map(getPatternForPart)
|
||||||
|
.join("")
|
||||||
|
|
||||||
// Formats a dayjs date according to schema flags
|
// Formats a dayjs date according to schema flags
|
||||||
export const getDateDisplayValue = (
|
export const getDateDisplayValue = (
|
||||||
|
@ -224,6 +220,6 @@ export const getDateDisplayValue = (
|
||||||
} else if (!enableTime) {
|
} else if (!enableTime) {
|
||||||
return value.format(localeDateFormat)
|
return value.format(localeDateFormat)
|
||||||
} else {
|
} else {
|
||||||
return value.format(`${localeDateFormat}, HH:mm`)
|
return value.format(`${localeDateFormat} HH:mm`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue