A date is a string. Date math should be too.
A date is '2026-11-18', a time is '14:30', an instant is the number Date.now() returns. add, diff, startOf and toInstant are plain functions over those values, with daylight-saving rules that follow Temporal's, and no Date object on the calendar path.
bun add @pyreon/time - status
- ExperimentalThe value layer is complete and checked against
Temporal. The API may change in a minor release before it is promoted to Stable. - values
- strings and numbers
'2026-11-18','14:30',Date.now(). Nothing to construct withnew. - checked against
TemporalSeeded randomized tests compare arithmetic, weeks, grids and zones with it, plus hand-verified DST cases.- size
- 5.9 kB gzip for ten operationsFrom
@pyreon/time/core, DST rules included. Day.js with three plugins is 5.4 kB, date-fns 8.5 kB, Luxon 21.9 kB.
- 0
Dateobjects on the calendar arithmetic path, and no dependencies in@pyreon/time/coreor/fppackages/fundamentals/time/README.md ("no Date object on the path"; "core and /fp have no dependencies") - 5.9 kB gzip for ten operations with DST disambiguation, ISO weeks and strict validation; Day.js with three plugins is 5.4 kB, date-fns 8.5 kB and Luxon 21.9 kBBENCHMARKS.md, "@pyreon/time vs Date, Temporal, date-fns, Day.js, Luxon: bundle size (2026-11-18)"; re-run 2026-11-18 with
bun run bench:bundlein packages/fundamentals/time: Pyreon 5.90, Day.js 5.42, date-fns 8.53, Luxon 21.89 kB · Bun.build, minify, browser target, NODE_ENV=production, gzip -9
synthetic · author-run · M3 Max · record of 2026-11-05
Every result, including where we lose →Calendar math that does what the calendar does.
Plain values, plain functions
add('2026-01-31', { months: 1 })is'2026-02-28': the day clamps, and the result is a string of the same shape. No wrapper object, no clone, no.toString()to remember.Strings compare as strings
Values this package produces are canonical (
14:30, not14:30:00), so===, aMapkey and plain string sorting are all correct.normalizebrings in a value typed by hand.Zones without the traps
toInstant('2026-03-29T02:30', 'Europe/Prague')falls in a gap that does not exist. It resolves to03:30the way Temporal does, and you can ask forearlier,laterorrejectinstead.Calendars and clocks included
monthGridstarts weeks on the locale's first weekday (weekStartOf),quarterOfandstartOf(..., 'quarter')read quarters, anduseToday,useCountdownanduseRelativekeep a label current on shared timers.
The same month, two answers.
Month math overflows, and the result depends on the machine's time zone.
const d = new Date(2026, 0, 31)
d.setMonth(d.getMonth() + 1)
// d is March 3: February 31 rolled over.A string in, a string out. The day clamps.
import { add, diff } from '@pyreon/time/core'
add('2026-01-31', { months: 1 }) // '2026-02-28'
diff('2026-11-18', '2026-12-24', 'day') // 36Coming from date-fns, Day.js, Luxon or Temporal?
Strings in and out, no Date in between.
import { addMonths, differenceInCalendarDays, format, startOfWeek } from 'date-fns'
format(addMonths(new Date(2026, 0, 31), 1), 'yyyy-MM-dd') // '2026-02-28'
differenceInCalendarDays(new Date(2026, 11, 24), new Date(2026, 10, 18)) // 36
format(startOfWeek(new Date(2026, 10, 18), { weekStartsOn: 1 }), 'yyyy-MM-dd') // '2026-11-16'Same answers. date-fns works on Date objects in the machine's zone and needs @date-fns/tz for named zones; here a date is the string you already have. For the ten-operation set the bundle is 5.9 kB gzip against 8.5 kB for date-fns with its zone package, and printing in a language stays in @pyreon/format.
import { add, diff, startOf } from '@pyreon/time/core'
add('2026-01-31', { months: 1 }) // '2026-02-28'
diff('2026-11-18', '2026-12-24', 'day') // 36
startOf('2026-11-18', 'week') // '2026-11-16'The same calls without the wrapper.
import dayjs from 'dayjs'
dayjs('2026-01-31').add(1, 'month').format('YYYY-MM-DD') // '2026-02-28'
dayjs('2026-12-24').diff('2026-11-18', 'day') // 36Same answers. Day.js is the smaller of the two for the ten-operation set with its utc, timezone and isoWeek plugins: 5.4 kB gzip against 5.9 kB. The difference is that these are plain functions over strings (no wrapper object, no plugin to register) and the zone rules follow Temporal's disambiguation, with a fix-it error when a time does not exist.
import { add, diff } from '@pyreon/time/core'
add('2026-01-31', { months: 1 }) // '2026-02-28'
diff('2026-11-18', '2026-12-24', 'day') // 36Zone conversion without a DateTime.
import { DateTime } from 'luxon'
DateTime.fromISO('2026-11-18T09:00', { zone: 'America/New_York' })
.setZone('Asia/Tokyo')
.toFormat("yyyy-MM-dd'T'HH:mm") // '2026-11-18T23:00'Same answer. Luxon is the largest of the group for this task set: 21.9 kB gzip against 5.9 kB. The result here is a string you can compare, sort and store as it is.
import { toInstant, toPlainDateTime } from '@pyreon/time/core'
const at = toInstant('2026-11-18T09:00', 'America/New_York')
toPlainDateTime(at, 'Asia/Tokyo') // '2026-11-18T23:00'The same model, as plain strings.
Temporal.PlainDate.from('2026-01-31').add({ months: 1 }).toString() // '2026-02-28'
Temporal.PlainDate.from('2026-11-18').until('2026-12-24', { largestUnit: 'day' }).days // 36
Temporal.ZonedDateTime.from('2026-11-18T09:00[America/New_York]')
.withTimeZone('Asia/Tokyo').toPlainDateTime().toString() // '2026-11-18T23:00:00'Temporal is the standard, and native Temporal is far smaller than any library (0.41 kB for the adapter code in the size test): use it where every runtime you ship to has it. This package follows its model (plain dates, DST disambiguation) without depending on it, runs in any engine today, and its tests compare every arithmetic, week, grid and zone function with Temporal where Temporal exists. Output differs in one detail: canonical times drop zero seconds (23:00, not 23:00:00).
import { add, diff, toInstant, toPlainDateTime } from '@pyreon/time/core'
add('2026-01-31', { months: 1 }) // '2026-02-28'
diff('2026-11-18', '2026-12-24', 'day') // 36
toPlainDateTime(toInstant('2026-11-18T09:00', 'America/New_York'), 'Asia/Tokyo') // '2026-11-18T23:00'A calendar, a planner and live clocks.
Everything below is @pyreon/time. The calendar is monthGrid with the week starting where the language says (weekStartOf); click a day or use the arrow, Home, End and Page keys. The strip shows month math clamping on the 31st. The planner converts one wall-clock time between three zones, including days when the clocks skip an hour. The clocks tick on shared timers.
January 2026
Arrow keys move, Home and End jump to the week's edges, Page keys change month (Shift: year).
Selected
2026-01-31Add 1 month
2026-02-28Add 30 days
2026-03-02Start of week
2026-01-25Start of quarter
2026-01-01 (Q1)End of month
2026-01-31ISO week, day of year
W5, day 31
The 31th does not exist next month: the day clamps to 28.
New York
2026-03-28T21:30 · UTC-4Prague
2026-03-29T03:30 · UTC+2Tokyo
2026-03-29T10:30 · UTC+9
02:30 does not exist on 2026-03-29 in Prague: the clocks skip an hour, so it resolves to 03:30.
Now in Prague
–Today in Tokyo
–New Year in Prague
–
Three clocks, two shared timers: one per granularity, not one per reader.
Plain functions, the whole calendar.
- Values you can read
PlainDate,PlainTime,PlainDateTimeandPlainYearMonthare string types with template-literal shapes, so a literal type-checks without a cast. addandsubtractYears, months, weeks, days and time units. Month and year math clamps the day; the result has the same shape as the input.diffandbetweenWhole units from one value to another, truncated toward zero;betweengives the largest-unit breakdown, ready for a duration formatter.startOfandendOfFrom a millisecond to a year, quarters included, with a configurable week start.- Compare and clamp
compare,isBefore,isAfter,isSame,min,maxandclampon same-shape values. - Canonical output Produced values are the shortest exact form, so
===and string sorting are correct;normalizeandparseISObring outside values to the same form. - Calendar queries
dayOfWeek,weekOfYear,quarterOf,daysInMonth,isLeapYear,eachDay,iterateDays,weekStartOfandweekendOf. monthGridWeeks of dates for a month view, starting on any weekday, padded with the neighbouring months, four to six rows or always six.- Zones and instants
toInstant,toPlainDateTime,offsetAtandaddInstant, with four disambiguation modes for gaps and overlaps and one cachedIntlformatter per zone. - Clock hooks
useTodayflips at local midnight,useCountdownanduseElapsedtick every second,useRelativeadapts its cadence to the distance. Many readers share one timer. - Composable
@pyreon/time/fphas the value-last form of each operation, so you can name and chain them withpipe, andinZoneapplies a zone once. - Strict checks
isPlainDate('2026-02-30')isfalse: the shape and the calendar must both be real, and errors say how to fix the call.
Things to build with it.
Add a month to the last day of January and land on the last day of February, not on March.
import { add, diff } from '@pyreon/time/core'
const due = add('2026-01-31', { months: 1 }) // '2026-02-28'
diff('2026-01-31', due, 'day') // 28Resolve the wall-clock time once to an instant, then read it back in each zone.
import { toInstant, toPlainDateTime } from '@pyreon/time/core'
const at = toInstant('2026-11-18T09:00', 'America/New_York')
toPlainDateTime(at, 'America/New_York') // '2026-11-18T09:00'
toPlainDateTime(at, 'Europe/Prague') // '2026-11-18T15:00'
toPlainDateTime(at, 'Asia/Tokyo') // '2026-11-18T23:00'Prague skips 02:00 to 03:00 on 2026-03-29. Say what you want when someone asks for 02:30 that day, or let reject fail with a message that names the options.
import { toInstant, toPlainDateTime } from '@pyreon/time/core'
const ask = (disambiguation: 'earlier' | 'later') =>
toPlainDateTime(toInstant('2026-03-29T02:30', 'Europe/Prague', { disambiguation }), 'Europe/Prague')
toPlainDateTime(toInstant('2026-03-29T02:30', 'Europe/Prague'), 'Europe/Prague') // '2026-03-29T03:30' (compatible, the default)
ask('earlier') // '2026-03-29T01:30'
ask('later') // '2026-03-29T03:30'
// { disambiguation: 'reject' } throws: "[Pyreon] toInstant: 2026-03-29T02:30 does not exist in Europe/Prague ..."A day later and 24 hours later are different times on the day the clocks change.
import { addInstant, toInstant, toPlainDateTime } from '@pyreon/time/core'
const noon = toInstant('2026-03-28T12:00', 'Europe/Prague')
toPlainDateTime(addInstant(noon, { days: 1 }, 'Europe/Prague'), 'Europe/Prague') // '2026-03-29T12:00'
toPlainDateTime(addInstant(noon, { hours: 24 }, 'Europe/Prague'), 'Europe/Prague') // '2026-03-29T13:00'weekStartOf reads the week's first day from the locale data; monthGrid takes it as weekStart.
import { monthGrid, weekStartOf } from '@pyreon/time/core'
weekStartOf('en-US') // 7 (Sunday)
weekStartOf('cs') // 1 (Monday)
weekStartOf('ar') // 6 (Saturday)
monthGrid('2026-11', { weekStart: weekStartOf('cs') })[0]
// ['2026-10-26', '2026-10-27', '2026-10-28', '2026-10-29', '2026-10-30', '2026-10-31', '2026-11-01']
monthGrid('2026-11', { weekStart: weekStartOf('en-US') })[0]
// ['2026-11-01', '2026-11-02', '2026-11-03', '2026-11-04', '2026-11-05', '2026-11-06', '2026-11-07']Plain functions, three entries.
Every export has a reference page with its signature, an example and the mistakes people make with it.
- plainDate
- plainYearMonth
- plainTime
- isPlainDate
- isPlainTime
- isPlainDateTime
- isPlainYearMonth
- dateParts
- timeParts
- normalize
- parseISO
- add
- subtract
- diff
- between
- startOf
- endOf
- toMilliseconds
- compare
- isBefore
- isAfter
- isSame
- min
- max
- clamp
- dayOfWeek
- dayOfYear
- weekOfYear
- quarterOf
- daysInMonth
- isLeapYear
- eachDay
- iterateDays
- monthGrid
- weekStartOf
- weekendOf
- toInstant
- toPlainDateTime
- toPlainDate
- toPlainTime
- offsetAt
- addInstant
- isTimeZone
- inZone
- now
- today
- setClock
- useToday
- useCountdown
- useElapsed
- useRelative
- relativeDistance
- @pyreon/time
- @pyreon/time/core
- @pyreon/time/fp
Good to know before you start.
Experimental
The API may change in a minor release before it is promoted to Stable. Pin the version while you build on it.
Clock hooks print the request clock on the server
useToday, useCountdown, useElapsed and useRelative start no timer on a server and read the request's clock. Render clockScript() from @pyreon/ambient so the first client render reads the same instant, or show the value after mount.
Months and years are not milliseconds
toMilliseconds throws for months and years, because their length depends on the date. Use diff, or addInstant with a zone.
The proleptic Gregorian calendar
Years run from 0001 to 9999. Months are 1 to 12 and weekdays are ISO 1 (Monday) to 7 (Sunday): unlike Date, nothing is zero-based.
Strings are checked at the boundary
A plain string does not type-check as a PlainDate; isPlainDate is the guard. The types are looser than the runtime check, because template literal types cannot count digits.
iOS and Android are not covered yet
The package is web-only today.
What people ask first.
Why not use Temporal?
Use it where every runtime you ship to has it: native Temporal is far smaller than any library. This package follows Temporal's model (plain dates, four disambiguation modes for gaps and overlaps) without depending on it, works in any engine today as plain strings and numbers, and its test suite compares its answers with Temporal wherever Temporal exists.
How big is it?
For ten operations (add days and months, diff in days, compare, start of week and month, a month grid, parse ISO, an instant to wall time and back in a zone), @pyreon/time/core is 5.90 kB gzip. Day.js with utc, timezone and isoWeek is 5.42 kB, so Day.js is smaller. date-fns with @date-fns/tz is 8.53 kB and Luxon 21.89 kB. Hand-written UTC code with Date is 0.58 kB and native Temporal 0.41 kB, without DST disambiguation, ISO weeks or validation. add alone is 2.65 kB. Measured with Bun's bundler, minified, gzip -9.
How fast is it?
We have not published timing numbers, so this page makes no speed claim. The benchmarks are written and gate-checked against Temporal on every input, but they have not been run on a quiet machine.
Where do the clock and the time zone come from?
From @pyreon/ambient, which holds the locale, the time zone and the clock and is shared with @pyreon/format. setTimeZone changes the zone every reader of the clock hooks uses, and setClock pins the clock in tests. The Ambient docs page, linked below, covers the server hand-over.
Does it work with @pyreon/format?
Yes. A PlainDate is a calendar value there and never shifts with the time zone, between(a, b) returns the duration shape formatDuration takes, and useRelative returns the { value, unit } that @pyreon/format turns into words.
Does it run on iOS and Android?
Not yet; the package is web-only today.
Built to be used together.
Format
Print these values in the reader's language, with calendar dates that never shift.
Ambient
The locale, time zone and clock that time and format share. It has no product page; its docs page covers it.
RX
Use the value-last functions as map and groupBy callbacks.
Table
Sort and filter columns of ISO dates as plain strings.
Count the days the way the calendar does.
bun add @pyreon/time