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 are not part of the bare ldml dialect — they convert only through the dateFns library (from: momentjs, to: dateFns). A dialect → dialect conversion literalizes them instead.

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 produces the standards-correct token; enabling these options is the caller’s responsibility. The converter does not track which options you enabled — if a token needs one you did not pass, date-fns throws at format() time, which is the authoritative signal for your exact version.

Last updated on