demo ยท v144
Duration Arithmetic
The biggest pain Temporal fixed isn’t parsing — it’s durations. Duration, since, until, round, balance, and total. Pick two instants and ask the question every billing system, calendar app, and analytics dashboard asks: how long was that?
Temporal: checking…
Temporal.Duration
—
legacy Date math
—
the API
const a = Temporal.PlainDateTime.from("2026-01-15T09:00:00");
const b = Temporal.PlainDateTime.from("2027-03-04T17:30:00");
// signed difference, balanced to a single unit
const dur = a.until(b, { largestUnit: "years" });
// => P1Y1M17DT8H30M (1 year, 1 month, 17 days, 8h30m)
// round to a coarser unit
dur.round({ smallestUnit: "days", relativeTo: a }); // P1Y1M18D
// total in arbitrary units
dur.total({ unit: "hours", relativeTo: a }); // 10208.5