Timezone Select

An IANA timezone picker showing each zone's current offset and local time. Zones are named by city, never by abbreviation — "CST" is Central, China and Cuba Standard Time.

src/components/ui/timezone-select.tsx

About

From the component's own source, where it was written.

An IANA timezone picker showing each zone's current offset and local time.

The list comes from Intl.supportedValuesOf('timeZone'), so it is whatever the runtime actually supports rather than a hardcoded table that goes stale every time a government moves a DST boundary. Older runtimes without that method fall back to a small common set — a short list beats a crash.

Offsets are computed live rather than stored. A zone's offset is a function of the date, and a list built in January is wrong for half the year.

Zones are labelled by city, not by abbreviation. "CST" is Central Standard Time, China Standard Time and Cuba Standard Time; America/Chicago is one place. The abbreviation is shown alongside for recognition, never alone.

Install

npx astralyx-ui add timezone-select

Usage

import { TimezoneSelect } from '@/components/ui/timezone-select'

<TimezoneSelect value={zone} onValueChange={setZone} />

Composer

Change the props and the source below follows.

Props
tsx
<TimezoneSelect value={zone} onValueChange={setZone} />

Examples

Controlled selection

API

Generated from the source, so it cannot fall behind the code. One table per exported component, then hooks, functions and types.

TimezoneSelect

Extends Omit< ComponentProps<typeof Combobox>, 'options' | 'searchPlaceholder' >.

PropTypeDefaultDescription
defaultValuestring——
valuestring——
errorboolean——
disabledboolean——
variant'default' | 'secondary' | 'ghost'—Matches Input and Select, so a form can be uniform.
sizekeyof typeof fieldSize——
onValueChange(value: string) => void——
placeholderstring'Select timezone…'—
emptyMessagestring——
zonesstring[]—Restrict the list. A booking form rarely needs all four hundred.
showLocalTimebooleantrueThe zone's current wall-clock time — usually the fastest way to recognise the right one.
nowDate—Reference instant for offsets. Defaults to now.

Functions

FunctionSignatureDescription
listTimezones() => string[]—
offsetMinutes(zone: string, at: Date) => numberCurrent UTC offset of a zone, in minutes, derived from a formatted date.
formatOffset(minutes: number) => string—

Behaviour

TopicDetailDescription
optionsfrom the runtimeIntl.supportedValuesOf("timeZone"), so the list is whatever the browser actually supports rather than a table that rots each time a government moves a DST boundary.
offsetscomputed liveA zone's offset is a function of the date. A list built in January is wrong for half the year.
searchcity or regionThe region stays in the label, so Europe/London is findable by "Europe" as well as by "London".