Skip to content

Commit

Permalink
Fix: Unknown local iana (#3837)
Browse files Browse the repository at this point in the history
  • Loading branch information
djbarnwal authored Jan 11, 2024
1 parent 26d6a1c commit da11ba2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
// Add local and utc time zone to the top of the list
$: availableTimeZones = [userLocalIANA, UTCIana, ...availableTimeZones];
// If localIANA is same as UTC, remove UTC from the list
$: if (userLocalIANA === UTCIana) {
availableTimeZones = availableTimeZones.slice(1);
}
const onTimeZoneSelect = (timeZone: string) => {
dispatch("select-time-zone", { timeZone });
};
Expand Down
6 changes: 5 additions & 1 deletion web-common/src/lib/time/timezone/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ export function removeZoneOffset(dt: Date, iana: string) {
}

export function getLocalIANA(): string {
return Intl.DateTimeFormat().resolvedOptions().timeZone;
const localIANA = Intl.DateTimeFormat().resolvedOptions().timeZone;
const zone = DateTime.local().setZone(localIANA);

if (zone.isValid) return localIANA;
else return getUTCIANA();
}

export function getUTCIANA(): string {
Expand Down

1 comment on commit da11ba2

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.