# Timezone picker

> A searchable IANA timezone picker with live local clocks, exact UTC offset deltas, a spring-driven 24-hour daylight hairline and one-click Detect.

Selecting a timezone from an unsearchable list of 400 raw IANA strings forces people to guess offsets and daylight saving rules. TimezonePicker combines a curated 42-city global IANA table with native Intl.DateTimeFormat calculations (zero external timezone bundles) and accepts any valid IANA string passed in. As you hover or step through cities with the keyboard, a spring-driven needle glides across a 24-hour solar daylight hairline marking night, twilight, daytime and 09:00 to 17:00 business hours while live clocks and exact +/-Xh deltas against the browser timezone update in place. One-click Detect snaps directly to the user local timezone, and both popover and inline variants are included.

## Install

```bash
npx shadcn@latest add https://hairlineui.com/r/timezone-picker.json
```

Needs React 19, Tailwind CSS v4 and shadcn/ui theme variables (any style, light and dark). Icons from lucide-react.

- npm: `lucide-react`
- Hairline UI components it needs (the CLI installs them too): `text-morph`
- Docs and live preview: https://hairlineui.com/ui/timezone-picker
- Registry item (source): https://hairlineui.com/r/timezone-picker.json

## Usage

```tsx
import { TimezonePicker } from "@/components/timezone-picker";

<TimezonePicker
  value={timezone}
  onChange={(iana) => setTimezone(iana)}
/>
```

## Profile preferences synced with browser detection

Store the canonical IANA string (never a raw UTC offset) so daylight saving changes stay accurate year-round.

```tsx
"use client";
import { useState } from "react";
import { TimezonePicker, detectLocalTimezone } from "@/components/timezone-picker";

export function ProfileTimezoneField({ initial }: { initial?: string }) {
  const [iana, setIana] = useState(() => initial ?? detectLocalTimezone());

  return (
    <div className="space-y-2">
      <label className="text-xs font-medium text-foreground">Default timezone</label>
      <TimezonePicker
        value={iana}
        onChange={(nextIana) => setIana(nextIana)}
      />
    </div>
  );
}
```

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `value / defaultValue / onChange` | `string / string / (iana, info) => void` | – | Controlled or uncontrolled canonical IANA timezone string. |
| `variant` | `"popover" \| "inline"` | `"popover"` | Compact form trigger with floating menu, or always-open embedded panel. |
| `hour12 / showDiff / showHorizon / allowDetect` | `boolean` | `false / true / true / true` | Toggle 12-hour formatting, local offset diff chips, the 24-hour daylight hairline and the Detect button. |
| `zones` | `TimezoneEntry[]` | `COMMON_TIMEZONES` | Override the curated 42-city table; arbitrary valid IANA values passed via value are preserved automatically. |
| `getTimezoneInfo / detectLocalTimezone / formatOffsetDiff` | `exported utility functions` | – | Compute live zone metadata, resolve the browser timezone and format offset differences elsewhere in your app. |

## States

- **closed trigger**: Shows the solar phase icon, city, IANA identifier, UTC offset and live local time inside a compact hairline field.
- **searching and stepping**: Filtering narrows rows instantaneously while hovering or pressing Arrow keys glides the 24-hour daylight needle to each city solar hour.
- **detected**: Pressing Detect snaps straight to the browser timezone and confirms with an emerald Check badge.
- **inline panel**: Renders the full searchable card and daylight hairline embedded without a trigger or floating popover.
- **reduced motion**: The 24-hour solar needle jumps directly to each timezone hour without spring travel.

## What it handles

A real timezone control has to compute DST-aware offsets without shipping megabytes of zone tables and make local time immediately legible.

- **24-hour solar daylight hairline**: Highlights night, twilight, daylight and 09:00 to 17:00 working hours with a spring-driven live needle that glides to every highlighted city.
- **Zero-dependency Intl engine**: Computes live local times, DST-accurate UTC offsets and abbreviations straight from native Intl.DateTimeFormat, updating cleanly on minute boundaries.
- **Exact delta from your local time**: Displays Local, Same time, +5.5h or -9h on every row so users immediately see how far away a city is.
- **Search by city, IANA, abbreviation or offset**: Matches New York, Bengaluru, IST, PST, UTC+05:30, airport codes and country names with full ArrowUp/ArrowDown/Home/End/Enter keyboard navigation.
- **One-click local Detect**: Resolves Intl.DateTimeFormat().resolvedOptions().timeZone and confirms selection with an inline emerald Detected flash.
- **Popover and inline modes**: Use variant="popover" inside compact forms or variant="inline" directly inside scheduling modals and settings panels.

## Replaces

raw IANA select dropdown, moment-timezone picker, browser timezone detector, UTC offset calculator

## Where it fits

- **Calendar and booking flows**: Let invitees pick their local timezone with live wall-clock previews and an immediate daylight check before booking.
- **Account and workspace settings**: Detect the browser timezone in one click or search by city, country, airport code, abbreviation or UTC offset.
- **Cron schedules and billing anchors**: Pair with Cron input so operators know the exact UTC offset and local hour a scheduled job will run.
- **Distributed team rosters**: Render the inline panel inside a sidebar or modal to compare teammate offsets and working-hour overlap.

## Notes

- Timers align to the next minute boundary so open pickers update live clocks accurately without running a 1-second interval.
- Because Intl.DateTimeFormat computes offsets for the live Date, DST transitions are reflected automatically with zero static offset bugs.
- Any arbitrary valid IANA string passed in value (even if absent from COMMON_TIMEZONES) is humanized and injected cleanly into the list.

License: MIT (https://hairlineui.com/license#components)
