Skip to content

Units and types ​

Units ​

Comparisons, startOf and endOf share one set of units. Each also goes by its plural and the aliases below. Aliases are case-sensitive, as in Day.js: M is month, m minute.

UnitAliasesKind
yearyears, ycalendar
monthmonths, Mcalendar
weekweeks, wcalendar
daydays, dcalendar
hourhours, htime
minuteminutes, m, min, minstime
secondseconds, s, sec, secstime
millisecondmilliseconds, mstime

Units follow the receiver:

  • PlainDate takes calendar units: it has no clock.
  • Instant takes time units: it has no calendar.
  • PlainDateTime and ZonedDateTime take both.
ts
Chronos(today).isSame(deadline, "M"); // fine
Chronos(today).isSame(deadline, "hour"); // type error: a PlainDate has no hours

Exported types ​

All are type-only exports from chronos-temporal.

TypeWhat it is
SupportedTemporalTypePlainDate | PlainDateTime | ZonedDateTime | Instant
CalendarUnitCalendar units, by name or alias
TimeUnitTime units, by name or alias
UnitCalendarUnit | TimeUnit
UnitOf<T>The units a value of type T supports
BetweenOptions<T>Options of isBetween and range checks
ZonedParseOptionsOptions of Chronos.parse for zoned types
Query<T>The query methods
Manipulate<T>The manipulate methods
Display<T>The display methods
Range<T>What Chronos.range returns
ParseThe signature of Chronos.parse

Chronos(value) returns Query<T> & Manipulate<T> & Display<T>, but by the contract that type never leaves the expression.

Overloads ​

Chronos and Chronos.range have one overload per type, so a union-typed receiver is rejected rather than widening the argument type and hiding a PlainDate-versus-ZonedDateTime mix. Narrow the value first.

Released under the MIT licence.