From 07eeae84867414cbbfca611bb9b6eb66d7a77cac Mon Sep 17 00:00:00 2001 From: Maurice Date: Mon, 23 Nov 2026 19:42:40 +0100 Subject: [PATCH] fix(dashboard): name Etc/GMT world clocks by their real offset An Etc/GMT zone counts westward as positive, so Etc/GMT-4 is four hours ahead of UTC. The clock's title and the zone picker printed the id's own sign, and someone who picked GMT+4 got a clock four hours behind UTC; both now read the real offset, on the desktop and the phone. Closes #3175 --- .../Dashboard/useDashboardTimezones.test.ts | 18 +++++++++++++++++- .../Dashboard/useDashboardTimezones.ts | 18 ++++++++++++++++++ .../mobile/screens/dashboard/MDashWidgets.tsx | 4 ++-- client/src/pages/DashboardPage.tsx | 4 ++-- 4 files changed, 39 insertions(+), 5 deletions(-) diff --git a/client/src/components/Dashboard/useDashboardTimezones.test.ts b/client/src/components/Dashboard/useDashboardTimezones.test.ts index b5580930f..28a75eb7d 100644 --- a/client/src/components/Dashboard/useDashboardTimezones.test.ts +++ b/client/src/components/Dashboard/useDashboardTimezones.test.ts @@ -2,7 +2,7 @@ import { act, renderHook, waitFor } from '@testing-library/react'; import { useSettingsStore } from '../../store/settingsStore'; -import { shortZone, useDashboardTimezones } from './useDashboardTimezones'; +import { shortZone, useDashboardTimezones, zoneOptionLabel } from './useDashboardTimezones'; const updateSetting = vi.fn<(key: string, value: unknown) => Promise>(); const home = Intl.DateTimeFormat().resolvedOptions().timeZone; @@ -32,6 +32,22 @@ describe('shortZone', () => { }); }); +describe('Etc/GMT zones (#3175)', () => { + it('FE-COMP-TZHOOK-010: names an Etc/GMT zone by its real offset, which is the opposite of the sign in its id', () => { + expect(shortZone('Etc/GMT-4')).toBe('GMT+4'); + expect(shortZone('Etc/GMT+4')).toBe('GMT-4'); + expect(shortZone('Etc/GMT-14')).toBe('GMT+14'); + expect(shortZone('Etc/GMT+0')).toBe('GMT'); + expect(shortZone('Etc/UTC')).toBe('UTC'); + }); + + it('FE-COMP-TZHOOK-011: the picker lists an Etc/GMT zone under its real offset and every other zone by its id', () => { + expect(zoneOptionLabel('Etc/GMT-4')).toBe('GMT+4'); + expect(zoneOptionLabel('Etc/GMT+4')).toBe('GMT-4'); + expect(zoneOptionLabel('America/New_York')).toBe('America/New York'); + }); +}); + describe('useDashboardTimezones', () => { it('FE-COMP-TZHOOK-002: an unset list falls back to home plus the defaults, a stored one is honoured', () => { const fallback = renderHook(() => useDashboardTimezones('en')); diff --git a/client/src/components/Dashboard/useDashboardTimezones.ts b/client/src/components/Dashboard/useDashboardTimezones.ts index a2da83bb0..a576e7b90 100644 --- a/client/src/components/Dashboard/useDashboardTimezones.ts +++ b/client/src/components/Dashboard/useDashboardTimezones.ts @@ -28,12 +28,30 @@ const FALLBACK_ZONES = [ 'UTC', ]; +// Etc/GMT±N counts westward as positive (POSIX), so Etc/GMT-4 is four hours ahead of UTC. +const ETC_GMT = /^Etc\/GMT([+-])(\d{1,2})$/; + +/** The real offset of an Etc/GMT zone (Etc/GMT-4 reads GMT+4), or null for any other zone. */ +function etcGmtLabel(tz: string): string | null { + const match = ETC_GMT.exec(tz); + if (!match) return null; + if (Number(match[2]) === 0) return 'GMT'; + return `GMT${match[1] === '+' ? '-' : '+'}${match[2]}`; +} + /** The city part of a zone id, so America/New_York reads New York. */ export function shortZone(tz: string): string { + const etc = etcGmtLabel(tz); + if (etc) return etc; const city = tz.split('/').pop() || tz; return city.replace(/_/g, ' '); } +/** How the zone picker lists a zone: its id, with Etc/GMT zones under their real offset. */ +export function zoneOptionLabel(tz: string): string { + return etcGmtLabel(tz) ?? tz.replace(/_/g, ' '); +} + /** * The dashboard's world clocks: the zone list lives in the user's settings, the * clocks tick every 30 seconds, `adding` toggles the zone picker. diff --git a/client/src/mobile/screens/dashboard/MDashWidgets.tsx b/client/src/mobile/screens/dashboard/MDashWidgets.tsx index 0521170b7..f9eb12470 100644 --- a/client/src/mobile/screens/dashboard/MDashWidgets.tsx +++ b/client/src/mobile/screens/dashboard/MDashWidgets.tsx @@ -10,7 +10,7 @@ import { useAddonStore } from '../../../store/addonStore' import { entityGradient } from '../../../utils/gradients' import { useCurrencyConverter } from '../../../components/Dashboard/useCurrencyConverter' import { useCollectionLists } from '../../../components/Dashboard/useCollectionLists' -import { shortZone, useDashboardTimezones } from '../../../components/Dashboard/useDashboardTimezones' +import { shortZone, useDashboardTimezones, zoneOptionLabel } from '../../../components/Dashboard/useDashboardTimezones' import { formatTime, splitReservationDateTime } from '../../../utils/formatters' import { normalizeAppearance, MOBILE_DASH_TOKENS, type MobileDashToken } from '@trek/shared' import { MOMENT_LABEL, upcomingKey, type UpcomingReservation } from '../../../pages/dashboard/dashboardModel' @@ -231,7 +231,7 @@ function MTimezonesWidget(): React.ReactElement { > {allZones.filter(z => !zones.includes(z)).map(z => ( - + ))} )} diff --git a/client/src/pages/DashboardPage.tsx b/client/src/pages/DashboardPage.tsx index 245fed2d2..fa0c5ed74 100644 --- a/client/src/pages/DashboardPage.tsx +++ b/client/src/pages/DashboardPage.tsx @@ -25,7 +25,7 @@ import { IcsSubscribeModal } from '../components/Planner/IcsSubscribeModal' import CollectionsWidget from '../components/Dashboard/CollectionsWidget' import { useCurrencyConverter } from '../components/Dashboard/useCurrencyConverter' import { useDashboardPlugins } from '../components/Dashboard/useDashboardPlugins' -import { shortZone, useDashboardTimezones } from '../components/Dashboard/useDashboardTimezones' +import { shortZone, useDashboardTimezones, zoneOptionLabel } from '../components/Dashboard/useDashboardTimezones' import PluginWidgets from '../components/Plugins/PluginWidgets' import PluginFrame from '../components/Plugins/PluginFrame' import { TripCardBadges } from '../components/Plugins/TripCardBadges' @@ -701,7 +701,7 @@ function TimezoneTool({ locale }: { locale: string }): React.ReactElement { const tzOptions = allZones .filter(z => !zones.includes(z)) - .map(z => ({ value: z, label: z.replace(/_/g, ' '), searchLabel: z })) + .map(z => ({ value: z, label: zoneOptionLabel(z), searchLabel: `${z} ${zoneOptionLabel(z)}` })) return (