|
| 1 | +# Eleventy’s ISO8601 Date parser |
| 2 | + |
| 3 | +Features: |
| 4 | + |
| 5 | +- Zero dependency super minimal ISO8601 date parsing library. Alternatives were [too lax, inaccurate, huge on disk, or hundle in bundle](https://fediverse.zachleat.com/@zachleat/114870836413532617). |
| 6 | +- Dates with 8 digits do not require `-` delimiters (all other dates require delimiters, e.g. `YYYY-MM`) |
| 7 | +- Times with 6 digits do not require `:` delimiters (all others times require delimiters, e.g. `HH:II`) |
| 8 | +- Requires the `T` delimiter for date and time |
| 9 | +- Defaults to UTC when time zone is unknown instead of local time (`Z` can be explicit or implied) |
| 10 | + - This matches previous behavior in Eleventy and this feature maintains consistency between build and deploy servers. |
| 11 | +- Supports +00:00 or -00:00 style time zone offsets |
| 12 | +- Invalid strings throw errors. |
| 13 | + |
| 14 | +Not supported: |
| 15 | + |
| 16 | +- Standalone times are not supported (must be date or datetime) |
| 17 | +- [ISO week date syntax](https://en.wikipedia.org/wiki/ISO_week_date) (e.g. `YYYY-W01-1`) |
| 18 | +- Day of year syntax is not supported (e.g. `YYYY-001`, `YYYY-365`) |
| 19 | +- Fractional syntax for hours or minutes (e.g. `T14.6` or `T10:30.6`). Fractional seconds (e.g. milliseconds) are supported (of course). |
| 20 | + |
| 21 | +## `luxon` Comparison |
| 22 | + |
| 23 | +More strict parsing compared with [Luxon’s `fromISO`](https://moment.github.io/luxon/#/parsing?id=iso-8601) (used in Eleventy v0.x through v3): |
| 24 | + |
| 25 | +``` |
| 26 | +2016 |
| 27 | +2016-05 |
| 28 | +201605 # Dropped, delimiter required if date is not 8 digits |
| 29 | +2016-05-25 |
| 30 | +20160525 |
| 31 | +2016-05-25T09 |
| 32 | +2016-05-25T09:24 |
| 33 | +2016-05-25T09:24:15 |
| 34 | +2016-05-25T09:24:15.123 |
| 35 | +2016-05-25T0924 |
| 36 | +2016-05-25T092415 |
| 37 | +2016-05-25T092415.123 |
| 38 | +2016-05-25T09:24:15,123 |
| 39 | +
|
| 40 | +# No ISO week date syntax |
| 41 | +2016-W21-3 # Dropped |
| 42 | +2016W213 # Dropped |
| 43 | +2016-W21-3T09:24:15.123 # Dropped |
| 44 | +2016W213T09:24:15.123 # Dropped |
| 45 | +
|
| 46 | +# No day of year syntax (e.g. 200th day of the year) |
| 47 | +2016-200 # Dropped |
| 48 | +2016200 # Dropped |
| 49 | +2016-200T09:24:15.123 # Dropped |
| 50 | +
|
| 51 | +# No implied current day (time-only syntax) |
| 52 | +09:24 # Dropped |
| 53 | +09:24:15 # Dropped |
| 54 | +09:24:15.123 # Dropped |
| 55 | +09:24:15,123 # Dropped |
| 56 | +``` |
0 commit comments