Skip to content
// EFFECT DAYS 2026

TimeField unstable

A controlled time input that formats and parses text for a locale. Supply an <input> builder and a TimeOfDay | null value, then update that value from Committed events. The field keeps draft text while the user types.

Anatomy

Part Element
input <input>, the editable time field

input takes the consumer's <input> builder and returns it, so you can chain classes, attributes and handlers. It wraps the element in a <span style="display:contents">, which also holds the hidden form input when name is set.

The parts also return value, inputValue (the text the input shows), pattern (such as "hh:mm" or "hh:mm am", for a placeholder or hint), disabled, readOnly and required.

Time values

A TimeOfDay is a wall-clock time with no day or time zone, spelled as <input type="time"> submits it: "09:30", or "09:30:15" with seconds. Each time has one spelling, so equal times are equal strings and strings sort in time order.

Parsing

The locale determines 12-hour or 24-hour display unless hourCycle is set. Parsing accepts the locale's separators and AM/PM labels (case-insensitive), or 24-hour H:mm, which takes precedence. Invalid times such as 25:00 or 13:00 PM are rejected. Text with seconds is rejected unless seconds is enabled.

Naming and validation

Name the input with a <label for>, an aria-label, or a Field: draw it with timeField.input(field.control(h.input)) and pass disabled: field.disabled. TimeField never writes aria-invalid or id, leaving validation and labelling to Field. Rules such as opening hours belong in the app and its Field.

Data attributes

On input, each present with an empty value or absent:

  • data-disabled
  • data-readonly
  • data-required

Keyboard

On input, Enter commits the typed text; text that does not parse stays in the input. Enter is ignored while an input method is composing or with a modifier key held.

Events

Committed carries { time: TimeOfDay | null } when the user finishes editing with blur or Enter and the parsed time differs from value. Empty text commits null. On blur, text that does not parse commits nothing and reverts to the formatted value. Without seconds, a value with seconds shows without them and keeps them until the user edits the text.

Forms

When name is set, a hidden input submits the TimeOfDay ("" when empty) and the visible input has no name. A disabled field submits nothing.

The server formats with its own default locale, which may differ from the browser's, so pass locale when rendering on a server.

Example (Time slots in a Select, labelled like the field)

A list of slots is a Select or Combobox of TimeOfDay values. Build the items from a step and a range, disable the ones that are taken, and label them with formatTimeOfDay so they read like a TimeField.

Example (A day, a time and a time zone as one moment, with daylight saving time)

Call DateTime.makeZonedUnsafe with disambiguation: "earlier" and "later" to distinguish three cases:

  • Both readings are the same instant: the time is exact.
  • Different instants preserve the requested local date and time: the time is repeated.
  • The readings change the requested local date or time: the time is skipped.

The app decides which reading to keep. An invalid time zone throws.

Example A labelled time field whose value lives in the consumer's Model

import { UiSchema } from "effect/ui"
import { Html, HtmlServer } from "effect/ui/html"
import { Field, TimeField, TimeOfDay } from "effect/ui/kit"
import { Effect, Schema } from "effect"
const MeetingMessage = UiSchema.TaggedEnum({
CommittedStart: { start: Schema.NullOr(TimeOfDay) }
})
const Meeting = Html.component({
name: "Meeting",
model: Schema.Struct({ start: Schema.NullOr(TimeOfDay) }),
message: MeetingMessage
}).make({
init: () => ({ start: TimeOfDay.make("14:30") }),
update: {
CommittedStart: ($, { start }) => $.evolve({ start })
},
view: (h, model) =>
Field(h, {
view: (field) =>
TimeField(h, {
props: { value: model.start, locale: "en-US", name: "start", disabled: field.disabled },
onEmit: {
Committed: ({ time }) => MeetingMessage.CommittedStart({ start: time })
},
view: (timeField) =>
field.root(h.div).children(
field.label(h.label).children("Starts at"),
timeField.input(field.control(h.input.class("time"))).attr("placeholder", timeField.pattern)
)
})
})
})
const { html } = await Effect.runPromise(HtmlServer.renderToHtml(Meeting, {}))
if (!/<input class="time"[^>]*value="2:30.PM"/.test(html)) throw new Error("the input doesn't show the time")
if (!/<input[^>]*type="hidden"[^>]*name="start"[^>]*value="14:30"/.test(html)) throw new Error("no form value")

Example Time slots in a Select, labelled like the field

