moment
The Moment.js-style token grammar. Imported from rosetta-date/dialects:
import { moment } from 'rosetta-date/dialects'- Spec: Moment.js format tokens
- Family:
delimited— ASCII letters are token characters - Literals: brackets
[...]— see Literals & Adjacency
Tokens
Each token and the canonical field it maps to. For how these compare across dialects, see Token Mapping.
| Meaning | Token |
|---|---|
| Era, abbreviated | N |
| Era, wide | NNNN |
| Era, narrow | NNNNN |
| Calendar year | YYYY |
| Calendar year, 2-digit | YY |
| Local week-numbering year | gggg |
| Local week-numbering year, 2-digit | gg |
| ISO week-numbering year | GGGG |
| ISO week-numbering year, 2-digit | GG |
| Quarter | Q |
| Quarter, ordinal | Qo |
| Month | M |
| Month, 2-digit | MM |
| Month, ordinal | Mo |
| Month, abbreviated | MMM |
| Month, wide | MMMM |
| Local week of year | w |
| Local week of year, 2-digit | ww |
| Local week of year, ordinal | wo |
| ISO week of year | W |
| ISO week of year, 2-digit | WW |
| ISO week of year, ordinal | Wo |
| Day of month | D |
| Day of month, 2-digit | DD |
| Day of month, ordinal | Do |
| Day of year | DDD |
| Day of year, 3-digit | DDDD |
| Day of year, ordinal | DDDo |
| Weekday, abbreviated | ddd |
| Weekday, wide | dddd |
| Weekday, short | dd |
| Weekday, number (locale) | d |
| Weekday, number (ISO) | E |
| AM/PM | A |
| AM/PM, lowercase | a |
| Hour 1–12 | h hh |
| Hour 0–23 | H HH |
| Hour 1–24 | k kk |
| Minute | m mm |
| Second | s ss |
| Fractional second | S SS SSS |
| Time-zone name | z |
Offset, ±hh:mm | Z |
Offset, ±hhmm | ZZ |
| Unix timestamp, seconds | X |
| Unix timestamp, milliseconds | x |
| Localized date (short / medium / long) | L ll LL |
| Localized time (short / with seconds) | LT LTS |
| Localized date + time (medium / long / full) | lll LLL LLLL |
Aliases
Extra spellings that are parsed but normalize to the primary token above when rendered:
Y→ calendar year (likeYYYY).NN/NNN→ abbreviated era (likeN).zz→ time-zone name (likez).
Caveats
- Narrow era (
NNNNN) renders the abbreviation (e.g.AD), not a true one-character form. - Weekday number
dis0–6(locale-dependent). Dialects that also expose a locale weekday number may number the days differently, so the numeric value is not guaranteed to match across dialects. Aandadiffer only in case — moment encodes case, not width. Lowercaseamaps to a distinct canonical, so it round-trips through grammars that also encode case (e.g.strftime’s%P), but falls to the unsupported-token policy for a target that cannot force lowercase.- A literal
]has no in-band escape inside a[...]run, so it is emitted between bracketed spans (a]b→[a]][b]); the text still round-trips intact.
Last updated on