Make sure the localized datetime follow the current MBZ locale

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2021-03-08 18:37:25 +01:00
parent 2b626d1620
commit 6ccad5344c
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773

View File

@ -1,11 +1,12 @@
import { DateTimeFormatOptions } from "vue-i18n";
import { i18n } from "../utils/i18n";
function parseDateTime(value: string): Date {
return new Date(value);
}
function formatDateString(value: string): string {
return parseDateTime(value).toLocaleString(undefined, {
return parseDateTime(value).toLocaleString(locale(), {
weekday: "long",
year: "numeric",
month: "long",
@ -14,7 +15,7 @@ function formatDateString(value: string): string {
}
function formatTimeString(value: string): string {
return parseDateTime(value).toLocaleTimeString(undefined, {
return parseDateTime(value).toLocaleTimeString(locale(), {
hour: "numeric",
minute: "numeric",
});
@ -34,8 +35,10 @@ function formatDateTimeString(value: string, showTime = true): string {
options.hour = "numeric";
options.minute = "numeric";
}
const format = new Intl.DateTimeFormat(undefined, options);
const format = new Intl.DateTimeFormat(locale(), options);
return format.format(parseDateTime(value));
}
const locale = () => i18n.locale.replace("_", "-");
export { formatDateString, formatTimeString, formatDateTimeString };