diff --git a/web-common/src/features/dashboards/time-controls/TimeZoneSelector.svelte b/web-common/src/features/dashboards/time-controls/TimeZoneSelector.svelte index 1df56e1d8e1..e6de6586e05 100644 --- a/web-common/src/features/dashboards/time-controls/TimeZoneSelector.svelte +++ b/web-common/src/features/dashboards/time-controls/TimeZoneSelector.svelte @@ -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 }); }; diff --git a/web-common/src/lib/time/timezone/index.ts b/web-common/src/lib/time/timezone/index.ts index 20df8a03445..6a582d32346 100644 --- a/web-common/src/lib/time/timezone/index.ts +++ b/web-common/src/lib/time/timezone/index.ts @@ -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 {