Skip to content

Commit 6554968

Browse files
committed
Add more docs about changes
1 parent 1cf37f5 commit 6554968

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

README.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,53 @@
1-
# Eleventy’s ISO8601 Date parser
1+
# Eleventy ISO8601 Date Parser
22

33
Features:
44

55
- Zero dependency super minimal ISO8601 date parsing library. Alternatives were [too lax, inaccurate, huge on disk, or huge 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)
6+
- All dates supported by this library are RFC-9557 compatible (parseable by `Temporal.Instant.from` or `Temporal.PlainDateTime.from`) to prepare for wider [Temporal API](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Temporal) support.
7+
- Note that this is not a full polyfill — not all RFC-9557 dates are supported here. Alternatives: [`temporal-polyfill`](https://github.com/fullcalendar/temporal-polyfill) or [`js-temporal/temporal-polyfill`](https://github.com/js-temporal/temporal-polyfill)
8+
- Defaults to UTC when time zone is unknown instead of local time
109
- This matches previous behavior in Eleventy and this feature maintains consistency between build and deploy servers.
1110
- Supports +00:00 or -00:00 style time zone offsets
1211
- Invalid strings throw errors.
12+
- Delimiter notes:
13+
- Requires the `T` delimiter for Date and Time
14+
- Dates with 8 digits do not require `-` delimiters (all other dates require delimiters, e.g. `YYYY-MM`)
15+
- Times with 6 digits do not require `:` delimiters (all others times require delimiters, e.g. `HH:II`)
1316

14-
Not supported:
17+
Not supported (for RFC 9557 compatibility):
1518

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).
19+
- Standalone time formats are *not* supported (must be Date or DateTime)
20+
- [ISO week date syntax](https://en.wikipedia.org/wiki/ISO_week_date) is *not* supported (e.g. `YYYY-W01-1`)
21+
- Day of year syntax is *not* supported (e.g. `YYYY-001`, `YYYY-365`)
22+
- Fractional syntax for hours or minutes (e.g. `T14.6` or `T10:30.6`) is *not* supported. Fractional seconds (e.g. milliseconds) are supported (of course).
2023

21-
## `luxon` Comparison
24+
## Usage
25+
26+
```
27+
npm install @11ty/parse-date-strings
28+
```
29+
30+
```js
31+
import { parse } from "@11ty/parse-date-strings
32+
33+
// returns JavaScript Date object
34+
parse("2000-01-01") instanceof Date
35+
> true
36+
37+
// Convert to UTC String
38+
parse("2000-01-01").toUTCString()
39+
> "Mon, 01 Jan 2001 00:00:00 GMT"
40+
```
41+
42+
## Comparisons
43+
44+
### `luxon`
2245
2346
More strict parsing compared with [Luxon’s `fromISO`](https://moment.github.io/luxon/#/parsing?id=iso-8601) (used in Eleventy v0.x through v3):
2447
2548
```
26-
2016
27-
2016-05
49+
2016 # Dropped
50+
2016-05 # Dropped
2851
201605 # Dropped, delimiter required if date is not 8 digits
2952
2016-05-25
3053
20160525

0 commit comments

Comments
 (0)