Skip to content

Commit

Permalink
Merge pull request #86 from bjuppa/avoid-local-timezone-short-form
Browse files Browse the repository at this point in the history
Return UTC if system reported a short form timezone name
  • Loading branch information
bjuppa authored Dec 16, 2023
2 parents d2a0eac + 99f7921 commit d020126
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 d020126

Please sign in to comment.