import { UiSchema } from "effect/ui"
import { Html, HtmlServer } from "effect/ui/html"
import { formatTimeOfDay, makeSelect, TimeOfDay, timeOfDayParts } from "effect/ui/kit"
import { Effect, Schema } from "effect"
const TimeSelect = makeSelect({ value: TimeOfDay })
const minutesOf = (time: TimeOfDay) => {
const { hour, minute } = timeOfDayParts(time)
return hour * 60 + minute
}
const pad = (n: number) => String(n).padStart(2, "0")
const slots = (min: TimeOfDay, max: TimeOfDay, step: number, taken: ReadonlySet<TimeOfDay>) => {
const items = []
for (let at = minutesOf(min); at <= minutesOf(max); at += step) {
const value = TimeOfDay.make(pad(Math.floor(at / 60)) + ":" + pad(at % 60))
items.push({ value, label: formatTimeOfDay(value, { locale: "en-US" }), disabled: taken.has(value) })
}
return items
}
const items = slots(TimeOfDay.make("09:00"), TimeOfDay.make("11:00"), 30, new Set([TimeOfDay.make("10:00")]))
const Message = UiSchema.TaggedEnum({
Picked: { time: TimeOfDay },
Toggled: { open: Schema.Boolean }
})
const Booking = Html.component({
name: "Booking",
model: Schema.Struct({ time: Schema.NullOr(TimeOfDay), open: Schema.Boolean }),
message: Message
}).make({
init: () => ({ time: TimeOfDay.make("09:30"), open: false }),
update: {
Picked: ($, { time }) => $.evolve({ time }),
Toggled: ($, { open }) => $.evolve({ open })
},
view: (h, model) =>
TimeSelect(h, {
props: { open: model.open, value: model.time, items, name: "time" },
onEmit: {
Picked: ({ value }) => typeof value === "string" ? Message.Picked({ time: value }) : undefined,
RequestedOpen: () => Message.Toggled({ open: true }),
RequestedClose: () => Message.Toggled({ open: false }),
Settled: () => undefined
},
view: (select) =>
h.div(
select.trigger(h.button).children(select.value(h.span)),
select.positioner(h.div).children(
select.popup(h.div).children(
items.map((item) => select.item({ element: h.div, value: item.value }).children(item.label))
)
)
)
})
})
if (items.map((item) => item.value).join() !== "09:00,09:30,10:00,10:30,11:00") throw new Error("wrong slots")
if (items.filter((item) => item.disabled).length !== 1) throw new Error("10:00 isn't disabled")
const { html } = await Effect.runPromise(HtmlServer.renderToHtml(Booking, {}))
if (!/<button[^>]*>.*9:30.AM/.test(html)) throw new Error("the trigger doesn't show the slot")

Example A day, a time and a time zone as one moment, with daylight saving time

import { TimeOfDay, timeOfDayParts } from "effect/ui/kit"
import { DateTime } from "effect"
type Moment =
| { readonly _tag: "Exact"; readonly at: DateTime.Zoned }
| { readonly _tag: "Repeated"; readonly earlier: DateTime.Zoned; readonly later: DateTime.Zoned }
| { readonly _tag: "Skipped"; readonly before: DateTime.Zoned; readonly after: DateTime.Zoned }
// `day` is a DateField value: midnight UTC on the chosen day.
const momentOf = (day: DateTime.Utc, time: TimeOfDay, timeZone: string): Moment => {
const { year, month, day: date } = DateTime.toPartsUtc(day)
const { hour, minute, second } = timeOfDayParts(time)
const at = (disambiguation: "earlier" | "later") =>
DateTime.makeZonedUnsafe(
{ year, month, day: date, hour, minute, second },
{ timeZone, adjustForTimeZone: true, disambiguation }
)
const earlier = at("earlier")
const later = at("later")
if (DateTime.Equivalence(earlier, later)) return { _tag: "Exact", at: earlier }
// Compare the date too: a zone change can skip an entire day.
const wall = DateTime.toParts(earlier)
return wall.year === year && wall.month === month && wall.day === date &&
wall.hour === hour && wall.minute === minute && wall.second === second
? { _tag: "Repeated", earlier, later }
: { _tag: "Skipped", before: earlier, after: later }
}
const day = (month: number, date: number, year = 2025) => DateTime.makeUnsafe({ year, month, day: date })
const time = TimeOfDay.make("01:30")
if (momentOf(day(6, 1), time, "America/New_York")._tag !== "Exact") throw new Error("not exact")
if (momentOf(day(11, 2), time, "America/New_York")._tag !== "Repeated") throw new Error("not repeated")
const skipped = momentOf(day(3, 9), TimeOfDay.make("02:30"), "America/New_York")
if (skipped._tag !== "Skipped") throw new Error("not skipped")
if (DateTime.formatIsoOffset(skipped.after) !== "2025-03-09T03:30:00.000-04:00") throw new Error("wrong reading")
// Samoa skipped all of 2011-12-30.
if (momentOf(day(12, 30, 2011), TimeOfDay.make("12:00"), "Pacific/Apia")._tag !== "Skipped") throw new Error("skipped day")
9 exports Since v4.2.0 Source

Components

TimeField

unstable
Since v4.2.0

A headless time field. Call it with the consumer's h, the props, and a view closure that draws the input with timeField.input(h.input).

Details

