2020-10-01 15:07:15 +02:00
|
|
|
import { DateTimeFormatOptions } from "vue-i18n";
|
|
|
|
|
2019-09-09 09:31:08 +02:00
|
|
|
function parseDateTime(value: string): Date {
|
|
|
|
return new Date(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
function formatDateString(value: string): string {
|
2020-02-18 08:57:00 +01:00
|
|
|
return parseDateTime(value).toLocaleString(undefined, {
|
|
|
|
weekday: "long",
|
|
|
|
year: "numeric",
|
|
|
|
month: "long",
|
|
|
|
day: "numeric",
|
|
|
|
});
|
2019-09-09 09:31:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function formatTimeString(value: string): string {
|
2020-02-18 08:57:00 +01:00
|
|
|
return parseDateTime(value).toLocaleTimeString(undefined, { hour: "numeric", minute: "numeric" });
|
2019-09-09 09:31:08 +02:00
|
|
|
}
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
function formatDateTimeString(value: string, showTime = true): string {
|
2020-10-01 15:07:15 +02:00
|
|
|
const options: DateTimeFormatOptions = {
|
|
|
|
weekday: undefined,
|
2020-02-18 08:57:00 +01:00
|
|
|
year: "numeric",
|
|
|
|
month: "long",
|
|
|
|
day: "numeric",
|
2020-10-01 15:07:15 +02:00
|
|
|
hour: undefined,
|
|
|
|
minute: undefined,
|
2020-02-18 08:57:00 +01:00
|
|
|
};
|
2019-10-14 19:29:18 +02:00
|
|
|
if (showTime) {
|
2020-10-01 15:07:15 +02:00
|
|
|
options.weekday = "long";
|
2020-02-18 08:57:00 +01:00
|
|
|
options.hour = "numeric";
|
|
|
|
options.minute = "numeric";
|
2019-10-14 19:29:18 +02:00
|
|
|
}
|
2020-10-01 15:07:15 +02:00
|
|
|
const format = new Intl.DateTimeFormat(undefined, options);
|
|
|
|
return format.format(parseDateTime(value));
|
2019-09-09 09:31:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
export { formatDateString, formatTimeString, formatDateTimeString };
|