Add timezone handling

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-10-10 16:25:50 +02:00
parent eba3c70c9b
commit d58ca5743d
49 changed files with 1218 additions and 429 deletions

View File

@@ -14,10 +14,11 @@ function formatDateString(value: string): string {
});
}
function formatTimeString(value: string): string {
function formatTimeString(value: string, timeZone: string): string {
return parseDateTime(value).toLocaleTimeString(locale(), {
hour: "numeric",
minute: "numeric",
timeZone,
});
}
@@ -55,6 +56,7 @@ const SHORT_TIME_FORMAT_OPTIONS: DateTimeFormatOptions = {
function formatDateTimeString(
value: string,
timeZone: string | undefined = undefined,
showTime = true,
dateFormat = "long"
): string {
@@ -66,6 +68,7 @@ function formatDateTimeString(
options = {
...options,
...(isLongFormat ? LONG_TIME_FORMAT_OPTIONS : SHORT_TIME_FORMAT_OPTIONS),
timeZone,
};
}
const format = new Intl.DateTimeFormat(locale(), options);