The field's own attributes win over the ones the consumer set on the builder before the part, including the ones a state leaves absent:

  • input: type, name (removed from the visible input so the hidden input submits the time), form, required, readonly, disabled, aria-disabled (removed), data-disabled, data-readonly, data-required and value.

autocomplete, autocorrect and spellcheck are written only when the builder has none. aria-invalid and id are never written, so Field keeps full ownership of them.

The input handles input, blur and keydown on a layer of its own, so the consumer's handlers for them, and a Field's, still run.

Draft text is not restored after history navigation or a reload.

Signature

declare const TimeField: Headless<{
readonly disabled?: boolean;
readonly form?: string;
readonly hourCycle?: "h12" | "h23";
readonly locale?: string | readonly Array<string>;
readonly name?: string;
readonly readOnly?: boolean;
readonly required?: boolean;
readonly seconds?: boolean;
readonly value: string & Brand<"TimeOfDay"> | null;
}, {
readonly _tag: "Committed";
readonly time: string & Brand<"TimeOfDay"> | null;
}, {
disabled: boolean;
input: Part<"input", [], never>;
inputValue: string;
pattern: string;
readOnly: boolean;
required: boolean;
value: string & Brand<"TimeOfDay"> | null;
}, never, never, never, never, never, never, {
readonly draft: string | null;
}, {
readonly _tag: "PressedEnter";
} | {
readonly _tag: "BlurredInput";
readonly disabled: boolean;
} | {
readonly _tag: "UpdatedInput";
readonly value: string;
}, QueryEntries<{}, {}>>

Models

TimeFieldEvents

type unstable
Since v4.2.0

What a TimeField emits.

Signature

type TimeFieldEvents = typeof TimeFieldEvents.Type

TimeFieldProps

type unstable
Since v4.2.0

The props of a TimeField.

Signature

type TimeFieldProps = typeof TimeFieldProps.Type

TimeOfDay

type unstable
Since v4.2.0

A time of day with no day or time zone, such as "09:30".

Signature

type TimeOfDay = typeof TimeOfDay.Type

Schemas

Since v4.2.0

Committed requests a new value through its time payload, or null when the field is cleared.

Signature

declare const TimeFieldEvents: TaggedEnum<{
Committed: TaggedStruct<"Committed", {
readonly time: NullOr<brand<String, "TimeOfDay">>;
}>;
}>
Since v4.2.0

Props for a TimeField.

Details

  • value: the time, or null for an empty field.
  • locale: the locale used to format, parse and derive pattern; the runtime's default when left out.
  • hourCycle: "h12" for 12-hour text with AM/PM, "h23" for 24-hour text; the locale's when left out.
  • seconds: shows and accepts seconds.
  • name: the form field name for the hidden input carrying the time.
  • form: the id of the form that submits it, when the field is not inside one.
  • disabled: disables both inputs and commits nothing.
  • readOnly: keeps the input focusable and selectable but commits nothing.
  • required: sets the native required attribute.

Signature

declare const TimeFieldProps: Struct<{
readonly disabled: optional<Boolean>;
readonly form: optional<String>;
readonly hourCycle: optional<Literals<readonly ["h12", "h23"]>>;
readonly locale: optional<Union<readonly [String, $Array<String>]>>;
readonly name: optional<String>;
readonly readOnly: optional<Boolean>;
readonly required: optional<Boolean>;
readonly seconds: optional<Boolean>;
readonly value: NullOr<brand<String, "TimeOfDay">>;
}>

TimeOfDay

unstable
Since v4.2.0

A time of day with no day or time zone: "HH:mm", or "HH:mm:ss" when the seconds aren't zero, as <input type="time"> submits it.

Details

Hours run from 00 to 23. Zero seconds are left off, so "09:30:00" is rejected in favour of "09:30": each time has one spelling, and comparing two strings compares the times.

Signature

declare const TimeOfDay: brand<String, "TimeOfDay">

Example Making and reading a time

import { TimeOfDay, timeOfDayParts } from "effect/ui/kit"
import { Schema } from "effect"
const start = TimeOfDay.make("09:30")
if (timeOfDayParts(start).minute !== 30) throw new Error("wrong minute")
if (Schema.is(TimeOfDay)("09:30:00")) throw new Error("zero seconds are spelled 09:30")

Utils

Since v4.2.0

Formats a slot label to match a TimeField using the same options.

Details

  • locale: the runtime's default when left out.
  • hourCycle: "h12" or "h23"; the locale's when left out.
  • seconds: shows the seconds. Left off when false or left out.

Signature

declare function formatTimeOfDay(time: string & Brand<"TimeOfDay">, options?: {
readonly hourCycle?: "h12" | "h23";
readonly locale?: Locale;
readonly seconds?: boolean;
}): string
Since v4.2.0

Returns the hour (0โ€“23), minute and second, using zero for omitted seconds.

Signature

declare function timeOfDayParts(time: string & Brand<"TimeOfDay">): {
readonly hour: number;
readonly minute: number;
readonly second: number;
}