Epoch Input

Reads a timestamp back as a date in your zone and UTC and catches unit mix-ups, so a value isn't saved as year 57,754 or the wrong hour.

StopsTimestamp saved as year 57754

Installation

pnpm dlx shadcn@latest add https://bollard-ui.vercel.app/r/epoch-input.json

The files land in your project. They're yours to edit.

Usage

epoch-input-usage.tsx
import { EpochInput } from "@/components/ui/epoch-input"

return <EpochInput label="Trial ends at (Unix seconds)" unit="s" defaultValue="1760400000000" timeZone="Asia/Kolkata" now={Date.UTC(2025, 9, 10)} />

What it catches

  • Milliseconds where seconds belong (and micro/nanoseconds)
  • Excel serial dates, Windows FILETIME and .NET ticks
  • ISO strings with no time zone, which JavaScript and servers read differently
  • Date-only strings read as UTC midnight
  • Impossible dates (30 Feb) and values outside 32-bit range when int32 is set

Props

EpochInput props
PropTypeDefault
value

Controlled text.

string—
defaultValue

Initial text when uncontrolled.

string""
onValueChange

Called with the text on every edit or fix.

(value: string) => void—
onTimestampChange

Called with the instant it reads as, in ms, or null when it can't be read.

(ms: number | null) => void—
unit

The unit the field stores. A value in another unit is flagged with a one-tap conversion.

EpochUnit—
range

Years a real value falls in. Defaults to 1970–2100.

[number, number]—
int32

Flag values a signed 32-bit time can't hold (after 19 Jan 2038 03:14:07 UTC).

boolean—
timeZone

Time zone to read the value back in. Defaults to the device's.

string—
locale

Locale for dates.

string"en-GB"
now

Clock for "in 3 days" and for picking the likeliest unit, in ms. Defaults to the time the component mounted.

number—
label

Visible label; shorthand for `messages.label`.

string—
messages

Every visible string. `{found}`, `{expected}`, `{asIs}` and the other placeholders are filled in.

Partial<EpochInputMessages>—

* required. Also accepts the native props of <input> (className, aria-*, data-*…), passed through to it.

Accessibility

  • Visible <label>; aria-invalid and aria-describedby to the readback
  • After a fix, focus moves to the next fix or back to the input
  • Motion respects prefers-reduced-motion

Only what the source does. Test with your own screen reader and content before shipping.

Limitations

  • Unit guesses rely on plausible ranges; very old or far-future dates can be misread
  • Time zones come from the browser's Intl data

What it stops

Timestamp saved as year 57754

Also known as

unix timestamp · epoch · epoch converter · milliseconds · iso 8601 · utc · date-fns · created_at

Dependencies

Pairs well with