Skip to Content

dateFns

The date-fns rendering target. Imported from rosetta-date/libraries:

import { dateFns } from 'rosetta-date/libraries'
  • Base grammar: ldml.
  • Extensions: ordinal forms, ISO week fields, the Unix epoch, and localized presets.
  • Support model: the reference implementation of the ldml grammar plus its own extensions; it renders the whole effective grammar, so it carries no supports set.

The extensions below belong to the dateFns library, not the bare ldml dialect. Use the library endpoint to convert them (from: momentjs, to: dateFns). A dialect → dialect conversion literalizes them.

Ordinals

date-fns renders ordinal forms (…o) that are not in UTS #35. They convert from the matching moment ordinals.

MeaningToken
Quarter, ordinalQo
Month, ordinalMo
Local week of year, ordinalwo
Day of month, ordinaldo
Day of year, ordinalDo
ISO week of year, ordinalIo

ISO week fields & epoch

MeaningToken
ISO week-numbering yearRRRR
ISO week of yearI
ISO week of year, 2-digitII
ISO weekday, numberi
Unix timestamp, secondst
Unix timestamp, millisecondsT

Localized presets

date-fns spells the full preset range, including widths the moment grammar lacks (full date, time-with-zone, short date-time). See Localized presets.

MeaningToken
Date, short / medium / long / fullP PP PPP PPPP
Time, short / with seconds / long / fullp pp ppp pppp
Date + time, short / medium / long / fullPp PPpp PPPppp PPPPpppp

Option-gated tokens

date-fns guards a few tokens behind options you must enable in its format() call:

  • Day of year (D, DD) requires useAdditionalDayOfYearTokens: true.
  • Local week-year (YY, YYYY) requires useAdditionalWeekYearTokens: true.

rosetta-date emits the mapped token, but does not track which date-fns options are enabled. If a token needs an option you did not pass, date-fns throws at format() time.

Last updated on