Skip to content
@pyreon/time
fundamentals · dates

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
Documentation
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 with new.
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.
Dates are strings, and the operations are plain functions Schematic: three calls cycle. add('2026-01-31', { months: 1 }) returns '2026-02-28', because the day clamps to the end of February. diff('2026-11-18', '2026-12-24', 'day') returns 36. toPlainDateTime at an instant for 09:00 in New York, read in Asia/Tokyo, returns '2026-11-18T23:00'. A panel lists the four value shapes: PlainDate, PlainTime, PlainDateTime and Instant, all strings or numbers. A DATE IS A STRING · AN INSTANT IS A NUMBER call add('2026-01-31', { months: 1 })2026-02-28the day clamps to the end of Februarydiff('2026-11-18', '2026-12-24', 'day')36whole days between two stringstoPlainDateTime(at, 'Asia/Tokyo')2026-11-18T23:00at = 09:00 in New York, as an instant adddiffzone PlainDate'2026-11-18'PlainTime'14:30'PlainDateTime'2026-11-18T14:30'Instant1795010400000 plain functions, no Date object on the calendar path
  • 0 Date objects on the calendar arithmetic path, and no dependencies in @pyreon/time/core or /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:bundle in 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 →
why teams pick it

Calendar math that does what the calendar does.

  1. 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.

  2. Strings compare as strings

    Values this package produces are canonical (14:30, not 14:30:00), so ===, a Map key and plain string sorting are all correct. normalize brings in a value typed by hand.

  3. Zones without the traps

    toInstant('2026-03-29T02:30', 'Europe/Prague') falls in a gap that does not exist. It resolves to 03:30 the way Temporal does, and you can ask for earlier, later or reject instead.

  4. Calendars and clocks included

    monthGrid starts weeks on the locale's first weekday (weekStartOf), quarterOf and startOf(..., 'quarter') read quarters, and useToday, useCountdown and useRelative keep a label current on shared timers.

the difference

The same month, two answers.

Date

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.
with @pyreon/time

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') // 36
coming from

Coming from date-fns, Day.js, Luxon or Temporal?

Strings in and out, no Date in between.

date-fns
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'
Pyreon

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.

Day.js
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')              // 36
Pyreon

Same 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') // 36

Zone conversion without a DateTime.

Luxon
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'
Pyreon

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
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'
Pyreon

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'
try it

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.

Language (sets the first weekday)

January 2026

SunMonTueWedThuFriSat

Arrow keys move, Home and End jump to the week's edges, Page keys change month (Shift: year).

  • Selected

    2026-01-31
  • Add 1 month

    2026-02-28
  • Add 30 days

    2026-03-02
  • Start of week

    2026-01-25
  • Start of quarter

    2026-01-01 (Q1)
  • End of month

    2026-01-31
  • ISO week, day of year

    W5, day 31

The 31th does not exist next month: the day clamps to 28.

Day
Wall-clock time
In this zone
  • New York

    2026-03-28T21:30 · UTC-4
  • Prague

    2026-03-29T03:30 · UTC+2
  • Tokyo

    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.

what's included

Plain functions, the whole calendar.

  • Values you can read PlainDate, PlainTime, PlainDateTime and PlainYearMonth are string types with template-literal shapes, so a literal type-checks without a cast.
  • add and subtract Years, months, weeks, days and time units. Month and year math clamps the day; the result has the same shape as the input.
  • diff and between Whole units from one value to another, truncated toward zero; between gives the largest-unit breakdown, ready for a duration formatter.
  • startOf and endOf From a millisecond to a year, quarters included, with a configurable week start.
  • Compare and clamp compare, isBefore, isAfter, isSame, min, max and clamp on same-shape values.
  • Canonical output Produced values are the shortest exact form, so === and string sorting are correct; normalize and parseISO bring outside values to the same form.
  • Calendar queries dayOfWeek, weekOfYear, quarterOf, daysInMonth, isLeapYear, eachDay, iterateDays, weekStartOf and weekendOf.
  • monthGrid Weeks 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, offsetAt and addInstant, with four disambiguation modes for gaps and overlaps and one cached Intl formatter per zone.
  • Clock hooks useToday flips at local midnight, useCountdown and useElapsed tick every second, useRelative adapts its cadence to the distance. Many readers share one timer.
  • Composable @pyreon/time/fp has the value-last form of each operation, so you can name and chain them with pipe, and inZone applies a zone once.
  • Strict checks isPlainDate('2026-02-30') is false: the shape and the calendar must both be real, and errors say how to fix the call.
recipes

Things to build with it.

A deadline that clamps

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')                 // 28
One meeting, three time zones

Resolve 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'
A time that does not exist

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 is not 24 hours

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'
A month view that starts where the language does

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']
api

Plain functions, three entries.

Every export has a reference page with its signature, an example and the mistakes people make with it.

build and check · 11
  • plainDate
  • plainYearMonth
  • plainTime
  • isPlainDate
  • isPlainTime
  • isPlainDateTime
  • isPlainYearMonth
  • dateParts
  • timeParts
  • normalize
  • parseISO
arithmetic · 7
  • add
  • subtract
  • diff
  • between
  • startOf
  • endOf
  • toMilliseconds
compare · 7
  • compare
  • isBefore
  • isAfter
  • isSame
  • min
  • max
  • clamp
calendar · 11
  • dayOfWeek
  • dayOfYear
  • weekOfYear
  • quarterOf
  • daysInMonth
  • isLeapYear
  • eachDay
  • iterateDays
  • monthGrid
  • weekStartOf
  • weekendOf
zones and instants · 8
  • toInstant
  • toPlainDateTime
  • toPlainDate
  • toPlainTime
  • offsetAt
  • addInstant
  • isTimeZone
  • inZone
clocks · 8
  • now
  • today
  • setClock
  • useToday
  • useCountdown
  • useElapsed
  • useRelative
  • relativeDistance
entry points · 3
  • @pyreon/time
  • @pyreon/time/core
  • @pyreon/time/fp
good to know

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.

questions

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.

Count the days the way the calendar does.

bun add @pyreon/time
Read the Time guide