Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

fix(studio): show correct timezone offsets FE-4612 (#51484)

Jordi Enricd1e0b551c54a
diff --git a/apps/studio/components/interfaces/Account/Preferences/TimezoneSettings.tsx b/apps/studio/components/interfaces/Account/Preferences/TimezoneSettings.tsx
index e7be5ec816a..dd73ab52ba3 100644
--- a/apps/studio/components/interfaces/Account/Preferences/TimezoneSettings.tsx
+++ b/apps/studio/components/interfaces/Account/Preferences/TimezoneSettings.tsx
@@ -26,7 +26,11 @@ import {
PageSectionTitle,
} from 'ui-patterns/PageSection'
-import { findTimezoneByIana, TIMEZONES_BY_IANA } from '@/lib/constants/timezones'
+import {
+ getTimezoneLabel,
+ getTimezoneLabelByIana,
+ TIMEZONES_BY_IANA,
+} from '@/lib/constants/timezones'
import { useTimezone } from '@/lib/datetime'
import { guessLocalTimezone } from '@/lib/dayjs'
import { useTrack } from '@/lib/telemetry/track'
@@ -44,7 +48,7 @@ export const TimezoneSettings = () => {
// option will revert to.
const browserTimezone = useMemo(() => guessLocalTimezone(), [])
- const triggerLabel = useMemo(() => findTimezoneByIana(timezone)?.text ?? timezone, [timezone])
+ const triggerLabel = useMemo(() => getTimezoneLabelByIana(timezone), [timezone])
const handleSelect = (nextStored: string) => {
setTimezone(nextStored)
@@ -130,10 +134,10 @@ export const TimezoneSettings = () => {
key={ianaName}
// CommandItem matches against the `value` prop for the input filter — include
// both the human label and the IANA name so search works for either.
- value={`${entry.text} ${ianaName}`}
+ value={`${getTimezoneLabel(entry)} ${ianaName}`}
onSelect={() => handleSelect(ianaName)}
>
- {entry.text}
+ {getTimezoneLabel(entry)}
<CheckIcon
className={cn(
'ml-auto h-4 w-4',
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/PITR.constants.ts b/apps/studio/components/interfaces/Database/Backups/PITR/PITR.constants.ts
deleted file mode 100644
index 08ee0bb3b29..00000000000
--- a/apps/studio/components/interfaces/Database/Backups/PITR/PITR.constants.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-// Re-export from the shared location. The full timezone catalog now lives in
-// `lib/constants/timezones.ts` so it can be consumed outside of PITR.
-export { ALL_TIMEZONES } from '@/lib/constants/timezones'
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/PITR.types.ts b/apps/studio/components/interfaces/Database/Backups/PITR/PITR.types.ts
index 7787003f9b4..2e622c97062 100644
--- a/apps/studio/components/interfaces/Database/Backups/PITR/PITR.types.ts
+++ b/apps/studio/components/interfaces/Database/Backups/PITR/PITR.types.ts
@@ -1,12 +1,3 @@
-export interface Timezone {
- value: string
- abbr: string
- offset: number
- isdst: boolean
- text: string
- utc: string[]
-}
-
export interface Time {
h: number
m: number
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts b/apps/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts
index d47e74d077c..436630b98bf 100644
--- a/apps/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts
+++ b/apps/studio/components/interfaces/Database/Backups/PITR/PITR.utils.ts
@@ -1,8 +1,8 @@
import dayjs from 'dayjs'
-import { ALL_TIMEZONES } from './PITR.constants'
import type { Time } from './PITR.types'
import type { ProjectSelectedAddon } from '@/data/subscriptions/types'
+import { findTimezoneByIana, TIMEZONES_BY_IANA } from '@/lib/constants/timezones'
import { guessLocalTimezone } from '@/lib/dayjs'
export const getPITRRetentionDuration = (addons: ProjectSelectedAddon[]) => {
@@ -19,13 +19,8 @@ export const getDatesBetweenRange = (startDate: dayjs.Dayjs, endDate: dayjs.Dayj
}
export const getClientTimezone = () => {
- const defaultTz = guessLocalTimezone()
- const utcTz = ALL_TIMEZONES.find((option) => option.value === 'UTC')
- const timezone = ALL_TIMEZONES.find((option) => {
- if (option.utc.includes(defaultTz)) return option
- else return undefined
- })
- return timezone ?? (utcTz || ALL_TIMEZONES[0])
+ const utcTimezone = TIMEZONES_BY_IANA.find((option) => option.value === 'UTC')
+ return findTimezoneByIana(guessLocalTimezone()) ?? utcTimezone ?? TIMEZONES_BY_IANA[0]
}
export const formatNumberToTwoDigits = (number: Number) => {
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/PITRForm.tsx b/apps/studio/components/interfaces/Database/Backups/PITR/PITRForm.tsx
index 7a55dd2552c..e73b912a5aa 100644
--- a/apps/studio/components/interfaces/Database/Backups/PITR/PITRForm.tsx
+++ b/apps/studio/components/interfaces/Database/Backups/PITR/PITRForm.tsx
@@ -3,7 +3,6 @@ import { HelpCircle } from 'lucide-react'
import { useMemo, useState } from 'react'
import { Calendar, cn } from 'ui'
-import { type Timezone } from './PITR.types'
import {
constrainDateToRange,
formatNumberToTwoDigits,
@@ -15,6 +14,7 @@ import { TimezoneSelection } from './TimezoneSelection'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { FormPanel } from '@/components/ui/Forms/FormPanel'
import InformationBox from '@/components/ui/InformationBox'
+import type { Timezone } from '@/lib/constants/timezones'
type Props = {
onSubmit: (data: {
@@ -179,6 +179,7 @@ export function PITRForm({
<div className="w-[350px]">
<TimezoneSelection
selectedTimezone={selectedTimezone}
+ date={selectedDate}
onSelectTimezone={setSelectedTimezone}
/>
</div>
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx b/apps/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx
index fbc58643165..d6317aaf6bf 100644
--- a/apps/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx
+++ b/apps/studio/components/interfaces/Database/Backups/PITR/PITRSelection.tsx
@@ -1,4 +1,5 @@
import { useParams } from 'common'
+import dayjs from 'dayjs'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useState } from 'react'
@@ -22,7 +23,6 @@ import {
import { BackupsEmpty } from '../BackupsEmpty'
import { BackupsStorageAlert } from '../BackupsStorageAlert'
-import type { Timezone } from './PITR.types'
import { getClientTimezone } from './PITR.utils'
import { PITRForm } from './PITRForm'
import PITRStatus from './PITRStatus'
@@ -32,6 +32,7 @@ import { usePitrRestoreMutation } from '@/data/database/pitr-restore-mutation'
import { useSetProjectStatus } from '@/data/projects/project-detail-query'
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
import { PROJECT_STATUS } from '@/lib/constants'
+import { getTimezoneLabel, type Timezone } from '@/lib/constants/timezones'
export const PITRSelection = () => {
const router = useRouter()
@@ -135,7 +136,11 @@ export const PITRSelection = () => {
<div className="py-2 flex flex-col gap-3">
<div>
<p className="text-sm font-mono text-foreground-lighter">
- {selectedRecoveryPoint?.selectedTimezone.text}
+ {selectedRecoveryPoint &&
+ getTimezoneLabel(
+ selectedRecoveryPoint.selectedTimezone,
+ dayjs.unix(selectedRecoveryPoint.recoveryTimeTargetUnix)
+ )}
</p>
<p className="text-2xl">{selectedRecoveryPoint?.recoveryTimeString}</p>
</div>
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx b/apps/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx
index 623380197d0..ccee55b411c 100644
--- a/apps/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx
+++ b/apps/studio/components/interfaces/Database/Backups/PITR/PITRStatus.tsx
@@ -3,13 +3,13 @@ import { useParams } from 'common'
import dayjs from 'dayjs'
import { AlertCircle } from 'lucide-react'
-import type { Timezone } from './PITR.types'
import { TimezoneSelection } from './TimezoneSelection'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { FormPanel } from '@/components/ui/Forms/FormPanel'
import { useBackupsQuery } from '@/data/database/backups-query'
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
+import type { Timezone } from '@/lib/constants/timezones'
interface PITRStatusProps {
selectedTimezone: Timezone
@@ -82,6 +82,7 @@ const PITRStatus = ({
<div className="w-[350px]">
<TimezoneSelection
selectedTimezone={selectedTimezone}
+ date={dayjs.unix(latestPhysicalBackupDateUnix ?? 0)}
onSelectTimezone={onUpdateTimezone}
/>
</div>
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/TimezoneSelection.test.tsx b/apps/studio/components/interfaces/Database/Backups/PITR/TimezoneSelection.test.tsx
new file mode 100644
index 00000000000..858d534a51b
--- /dev/null
+++ b/apps/studio/components/interfaces/Database/Backups/PITR/TimezoneSelection.test.tsx
@@ -0,0 +1,56 @@
+import { screen } from '@testing-library/react'
+import userEvent from '@testing-library/user-event'
+import dayjs from 'dayjs'
+import { mockAnimationsApi } from 'jsdom-testing-mocks'
+import { describe, expect, test, vi } from 'vitest'
+
+import { TimezoneSelection } from './TimezoneSelection'
+import { findTimezoneByIana } from '@/lib/constants/timezones'
+import { customRender } from '@/tests/lib/custom-render'
+
+mockAnimationsApi()
+
+describe('TimezoneSelection', () => {
+ test('updates Madrid offsets when the restore date crosses daylight saving time and preserves the selected timezone', async () => {
+ const madridTimezone = findTimezoneByIana('Europe/Madrid')
+ if (!madridTimezone) throw new Error('Madrid timezone is missing from the timezone catalog')
+
+ const user = userEvent.setup()
+ const onSelectTimezone = vi.fn()
+ const winterLabel = '(UTC+01:00) Brussels, Copenhagen, Madrid, Paris'
+ const summerLabel = '(UTC+02:00) Brussels, Copenhagen, Madrid, Paris'
+ const { rerender } = customRender(
+ <TimezoneSelection
+ selectedTimezone={madridTimezone}
+ date={dayjs('2026-01-15T12:00:00Z')}
+ onSelectTimezone={onSelectTimezone}
+ />
+ )
+
+ const trigger = screen.getByRole('combobox')
+ expect(trigger).toHaveTextContent(winterLabel)
+ await user.click(trigger)
+ expect(await screen.findByRole('option', { name: winterLabel })).toBeVisible()
+
+ rerender(
+ <TimezoneSelection
+ selectedTimezone={madridTimezone}
+ date={dayjs('2026-07-15T12:00:00Z')}
+ onSelectTimezone={onSelectTimezone}
+ />
+ )
+
+ expect(trigger).toHaveTextContent(summerLabel)
+ expect(screen.getByRole('option', { name: summerLabel })).toBeVisible()
+ expect(screen.queryByRole('option', { name: winterLabel })).not.toBeInTheDocument()
+
+ await user.type(screen.getByPlaceholderText('Search timezone...'), 'Madrid')
+ const matchingTimezones = screen.getAllByRole('option')
+ expect(matchingTimezones).toHaveLength(1)
+ await user.click(screen.getByRole('option', { name: summerLabel }))
+
+ expect(onSelectTimezone).toHaveBeenCalledTimes(1)
+ expect(onSelectTimezone.mock.calls[0][0]).toBe(madridTimezone)
+ expect(trigger).toHaveAttribute('aria-expanded', 'false')
+ })
+})
diff --git a/apps/studio/components/interfaces/Database/Backups/PITR/TimezoneSelection.tsx b/apps/studio/components/interfaces/Database/Backups/PITR/TimezoneSelection.tsx
index 935cb9478d9..5b0cd633a58 100644
--- a/apps/studio/components/interfaces/Database/Backups/PITR/TimezoneSelection.tsx
+++ b/apps/studio/components/interfaces/Database/Backups/PITR/TimezoneSelection.tsx
@@ -1,3 +1,4 @@
+import type { Dayjs } from 'dayjs'
import { CheckIcon, Globe } from 'lucide-react'
import { useId, useState } from 'react'
import {
@@ -15,23 +16,22 @@ import {
ScrollArea,
} from 'ui'
-import { ALL_TIMEZONES } from './PITR.constants'
-import type { Timezone } from './PITR.types'
+import { getTimezoneLabel, TIMEZONES_BY_IANA, type Timezone } from '@/lib/constants/timezones'
interface TimezoneSelectionProps {
selectedTimezone: Timezone
+ date: Dayjs
onSelectTimezone: (timezone: Timezone) => void
}
export const TimezoneSelection = ({
selectedTimezone,
+ date,
onSelectTimezone,
}: TimezoneSelectionProps) => {
const [open, setOpen] = useState(false)
const listboxId = useId()
- const timezoneOptions = ALL_TIMEZONES.map((option) => option.text)
-
return (
<div className="w-full">
<Popover open={open} onOpenChange={setOpen}>
@@ -45,11 +45,7 @@ export const TimezoneSelection = ({
>
<span className="flex min-w-0 items-center gap-2">
<Globe aria-hidden="true" className="h-4 w-4 shrink-0" />
- <span className="truncate">
- {selectedTimezone
- ? timezoneOptions.find((option) => option === selectedTimezone.text)
- : 'Select timezone...'}
- </span>
+ <span className="truncate">{getTimezoneLabel(selectedTimezone, date)}</span>
</span>
</ComboboxTrigger>
</PopoverTrigger>
@@ -60,25 +56,20 @@ export const TimezoneSelection = ({
<CommandEmpty>No timezones found...</CommandEmpty>
<CommandGroup>
<ScrollArea className="h-72">
- {timezoneOptions.map((option) => (
+ {TIMEZONES_BY_IANA.map((option) => (
<CommandItem
- key={option}
- value={option}
- onSelect={(text) => {
- const selectedTimezone = ALL_TIMEZONES.find(
- (option) => option.text === text
- )
- if (selectedTimezone) {
- onSelectTimezone(selectedTimezone)
- setOpen(false)
- }
+ key={option.value}
+ value={getTimezoneLabel(option, date)}
+ onSelect={() => {
+ onSelectTimezone(option)
+ setOpen(false)
}}
>
- {option}
+ {getTimezoneLabel(option, date)}
<CheckIcon
className={cn(
'ml-auto h-4 w-4',
- selectedTimezone.text === option ? 'opacity-100' : 'opacity-0'
+ selectedTimezone.value === option.value ? 'opacity-100' : 'opacity-0'
)}
/>
</CommandItem>
diff --git a/apps/studio/components/interfaces/UserDropdown/TimezoneDropdown.tsx b/apps/studio/components/interfaces/UserDropdown/TimezoneDropdown.tsx
index f48990d77ec..0db9abb11bb 100644
--- a/apps/studio/components/interfaces/UserDropdown/TimezoneDropdown.tsx
+++ b/apps/studio/components/interfaces/UserDropdown/TimezoneDropdown.tsx
@@ -15,7 +15,11 @@ import {
ScrollArea,
} from 'ui'
-import { findTimezoneByIana, TIMEZONES_BY_IANA } from '@/lib/constants/timezones'
+import {
+ getTimezoneLabel,
+ getTimezoneLabelByIana,
+ TIMEZONES_BY_IANA,
+} from '@/lib/constants/timezones'
import { useTimezone } from '@/lib/datetime'
import { guessLocalTimezone } from '@/lib/dayjs'
import { useTrack } from '@/lib/telemetry/track'
@@ -33,7 +37,7 @@ export const TimezoneDropdown = () => {
const browserTimezone = useMemo(() => guessLocalTimezone(), [])
const triggerLabel = useMemo(() => {
- return findTimezoneByIana(timezone)?.text ?? timezone
+ return getTimezoneLabelByIana(timezone)
}, [timezone])
const handleSelect = (nextStored: string) => {
@@ -87,7 +91,7 @@ export const TimezoneDropdown = () => {
value="UTC Coordinated Universal Time"
onSelect={() => handleSelect('UTC')}
>
- {'(UTC) Coordinated Universal Time'}
+ {'(UTC+00:00) Coordinated Universal Time'}
<CheckIcon
className={cn(
'ml-auto h-4 w-4',
@@ -103,10 +107,10 @@ export const TimezoneDropdown = () => {
key={ianaName}
// CommandItem matches against the `value` prop for the input filter — include
// both the human label and the IANA name so search works for either.
- value={`${entry.text} ${ianaName}`}
+ value={`${getTimezoneLabel(entry)} ${ianaName}`}
onSelect={() => handleSelect(ianaName)}
>
- {entry.text}
+ {getTimezoneLabel(entry)}
<CheckIcon
className={cn(
'ml-auto h-4 w-4',
diff --git a/apps/studio/lib/constants/timezones.test.ts b/apps/studio/lib/constants/timezones.test.ts
index 69bc7ea7ca8..4db50bf0706 100644
--- a/apps/studio/lib/constants/timezones.test.ts
+++ b/apps/studio/lib/constants/timezones.test.ts
@@ -1,6 +1,12 @@
+import dayjs from 'dayjs'
import { describe, expect, it } from 'vitest'
-import { ALL_TIMEZONES, findTimezoneByIana, TIMEZONES_BY_IANA } from '@/lib/constants/timezones'
+import {
+ findTimezoneByIana,
+ getTimezoneLabel,
+ getTimezoneLabelByIana,
+ TIMEZONES_BY_IANA,
+} from '@/lib/constants/timezones'
describe('TIMEZONES_BY_IANA', () => {
it('produces one row per primary IANA name', () => {
@@ -9,15 +15,17 @@ describe('TIMEZONES_BY_IANA', () => {
})
it('prefers the standard-time row when multiple catalog rows share a primary IANA', () => {
- // ALL_TIMEZONES has both PDT (isdst: true) and PST (isdst: false) pointing
+ // The catalog has both PDT (isdst: true) and PST (isdst: false) pointing
// at America/Los_Angeles. The deduped view should pick the standard one
// so the picker label doesn't flip on DST changes.
- const collisions = ALL_TIMEZONES.filter((entry) => entry.utc[0] === 'America/Los_Angeles')
- expect(collisions.length).toBeGreaterThan(1)
+ const matches = TIMEZONES_BY_IANA.filter((entry) => entry.utc[0] === 'America/Los_Angeles')
+ expect(matches).toHaveLength(1)
+ expect(matches[0].isdst).toBe(false)
+ })
- const winner = TIMEZONES_BY_IANA.find((entry) => entry.utc[0] === 'America/Los_Angeles')
- expect(winner).toBeDefined()
- expect(winner!.isdst).toBe(false)
+ it('has no labels that name a fixed DST state, since the offset in the label is date-aware', () => {
+ const labels = TIMEZONES_BY_IANA.map((entry) => entry.text)
+ expect(labels.filter((label) => /Daylight|Standard/.test(label))).toEqual([])
})
it('preserves entries that have no collision', () => {
@@ -29,6 +37,34 @@ describe('TIMEZONES_BY_IANA', () => {
})
})
+describe('catalog integrity', () => {
+ const getOffsetHours = (timeZone: string, date: Date) => {
+ const value = new Intl.DateTimeFormat('en-US', { timeZone, timeZoneName: 'longOffset' })
+ .formatToParts(date)
+ .find((part) => part.type === 'timeZoneName')?.value
+ const match = value?.match(/GMT([+-])(\d\d):(\d\d)/)
+ if (!match) return 0
+ return (match[1] === '-' ? -1 : 1) * (Number(match[2]) + Number(match[3]) / 60)
+ }
+
+ const winter = new Date('2026-01-15T12:00:00Z')
+ const summer = new Date('2026-07-15T12:00:00Z')
+
+ const cases = TIMEZONES_BY_IANA.flatMap((entry) =>
+ entry.utc.map((iana) => [entry.text, iana, entry] as const)
+ )
+
+ it.each(cases)('%s: %s has the offset in its label in winter or summer', (_text, iana, entry) => {
+ const match = entry.text.match(/^\(UTC(?:([+-])(\d\d):(\d\d))?\)/)
+ expect(match).not.toBeNull()
+ const labelOffset = match?.[1]
+ ? (match[1] === '-' ? -1 : 1) * (Number(match[2]) + Number(match[3]) / 60)
+ : 0
+
+ expect([getOffsetHours(iana, winter), getOffsetHours(iana, summer)]).toContain(labelOffset)
+ })
+})
+
describe('findTimezoneByIana', () => {
it('matches the entry by its primary IANA name', () => {
const entry = findTimezoneByIana('America/Danmarkshavn')
@@ -42,7 +78,98 @@ describe('findTimezoneByIana', () => {
expect(entry?.utc).toContain('Asia/Tokyo')
})
+ it('returns the deduplicated row when the zone belongs to a collapsed catalog row', () => {
+ // Europe/Nicosia is only listed on the "E. Europe" row, which collapses into
+ // "Athens, Bucharest" because both share the primary Asia/Nicosia.
+ const entry = findTimezoneByIana('Europe/Nicosia')
+ expect(entry).toBe(TIMEZONES_BY_IANA.find((row) => row.utc[0] === entry?.utc[0]))
+ expect(entry?.text).toContain('Athens, Bucharest')
+ })
+
it('returns undefined for an unknown IANA name', () => {
expect(findTimezoneByIana('Not/A/Real_Zone')).toBeUndefined()
})
})
+
+const getTimezone = (zone: string) => {
+ const timezone = findTimezoneByIana(zone)
+ if (!timezone) throw new Error(`Timezone ${zone} not found`)
+ return timezone
+}
+
+describe('getTimezoneLabel', () => {
+ it.each([
+ ['2026-01-09T03:12:00Z', '(UTC+01:00) Brussels, Copenhagen, Madrid, Paris'],
+ ['2026-10-09T03:12:00Z', '(UTC+02:00) Brussels, Copenhagen, Madrid, Paris'],
+ ])('shows Madrid offset at %s', (date, label) => {
+ expect(getTimezoneLabel(getTimezone('Europe/Madrid'), dayjs(date))).toBe(label)
+ })
+
+ it.each([
+ ['2026-03-29T00:59:59Z', '(UTC+01:00)'],
+ ['2026-03-29T01:00:00Z', '(UTC+02:00)'],
+ ['2026-10-25T00:59:59Z', '(UTC+02:00)'],
+ ['2026-10-25T01:00:00Z', '(UTC+01:00)'],
+ ])('updates Madrid offset across daylight saving transitions at %s', (date, offset) => {
+ expect(getTimezoneLabel(getTimezone('Europe/Madrid'), dayjs(date))).toBe(
+ `${offset} Brussels, Copenhagen, Madrid, Paris`
+ )
+ })
+
+ it.each([
+ ['America/New_York', '2026-01-09T03:12:00Z', '(UTC-05:00)'],
+ ['America/New_York', '2026-10-09T03:12:00Z', '(UTC-04:00)'],
+ ['Asia/Kolkata', '2026-10-09T03:12:00Z', '(UTC+05:30)'],
+ ['Asia/Kathmandu', '2026-10-09T03:12:00Z', '(UTC+05:45)'],
+ ['Europe/London', '2026-10-09T03:12:00Z', '(UTC+01:00)'],
+ ['America/St_Johns', '2026-01-09T03:12:00Z', '(UTC-03:30)'],
+ ['Etc/GMT', '2026-10-09T03:12:00Z', '(UTC+00:00)'],
+ ])('formats %s offset including its sign and minutes', (zone, date, offset) => {
+ expect(getTimezoneLabel(getTimezone(zone), dayjs(date)).startsWith(offset)).toBe(true)
+ })
+
+ it('preserves the selected timezone and recovery timestamp', () => {
+ const timezone = getTimezone('Europe/Madrid')
+ const originalTimezone = structuredClone(timezone)
+ const recoveryDate = dayjs('2026-10-09T03:12:00Z').tz(timezone.utc[0])
+ const recoveryTimestamp = recoveryDate.unix()
+
+ expect(recoveryDate.format('HH:mm:ss')).toBe('05:12:00')
+ expect(recoveryDate.utc().format('HH:mm:ss')).toBe('03:12:00')
+ expect(getTimezoneLabel(timezone, recoveryDate)).toBe(
+ '(UTC+02:00) Brussels, Copenhagen, Madrid, Paris'
+ )
+ expect(recoveryDate.unix()).toBe(recoveryTimestamp)
+ expect(timezone).toEqual(originalTimezone)
+ })
+})
+
+describe('getTimezoneLabel at a zero offset', () => {
+ it('formats it as +00:00 like every other row', () => {
+ const utc = TIMEZONES_BY_IANA.find((entry) => entry.value === 'UTC')!
+ expect(getTimezoneLabel(utc, '2026-07-15T12:00:00Z')).toBe(
+ '(UTC+00:00) Coordinated Universal Time'
+ )
+ })
+})
+
+describe('getTimezoneLabelByIana', () => {
+ it('uses the offset in effect at the given date', () => {
+ expect(getTimezoneLabelByIana('Europe/Madrid', '2026-01-09T03:12:00Z')).toBe(
+ '(UTC+01:00) Brussels, Copenhagen, Madrid, Paris'
+ )
+ expect(getTimezoneLabelByIana('Europe/Madrid', '2026-10-09T03:12:00Z')).toBe(
+ '(UTC+02:00) Brussels, Copenhagen, Madrid, Paris'
+ )
+ })
+
+ it('defaults to the current date', () => {
+ expect(getTimezoneLabelByIana('Europe/Madrid')).toBe(
+ getTimezoneLabel(getTimezone('Europe/Madrid'), dayjs())
+ )
+ })
+
+ it('falls back to the IANA name when the zone is not in the catalog', () => {
+ expect(getTimezoneLabelByIana('Not/A/Real_Zone')).toBe('Not/A/Real_Zone')
+ })
+})
diff --git a/apps/studio/lib/constants/timezones.ts b/apps/studio/lib/constants/timezones.ts
index 218b45719e0..9d4f4eb43e8 100644
--- a/apps/studio/lib/constants/timezones.ts
+++ b/apps/studio/lib/constants/timezones.ts
@@ -1,34 +1,30 @@
+import dayjs from 'dayjs'
+
+// [Joshen] Retrieved from the following repo, although some of its values are stale
+// so we've made some amendments here
// https://github.com/dmfilipenko/timezones.json/blob/master/timezones.json
export interface Timezone {
value: string
- abbr: string
- offset: number
isdst: boolean
text: string
utc: string[]
}
-export const ALL_TIMEZONES: Timezone[] = [
+const ALL_TIMEZONES: Timezone[] = [
{
value: 'Dateline Standard Time',
- abbr: 'DST',
- offset: -12,
isdst: false,
text: '(UTC-12:00) International Date Line West',
utc: ['Etc/GMT+12'],
},
{
value: 'UTC-11',
- abbr: 'U',
- offset: -11,
isdst: false,
text: '(UTC-11:00) Coordinated Universal Time-11',
utc: ['Etc/GMT+11', 'Pacific/Midway', 'Pacific/Niue', 'Pacific/Pago_Pago'],
},
{
value: 'Hawaiian Standard Time',
- abbr: 'HST',
- offset: -10,
isdst: false,
text: '(UTC-10:00) Hawaii',
utc: [
@@ -41,8 +37,6 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Alaskan Standard Time',
- abbr: 'AKDT',
- offset: -8,
isdst: true,
text: '(UTC-09:00) Alaska',
utc: [
@@ -55,32 +49,24 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Pacific Standard Time (Mexico)',
- abbr: 'PDT',
- offset: -7,
isdst: true,
text: '(UTC-08:00) Baja California',
utc: ['America/Santa_Isabel'],
},
{
value: 'Pacific Daylight Time',
- abbr: 'PDT',
- offset: -7,
isdst: true,
text: '(UTC-07:00) Pacific Daylight Time (US & Canada)',
utc: ['America/Los_Angeles', 'America/Tijuana', 'America/Vancouver'],
},
{
value: 'Pacific Standard Time',
- abbr: 'PST',
- offset: -8,
isdst: false,
- text: '(UTC-08:00) Pacific Standard Time (US & Canada)',
+ text: '(UTC-08:00) Pacific Time (US & Canada)',
utc: ['America/Los_Angeles', 'America/Tijuana', 'America/Vancouver', 'PST8PDT'],
},
{
value: 'US Mountain Standard Time',
- abbr: 'UMST',
- offset: -7,
isdst: false,
text: '(UTC-07:00) Arizona',
utc: [
@@ -95,16 +81,12 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Mountain Standard Time (Mexico)',
- abbr: 'MDT',
- offset: -6,
- isdst: true,
- text: '(UTC-07:00) Chihuahua, La Paz, Mazatlan',
- utc: ['America/Chihuahua', 'America/Mazatlan'],
+ isdst: false,
+ text: '(UTC-07:00) La Paz, Mazatlan',
+ utc: ['America/Mazatlan'],
},
{
value: 'Mountain Standard Time',
- abbr: 'MDT',
- offset: -6,
isdst: true,
text: '(UTC-07:00) Mountain Time (US & Canada)',
utc: [
@@ -113,15 +95,12 @@ export const ALL_TIMEZONES: Timezone[] = [
'America/Denver',
'America/Edmonton',
'America/Inuvik',
- 'America/Ojinaga',
'America/Yellowknife',
'MST7MDT',
],
},
{
value: 'Central America Standard Time',
- abbr: 'CAST',
- offset: -6,
isdst: false,
text: '(UTC-06:00) Central America',
utc: [
@@ -137,8 +116,6 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Central Standard Time',
- abbr: 'CDT',
- offset: -5,
isdst: true,
text: '(UTC-06:00) Central Time (US & Canada)',
utc: [
@@ -159,34 +136,30 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Central Standard Time (Mexico)',
- abbr: 'CDT',
- offset: -5,
- isdst: true,
+ isdst: false,
text: '(UTC-06:00) Guadalajara, Mexico City, Monterrey',
utc: [
'America/Bahia_Banderas',
- 'America/Cancun',
+ 'America/Chihuahua',
'America/Merida',
'America/Mexico_City',
'America/Monterrey',
+ 'America/Ojinaga',
],
},
{
value: 'Canada Central Standard Time',
- abbr: 'CCST',
- offset: -6,
isdst: false,
text: '(UTC-06:00) Saskatchewan',
utc: ['America/Regina', 'America/Swift_Current'],
},
{
value: 'SA Pacific Standard Time',
- abbr: 'SPST',
- offset: -5,
isdst: false,
text: '(UTC-05:00) Bogota, Lima, Quito',
utc: [
'America/Bogota',
+ 'America/Cancun',
'America/Cayman',
'America/Coral_Harbour',
'America/Eirunepe',
@@ -200,8 +173,6 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Eastern Standard Time',
- abbr: 'EST',
- offset: -5,
isdst: false,
text: '(UTC-05:00) Eastern Time (US & Canada)',
utc: [
@@ -225,8 +196,6 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Eastern Daylight Time',
- abbr: 'EDT',
- offset: -4,
isdst: true,
text: '(UTC-04:00) Eastern Daylight Time (US & Canada)',
utc: [
@@ -250,32 +219,24 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'US Eastern Standard Time',
- abbr: 'UEDT',
- offset: -5,
isdst: false,
text: '(UTC-05:00) Indiana (East)',
utc: ['America/Indiana/Marengo', 'America/Indiana/Vevay', 'America/Indianapolis'],
},
{
value: 'Venezuela Standard Time',
- abbr: 'VST',
- offset: -4.5,
isdst: false,
- text: '(UTC-04:30) Caracas',
+ text: '(UTC-04:00) Caracas',
utc: ['America/Caracas'],
},
{
value: 'Paraguay Standard Time',
- abbr: 'PYT',
- offset: -4,
isdst: false,
- text: '(UTC-04:00) Asuncion',
+ text: '(UTC-03:00) Asuncion',
utc: ['America/Asuncion'],
},
{
value: 'Atlantic Standard Time',
- abbr: 'ADT',
- offset: -3,
isdst: true,
text: '(UTC-04:00) Atlantic Time (Canada)',
utc: [
@@ -289,16 +250,12 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Central Brazilian Standard Time',
- abbr: 'CBST',
- offset: -4,
isdst: false,
text: '(UTC-04:00) Cuiaba',
utc: ['America/Campo_Grande', 'America/Cuiaba'],
},
{
value: 'SA Western Standard Time',
- abbr: 'SWST',
- offset: -4,
isdst: false,
text: '(UTC-04:00) Georgetown, La Paz, Manaus, San Juan',
utc: [
@@ -336,32 +293,24 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Pacific SA Standard Time',
- abbr: 'PSST',
- offset: -4,
isdst: false,
text: '(UTC-04:00) Santiago',
- utc: ['America/Santiago', 'Antarctica/Palmer'],
+ utc: ['America/Santiago'],
},
{
value: 'Newfoundland Standard Time',
- abbr: 'NDT',
- offset: -2.5,
isdst: true,
text: '(UTC-03:30) Newfoundland',
utc: ['America/St_Johns'],
},
{
value: 'E. South America Standard Time',
- abbr: 'ESAST',
- offset: -3,
isdst: false,
text: '(UTC-03:00) Brasilia',
utc: ['America/Sao_Paulo'],
},
{
value: 'Argentina Standard Time',
- abbr: 'AST',
- offset: -3,
isdst: false,
text: '(UTC-03:00) Buenos Aires',
utc: [
@@ -381,8 +330,6 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'SA Eastern Standard Time',
- abbr: 'SEST',
- offset: -3,
isdst: false,
text: '(UTC-03:00) Cayenne, Fortaleza',
utc: [
@@ -401,82 +348,62 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Greenland Standard Time',
- abbr: 'GDT',
- offset: -3,
isdst: true,
- text: '(UTC-03:00) Greenland',
- utc: ['America/Godthab'],
+ text: '(UTC-02:00) Greenland',
+ utc: ['America/Nuuk', 'America/Godthab'],
},
{
value: 'Montevideo Standard Time',
- abbr: 'MST',
- offset: -3,
isdst: false,
text: '(UTC-03:00) Montevideo',
utc: ['America/Montevideo'],
},
{
value: 'Bahia Standard Time',
- abbr: 'BST',
- offset: -3,
isdst: false,
text: '(UTC-03:00) Salvador',
utc: ['America/Bahia'],
},
{
value: 'UTC-02',
- abbr: 'U',
- offset: -2,
isdst: false,
text: '(UTC-02:00) Coordinated Universal Time-02',
utc: ['America/Noronha', 'Atlantic/South_Georgia', 'Etc/GMT+2'],
},
{
value: 'Azores Standard Time',
- abbr: 'ADT',
- offset: 0,
isdst: true,
text: '(UTC-01:00) Azores',
utc: ['America/Scoresbysund', 'Atlantic/Azores'],
},
{
value: 'Cape Verde Standard Time',
- abbr: 'CVST',
- offset: -1,
isdst: false,
text: '(UTC-01:00) Cape Verde Is.',
utc: ['Atlantic/Cape_Verde', 'Etc/GMT+1'],
},
{
value: 'Morocco Standard Time',
- abbr: 'MDT',
- offset: 1,
- isdst: true,
- text: '(UTC) Casablanca',
+ isdst: false,
+ text: '(UTC+01:00) Casablanca',
utc: ['Africa/Casablanca', 'Africa/El_Aaiun'],
},
{
value: 'UTC',
- abbr: 'UTC',
- offset: 0,
isdst: false,
- text: '(UTC) Coordinated Universal Time',
+ text: '(UTC+00:00) Coordinated Universal Time',
utc: ['America/Danmarkshavn', 'Etc/GMT'],
},
{
value: 'British Summer Time',
- abbr: 'BST',
- offset: 1,
isdst: true,
text: '(UTC+01:00) Edinburgh, London',
utc: ['Europe/Isle_of_Man', 'Europe/Guernsey', 'Europe/Jersey', 'Europe/London'],
},
{
value: 'GMT Standard Time',
- abbr: 'GDT',
- offset: 1,
isdst: true,
- text: '(UTC) Dublin, Lisbon',
+ text: '(UTC+00:00) Dublin, Lisbon',
utc: [
'Atlantic/Canary',
'Atlantic/Faeroe',
@@ -487,10 +414,8 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Greenwich Standard Time',
- abbr: 'GST',
- offset: 0,
isdst: false,
- text: '(UTC) Monrovia, Reykjavik',
+ text: '(UTC+00:00) Monrovia, Reykjavik',
utc: [
'Africa/Abidjan',
'Africa/Accra',
@@ -511,8 +436,6 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'W. Europe Standard Time',
- abbr: 'WEDT',
- offset: 2,
isdst: true,
text: '(UTC+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna',
utc: [
@@ -537,8 +460,6 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Central Europe Standard Time',
- abbr: 'CEDT',
- offset: 2,
isdst: true,
text: '(UTC+01:00) Belgrade, Bratislava, Budapest, Ljubljana, Prague',
utc: [
@@ -553,24 +474,18 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Romance Standard Time',
- abbr: 'RDT',
- offset: 2,
isdst: true,
text: '(UTC+01:00) Brussels, Copenhagen, Madrid, Paris',
utc: ['Africa/Ceuta', 'Europe/Brussels', 'Europe/Copenhagen', 'Europe/Madrid', 'Europe/Paris'],
},
{
value: 'Central European Standard Time',
- abbr: 'CEDT',
- offset: 2,
isdst: true,
text: '(UTC+01:00) Sarajevo, Skopje, Warsaw, Zagreb',
utc: ['Europe/Sarajevo', 'Europe/Skopje', 'Europe/Warsaw', 'Europe/Zagreb'],
},
{
value: 'W. Central Africa Standard Time',
- abbr: 'WCAST',
- offset: 1,
isdst: false,
text: '(UTC+01:00) West Central Africa',
utc: [
@@ -592,48 +507,36 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Namibia Standard Time',
- abbr: 'NST',
- offset: 1,
isdst: false,
- text: '(UTC+01:00) Windhoek',
+ text: '(UTC+02:00) Windhoek',
utc: ['Africa/Windhoek'],
},
{
value: 'GTB Standard Time',
- abbr: 'GDT',
- offset: 3,
isdst: true,
text: '(UTC+02:00) Athens, Bucharest',
utc: ['Asia/Nicosia', 'Europe/Athens', 'Europe/Bucharest', 'Europe/Chisinau'],
},
{
value: 'Middle East Standard Time',
- abbr: 'MEDT',
- offset: 3,
isdst: true,
text: '(UTC+02:00) Beirut',
utc: ['Asia/Beirut'],
},
{
value: 'Egypt Standard Time',
- abbr: 'EST',
- offset: 2,
isdst: false,
text: '(UTC+02:00) Cairo',
utc: ['Africa/Cairo'],
},
{
value: 'Syria Standard Time',
- abbr: 'SDT',
- offset: 3,
- isdst: true,
- text: '(UTC+02:00) Damascus',
+ isdst: false,
+ text: '(UTC+03:00) Damascus',
utc: ['Asia/Damascus'],
},
{
value: 'E. Europe Standard Time',
- abbr: 'EEDT',
- offset: 3,
isdst: true,
text: '(UTC+02:00) E. Europe',
utc: [
@@ -655,8 +558,6 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'South Africa Standard Time',
- abbr: 'SAST',
- offset: 2,
isdst: false,
text: '(UTC+02:00) Harare, Pretoria',
utc: [
@@ -665,6 +566,8 @@ export const ALL_TIMEZONES: Timezone[] = [
'Africa/Gaborone',
'Africa/Harare',
'Africa/Johannesburg',
+ 'Africa/Juba',
+ 'Africa/Khartoum',
'Africa/Kigali',
'Africa/Lubumbashi',
'Africa/Lusaka',
@@ -676,8 +579,6 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'FLE Standard Time',
- abbr: 'FDT',
- offset: 3,
isdst: true,
text: '(UTC+02:00) Helsinki, Kyiv, Riga, Sofia, Tallinn, Vilnius',
utc: [
@@ -694,64 +595,48 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Turkey Standard Time',
- abbr: 'TDT',
- offset: 3,
isdst: false,
text: '(UTC+03:00) Istanbul',
utc: ['Europe/Istanbul'],
},
{
value: 'Israel Standard Time',
- abbr: 'JDT',
- offset: 3,
isdst: true,
text: '(UTC+02:00) Jerusalem',
utc: ['Asia/Jerusalem'],
},
{
value: 'Libya Standard Time',
- abbr: 'LST',
- offset: 2,
isdst: false,
text: '(UTC+02:00) Tripoli',
utc: ['Africa/Tripoli'],
},
{
value: 'Jordan Standard Time',
- abbr: 'JST',
- offset: 3,
isdst: false,
text: '(UTC+03:00) Amman',
utc: ['Asia/Amman'],
},
{
value: 'Arabic Standard Time',
- abbr: 'AST',
- offset: 3,
isdst: false,
text: '(UTC+03:00) Baghdad',
utc: ['Asia/Baghdad'],
},
{
value: 'Kaliningrad Standard Time',
- abbr: 'KST',
- offset: 3,
isdst: false,
text: '(UTC+02:00) Kaliningrad',
utc: ['Europe/Kaliningrad'],
},
{
value: 'Arab Standard Time',
- abbr: 'AST',
- offset: 3,
isdst: false,
text: '(UTC+03:00) Kuwait, Riyadh',
utc: ['Asia/Aden', 'Asia/Bahrain', 'Asia/Kuwait', 'Asia/Qatar', 'Asia/Riyadh'],
},
{
value: 'E. Africa Standard Time',
- abbr: 'EAST',
- offset: 3,
isdst: false,
text: '(UTC+03:00) Nairobi',
utc: [
@@ -759,9 +644,7 @@ export const ALL_TIMEZONES: Timezone[] = [
'Africa/Asmera',
'Africa/Dar_es_Salaam',
'Africa/Djibouti',
- 'Africa/Juba',
'Africa/Kampala',
- 'Africa/Khartoum',
'Africa/Mogadishu',
'Africa/Nairobi',
'Antarctica/Syowa',
@@ -773,89 +656,72 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Moscow Standard Time',
- abbr: 'MSK',
- offset: 3,
isdst: false,
text: '(UTC+03:00) Moscow, St. Petersburg, Volgograd, Minsk',
utc: ['Europe/Kirov', 'Europe/Moscow', 'Europe/Simferopol', 'Europe/Volgograd', 'Europe/Minsk'],
},
{
value: 'Samara Time',
- abbr: 'SAMT',
- offset: 4,
isdst: false,
text: '(UTC+04:00) Samara, Ulyanovsk, Saratov',
utc: ['Europe/Astrakhan', 'Europe/Samara', 'Europe/Ulyanovsk'],
},
{
value: 'Iran Standard Time',
- abbr: 'IDT',
- offset: 4.5,
isdst: true,
text: '(UTC+03:30) Tehran',
utc: ['Asia/Tehran'],
},
{
value: 'Arabian Standard Time',
- abbr: 'AST',
- offset: 4,
isdst: false,
text: '(UTC+04:00) Abu Dhabi, Muscat',
utc: ['Asia/Dubai', 'Asia/Muscat', 'Etc/GMT-4'],
},
{
value: 'Azerbaijan Standard Time',
- abbr: 'ADT',
- offset: 5,
isdst: true,
text: '(UTC+04:00) Baku',
utc: ['Asia/Baku'],
},
{
value: 'Mauritius Standard Time',
- abbr: 'MST',
- offset: 4,
isdst: false,
text: '(UTC+04:00) Port Louis',
utc: ['Indian/Mahe', 'Indian/Mauritius', 'Indian/Reunion'],
},
{
value: 'Georgian Standard Time',
- abbr: 'GET',
- offset: 4,
isdst: false,
text: '(UTC+04:00) Tbilisi',
utc: ['Asia/Tbilisi'],
},
{
value: 'Caucasus Standard Time',
- abbr: 'CST',
- offset: 4,
isdst: false,
text: '(UTC+04:00) Yerevan',
utc: ['Asia/Yerevan'],
},
{
value: 'Afghanistan Standard Time',
- abbr: 'AST',
- offset: 4.5,
isdst: false,
text: '(UTC+04:30) Kabul',
utc: ['Asia/Kabul'],
},
{
value: 'West Asia Standard Time',
- abbr: 'WAST',
- offset: 5,
isdst: false,
text: '(UTC+05:00) Ashgabat, Tashkent',
utc: [
'Antarctica/Mawson',
+ 'Antarctica/Vostok',
+ 'Asia/Almaty',
'Asia/Aqtau',
'Asia/Aqtobe',
'Asia/Ashgabat',
'Asia/Dushanbe',
'Asia/Oral',
+ 'Asia/Qyzylorda',
'Asia/Samarkand',
'Asia/Tashkent',
'Etc/GMT-5',
@@ -865,80 +731,54 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Yekaterinburg Time',
- abbr: 'YEKT',
- offset: 5,
isdst: false,
text: '(UTC+05:00) Yekaterinburg',
utc: ['Asia/Yekaterinburg'],
},
{
value: 'Pakistan Standard Time',
- abbr: 'PKT',
- offset: 5,
isdst: false,
text: '(UTC+05:00) Islamabad, Karachi',
utc: ['Asia/Karachi'],
},
{
value: 'India Standard Time',
- abbr: 'IST',
- offset: 5.5,
isdst: false,
text: '(UTC+05:30) Chennai, Kolkata, Mumbai, New Delhi',
utc: ['Asia/Kolkata', 'Asia/Calcutta'],
},
{
value: 'Sri Lanka Standard Time',
- abbr: 'SLST',
- offset: 5.5,
isdst: false,
text: '(UTC+05:30) Sri Jayawardenepura',
utc: ['Asia/Colombo'],
},
{
value: 'Nepal Standard Time',
- abbr: 'NST',
- offset: 5.75,
isdst: false,
text: '(UTC+05:45) Kathmandu',
utc: ['Asia/Kathmandu'],
},
{
value: 'Central Asia Standard Time',
- abbr: 'CAST',
- offset: 6,
isdst: false,
- text: '(UTC+06:00) Nur-Sultan (Astana)',
- utc: [
- 'Antarctica/Vostok',
- 'Asia/Almaty',
- 'Asia/Bishkek',
- 'Asia/Qyzylorda',
- 'Asia/Urumqi',
- 'Etc/GMT-6',
- 'Indian/Chagos',
- ],
+ text: '(UTC+06:00) Bishkek, Urumqi',
+ utc: ['Asia/Bishkek', 'Asia/Urumqi', 'Etc/GMT-6', 'Indian/Chagos'],
},
{
value: 'Bangladesh Standard Time',
- abbr: 'BST',
- offset: 6,
isdst: false,
text: '(UTC+06:00) Dhaka',
- utc: ['Asia/Dhaka', 'Asia/Thimphu'],
+ utc: ['Asia/Dhaka', 'Asia/Omsk', 'Asia/Thimphu'],
},
{
value: 'Myanmar Standard Time',
- abbr: 'MST',
- offset: 6.5,
isdst: false,
text: '(UTC+06:30) Yangon (Rangoon)',
utc: ['Asia/Rangoon', 'Indian/Cocos'],
},
{
value: 'SE Asia Standard Time',
- abbr: 'SAST',
- offset: 7,
isdst: false,
text: '(UTC+07:00) Bangkok, Hanoi, Jakarta',
utc: [
@@ -956,32 +796,24 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'N. Central Asia Standard Time',
- abbr: 'NCAST',
- offset: 7,
isdst: false,
text: '(UTC+07:00) Novosibirsk',
- utc: ['Asia/Novokuznetsk', 'Asia/Novosibirsk', 'Asia/Omsk'],
+ utc: ['Asia/Novokuznetsk', 'Asia/Novosibirsk'],
},
{
value: 'China Standard Time',
- abbr: 'CST',
- offset: 8,
isdst: false,
text: '(UTC+08:00) Beijing, Chongqing, Hong Kong, Urumqi',
utc: ['Asia/Hong_Kong', 'Asia/Macau', 'Asia/Shanghai'],
},
{
value: 'North Asia Standard Time',
- abbr: 'NAST',
- offset: 8,
isdst: false,
- text: '(UTC+08:00) Krasnoyarsk',
+ text: '(UTC+07:00) Krasnoyarsk',
utc: ['Asia/Krasnoyarsk'],
},
{
value: 'Singapore Standard Time',
- abbr: 'MPST',
- offset: 8,
isdst: false,
text: '(UTC+08:00) Kuala Lumpur, Singapore',
utc: [
@@ -996,88 +828,66 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'W. Australia Standard Time',
- abbr: 'WAST',
- offset: 8,
isdst: false,
text: '(UTC+08:00) Perth',
utc: ['Antarctica/Casey', 'Australia/Perth'],
},
{
value: 'Taipei Standard Time',
- abbr: 'TST',
- offset: 8,
isdst: false,
text: '(UTC+08:00) Taipei',
utc: ['Asia/Taipei'],
},
{
value: 'Ulaanbaatar Standard Time',
- abbr: 'UST',
- offset: 8,
isdst: false,
text: '(UTC+08:00) Ulaanbaatar',
utc: ['Asia/Choibalsan', 'Asia/Ulaanbaatar'],
},
{
value: 'North Asia East Standard Time',
- abbr: 'NAEST',
- offset: 8,
isdst: false,
text: '(UTC+08:00) Irkutsk',
utc: ['Asia/Irkutsk'],
},
{
value: 'Japan Standard Time',
- abbr: 'JST',
- offset: 9,
isdst: false,
text: '(UTC+09:00) Osaka, Sapporo, Tokyo',
utc: ['Asia/Dili', 'Asia/Jayapura', 'Asia/Tokyo', 'Etc/GMT-9', 'Pacific/Palau'],
},
{
value: 'Korea Standard Time',
- abbr: 'KST',
- offset: 9,
isdst: false,
text: '(UTC+09:00) Seoul',
utc: ['Asia/Pyongyang', 'Asia/Seoul'],
},
{
value: 'Cen. Australia Standard Time',
- abbr: 'CAST',
- offset: 9.5,
isdst: false,
text: '(UTC+09:30) Adelaide',
utc: ['Australia/Adelaide', 'Australia/Broken_Hill'],
},
{
value: 'AUS Central Standard Time',
- abbr: 'ACST',
- offset: 9.5,
isdst: false,
text: '(UTC+09:30) Darwin',
utc: ['Australia/Darwin'],
},
{
value: 'E. Australia Standard Time',
- abbr: 'EAST',
- offset: 10,
isdst: false,
text: '(UTC+10:00) Brisbane',
utc: ['Australia/Brisbane', 'Australia/Lindeman'],
},
{
value: 'AUS Eastern Standard Time',
- abbr: 'AEST',
- offset: 10,
isdst: false,
text: '(UTC+10:00) Canberra, Melbourne, Sydney',
utc: ['Australia/Melbourne', 'Australia/Sydney'],
},
{
value: 'West Pacific Standard Time',
- abbr: 'WPST',
- offset: 10,
isdst: false,
text: '(UTC+10:00) Guam, Port Moresby',
utc: [
@@ -1091,24 +901,18 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Tasmania Standard Time',
- abbr: 'TST',
- offset: 10,
isdst: false,
text: '(UTC+10:00) Hobart',
utc: ['Australia/Currie', 'Australia/Hobart'],
},
{
value: 'Yakutsk Standard Time',
- abbr: 'YST',
- offset: 9,
isdst: false,
text: '(UTC+09:00) Yakutsk',
utc: ['Asia/Chita', 'Asia/Khandyga', 'Asia/Yakutsk'],
},
{
value: 'Central Pacific Standard Time',
- abbr: 'CPST',
- offset: 11,
isdst: false,
text: '(UTC+11:00) Solomon Is., New Caledonia',
utc: [
@@ -1123,24 +927,18 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Vladivostok Standard Time',
- abbr: 'VST',
- offset: 11,
isdst: false,
- text: '(UTC+11:00) Vladivostok',
- utc: ['Asia/Sakhalin', 'Asia/Ust-Nera', 'Asia/Vladivostok'],
+ text: '(UTC+10:00) Vladivostok',
+ utc: ['Asia/Vladivostok', 'Asia/Ust-Nera'],
},
{
value: 'New Zealand Standard Time',
- abbr: 'NZST',
- offset: 12,
isdst: false,
text: '(UTC+12:00) Auckland, Wellington',
utc: ['Antarctica/McMurdo', 'Pacific/Auckland'],
},
{
value: 'UTC+12',
- abbr: 'U',
- offset: 12,
isdst: false,
text: '(UTC+12:00) Coordinated Universal Time+12',
utc: [
@@ -1156,40 +954,30 @@ export const ALL_TIMEZONES: Timezone[] = [
},
{
value: 'Fiji Standard Time',
- abbr: 'FST',
- offset: 12,
isdst: false,
text: '(UTC+12:00) Fiji',
utc: ['Pacific/Fiji'],
},
{
value: 'Magadan Standard Time',
- abbr: 'MST',
- offset: 12,
isdst: false,
- text: '(UTC+12:00) Magadan',
- utc: ['Asia/Anadyr', 'Asia/Kamchatka', 'Asia/Magadan', 'Asia/Srednekolymsk'],
+ text: '(UTC+11:00) Magadan, Sakhalin',
+ utc: ['Asia/Magadan', 'Asia/Sakhalin', 'Asia/Srednekolymsk'],
},
{
value: 'Kamchatka Standard Time',
- abbr: 'KDT',
- offset: 13,
isdst: true,
text: '(UTC+12:00) Petropavlovsk-Kamchatsky - Old',
- utc: ['Asia/Kamchatka'],
+ utc: ['Asia/Kamchatka', 'Asia/Anadyr'],
},
{
value: 'Tonga Standard Time',
- abbr: 'TST',
- offset: 13,
isdst: false,
text: "(UTC+13:00) Nuku'alofa",
utc: ['Etc/GMT-13', 'Pacific/Enderbury', 'Pacific/Fakaofo', 'Pacific/Tongatapu'],
},
{
value: 'Samoa Standard Time',
- abbr: 'SST',
- offset: 13,
isdst: false,
text: '(UTC+13:00) Samoa',
utc: ['Pacific/Apia'],
@@ -1216,6 +1004,46 @@ export const TIMEZONES_BY_IANA: Timezone[] = (() => {
return Array.from(seen.values())
})()
-/** Look up the catalog entry that owns the given IANA name (any of `utc[]`). */
-export const findTimezoneByIana = (iana: string): Timezone | undefined =>
- ALL_TIMEZONES.find((entry) => entry.utc.includes(iana))
+const TIMEZONES_BY_PRIMARY_IANA = new Map(TIMEZONES_BY_IANA.map((entry) => [entry.utc[0], entry]))
+
+/**
+ * Look up the catalog entry that owns the given IANA name (any of `utc[]`). Always returns the
+ * entry from `TIMEZONES_BY_IANA`, so the result is something a picker built from that list can
+ * show as selected, even if the IANA name was listed on a deduplicated-away row.
+ */
+export const findTimezoneByIana = (iana: string): Timezone | undefined => {
+ const entry = ALL_TIMEZONES.find((timezone) => timezone.utc.includes(iana))
+ return entry && (TIMEZONES_BY_PRIMARY_IANA.get(entry.utc[0]) ?? entry)
+}
+
+// Constructing an Intl.DateTimeFormat is expensive and pickers format ~100 rows on every render
+const offsetFormatters = new Map<string, Intl.DateTimeFormat>()
+
+const getOffsetFormatter = (timeZone: string) => {
+ let formatter = offsetFormatters.get(timeZone)
+ if (!formatter) {
+ formatter = new Intl.DateTimeFormat('en-US', { timeZone, timeZoneName: 'longOffset' })
+ offsetFormatters.set(timeZone, formatter)
+ }
+ return formatter
+}
+
+/**
+ * Catalog labels (`text`) carry a fixed offset prefix, e.g. `(UTC+01:00) Madrid`, which is wrong
+ * for half the year in zones that observe DST. This swaps that prefix for the zone's offset at
+ * `date` (defaults to now), derived from its primary IANA name (`utc[0]`).
+ */
+export const getTimezoneLabel = (timezone: Timezone, date?: dayjs.ConfigType) => {
+ const offset =
+ getOffsetFormatter(timezone.utc[0])
+ .formatToParts(dayjs(date).toDate())
+ .find((part) => part.type === 'timeZoneName')
+ ?.value.replace('GMT', '') || '+00:00'
+ return timezone.text.replace(/^\(UTC[^)]*\)/, `(UTC${offset})`)
+}
+
+/** Same as `getTimezoneLabel`, for a stored IANA name. Falls back to the IANA name if unknown. */
+export const getTimezoneLabelByIana = (iana: string, date?: dayjs.ConfigType) => {
+ const timezone = findTimezoneByIana(iana)
+ return timezone ? getTimezoneLabel(timezone, date) : iana
+}