Skip to content

Commit

Permalink
Return UTC if system reported a short form timezone name
Browse files Browse the repository at this point in the history
Closes #85
  • Loading branch information
bjuppa committed Dec 16, 2023
1 parent d2a0eac commit 99f7921
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions utils/localTimezone.ts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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";
}

0 comments on commit 99f7921

Please sign in to comment.