From 99f792102382b990ac9c7b9d707c3deb1ab93032 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Nilsved?= Date: Sat, 16 Dec 2023 14:39:48 +0100 Subject: [PATCH] Return UTC if system reported a short form timezone name Closes #85 --- utils/localTimezone.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/utils/localTimezone.ts b/utils/localTimezone.ts index f64259d..c1d29bf 100644 --- a/utils/localTimezone.ts +++ b/utils/localTimezone.ts @@ -1,6 +1,6 @@ /** * Get the name of the system timezone, and fallback to `"UTC"` if the system - * doesn't expose a timezone. + * doesn't expose a named timezone. * * This is useful for setting the initial value of an HTML input where the user * enters their timezone, or in a UI where the user has no option of selecting a @@ -9,5 +9,6 @@ * @category Timezones */ export function localTimezone(): string { - return Intl.DateTimeFormat()?.resolvedOptions()?.timeZone || "UTC"; + const tz = Intl.DateTimeFormat()?.resolvedOptions()?.timeZone; + return tz?.includes("/") ? tz : "UTC"; }