Merge branch 'fix-locale-datetime' into 'master'

Make sure the localized datetime follow the current MBZ locale

Closes #629

See merge request framasoft/mobilizon!848
This commit is contained in:
Thomas Citharel 2021-03-09 08:40:50 +00:00
commit 66af4e2edf

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 };