A day, a time and a time zone together, with daylight-saving changes handled and the time in the reader's own zone.
Rosa Tanaka
Onboarding advisor · 30 minutes
Friday, December 4 at 10:30 AM (America/New York). Stored as 2026-12-04T15:30:00.000Z.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { formatDate, formatTimeOfDay } from "./ui/uicontext/components/dates/DateMath.ts"import { DateTimePicker } from "./ui/uicontext/components/DateTimePicker.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, font, radius, space } from "./ui/uicontext/components/tokens.stylex.ts"// Booking a call with an advisor in New York, from Berlin. The slot is in the advisor's zone on// weekdays; change the zone to book in your own, and the note gives the time on the other side.const now = "2026-12-02T15:00:00Z"const styles = stylex.create({ card: { display: "grid", gap: space.lg, inlineSize: "min(100%, 30rem)" }, who: { display: "flex", alignItems: "center", gap: space.md }, avatar: { display: "grid", placeItems: "center", flexShrink: 0, inlineSize: 36, blockSize: 36, borderRadius: radius.full, backgroundColor: color.selected, fontSize: font.sm, fontWeight: 600 }, name: { margin: 0, fontWeight: 600, fontSize: font.base }, role: { margin: 0, fontSize: font.sm, color: color.muted }, summary: { margin: 0, fontSize: font.sm, color: color.muted, fontVariantNumeric: "tabular-nums", overflowWrap: "anywhere" },})const Message = UiSchema.TaggedEnum({ PickedSlot: { value: Schema.NullOr(Schema.String), timeZone: Schema.String, instant: Schema.NullOr(Schema.String) },})export const BookingSlot = Html.component({ name: "BookingSlot", model: Schema.Struct({ slot: Schema.NullOr(Schema.String), zone: Schema.String, instant: Schema.NullOr(Schema.String) }), message: Message,}).make({ init: () => ({ slot: "2026-12-04T10:30", zone: "America/New_York", instant: "2026-12-04T15:30:00.000Z" }), update: { PickedSlot: ($, { value, timeZone, instant }) => $.evolve({ slot: value, zone: timeZone, instant }) }, view: (h, { slot, zone, instant }) => h.div.attrs(sx(styles.card)).children( h.div.attrs(sx(styles.who)).children( h.span.attrs({ "aria-hidden": "true", ...sx(styles.avatar) }).children("RT"), h.div.children(h.p.attrs(sx(styles.name)).children("Rosa Tanaka"), h.p.attrs(sx(styles.role)).children("Onboarding advisor · 30 minutes")), ), DateTimePicker(h, { props: { label: "Call", hideLabel: true, value: slot, timeZone: zone, now, localZone: "Europe/Berlin", locale: "en-US", zonePicker: true, step: 30, min: "2026-12-03", max: "2027-02-26", unavailable: { weekdays: [0, 6], dates: ["2026-12-24", "2026-12-25", "2026-12-31", "2027-01-01"] }, }, onEmit: { Picked: (picked) => Message.PickedSlot(picked) }, }), h.p.attrs(sx(styles.summary)).children( slot === null ? "Pick a day and a time." : `${formatDate(slot.slice(0, 10), "en-US", { weekday: "long", month: "long", day: "numeric" })} at ${formatTimeOfDay(slot.slice(11), "en-US")} (${zone.replaceAll("_", " ")}). Stored as ${instant ?? "—"}.`, ), ),})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/date-time-pickerUsage
import { DateTimePicker } from "./ui/uicontext/components/DateTimePicker.ts"const Message = UiSchema.TaggedEnum({ PickedStart: { value: Schema.NullOr(Schema.String), timeZone: Schema.String, instant: Schema.NullOr(Schema.String) },})// store the instant to schedule with; keep the wall time and zone to show it againexport const Starts = (h: Html.H<typeof Message.Type>, start: string | null, zone: string, now: string) => DateTimePicker(h, { props: { label: "Starts", value: start, timeZone: zone, now, zonePicker: true }, onEmit: { Picked: (picked) => Message.PickedStart(picked) }, })Examples
Clock changes
A time the clocks skip moves to the one that happens, and a time that happens twice is the first. Either way, a note says so.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import { DateTimePicker } from "./ui/uicontext/components/DateTimePicker.ts"import { sx } from "./ui/uicontext/components/Sx.ts"// A maintenance window on the night New York's clocks go forward. 2:30 AM doesn't happen that// night, so the picker sets 3:30 AM and says why. Pick Nov 7, 2027 at 1:30 AM to see a time that// happens twice.const styles = stylex.create({ frame: { inlineSize: "min(100%, 30rem)" } })const Message = UiSchema.TaggedEnum({ PickedWindow: { value: Schema.NullOr(Schema.String), timeZone: Schema.String },})export const MaintenanceWindow = Html.component({ name: "MaintenanceWindow", model: Schema.Struct({ window: Schema.NullOr(Schema.String), zone: Schema.String }), message: Message,}).make({ init: () => ({ window: "2027-03-14T02:30", zone: "America/New_York" }), update: { PickedWindow: ($, { value, timeZone }) => $.evolve({ window: value, zone: timeZone }) }, view: (h, { window, zone }) => h.div.attrs(sx(styles.frame)).children(DateTimePicker(h, { props: { label: "Maintenance starts", value: window, timeZone: zone, now: "2026-12-02T15:00:00Z", localZone: "America/New_York", locale: "en-US", step: 30 }, onEmit: { Picked: ({ value, timeZone }) => Message.PickedWindow({ value, timeZone }) }, })),})API reference
Props
| Name | Type | Default | Description |
|---|---|---|---|
valuerequired | IsoDateTime | null | — | The wall-clock time in timeZone, as YYYY-MM-DDTHH:mm, or null for none |
timeZone | TimeZoneId | — | The zone the value is in; the reader's when left out |
nowrequired | string | — | The app's current instant (ISO): today, and each zone's offset, come from it |
zonePicker | boolean | — | Show the time zone menu |
localZone | TimeZoneId | — | The reader's own zone, for the note and the zone list; the browser's when left out |
locale | string | — | — |
labelrequired | string | — | Names the group: "Starts", "Delivery" |
hideLabel | boolean | — | — |
step | Int | 30 | Minutes between the times listed; 30 by default |
hour12 | boolean | — | — |
min | IsoDate | — | — |
max | IsoDate | — | — |
unavailable | UnavailableDates | — | — |
error | string | null | — | The app's message about the value |
id | string | — | — |
disabled | boolean | — | — |
readOnly | boolean | — | — |
Events
| Event | Payload | Description |
|---|---|---|
Picked | { value: IsoDateTime | null; timeZone: TimeZoneId; instant: string | null } | A new day, time or zone: store value and timeZone; instant is the moment they name, as an ISO timestamp in UTC (null while the value is) |