Duration Input

Parses durations typed many ways and reads them back in words, so 1.5 isn't logged as 1 h 50 min on a timesheet.

StopsTimesheet logs 1.5 as 1h50

Installation

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

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

Usage

duration-input-usage.tsx
import { DurationInput } from "@/components/ui/duration-input"

<DurationInput label="Time on task (hours)" unit="h" defaultValue="1.50" max={12 * 3600} />

What it catches

  • 1.50 meant as 1 h 50 min versus 1.5 hours
  • Ambiguous 1:30 (h:mm or m:ss), asked when limits can't decide
  • Values outside min and max, with the limit as a fix
  • Days converted using hoursPerDay (24 by default)

Props

DurationInput props
PropTypeDefault
label

Visible label.

string"Duration"
value

Controlled text, as typed.

string—
defaultValue

Initial text when uncontrolled.

string""
onValueChange

Called with the text and the duration in seconds, or null while it can't be read, is ambiguous or out of range.

(text: string, seconds: number | null) => void—
unit

Unit of a bare number such as "90".

DurationUnit"m"
colon

How "1:30" is read. "auto" uses min/max and asks when both readings fit.

ColonMode"auto"
min

Smallest allowed duration, in seconds.

number—
max

Largest allowed duration, in seconds.

number—
hoursPerDay

Hours in a "day", e.g. 8 for work-day estimates.

number24
hint

Helper text shown while the field is empty.

string—
messages

Override any of the default messages.

Partial<typeof DURATION_MESSAGES>—

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

Accessibility

  • Labelled input with the result read back in words
  • Each interpretation is a button with visible text

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

Limitations

  • Parses English unit words and abbreviations only
  • Days are 24 hours by default; set hoursPerDay (e.g. 8) for working days

What it stops

Timesheet logs 1.5 as 1h50

Also known as

duration · timesheet · hours · time tracking · estimate · jira · minutes · 1h30m

Dependencies

Pairs well with