Skip to content

Commit 4fc9cf5

Browse files
committed
cookbook: Add "Time zone from tzdata rules" example
An example of parsing the rules from the tzdata (sometimes called "Olson database") directly, and creating a Temporal.TimeZone object out of them. Closes: #605
1 parent 022f6f0 commit 4fc9cf5

File tree

4 files changed

+566
-0
lines changed

4 files changed

+566
-0
lines changed

docs/cookbook-tzdata.md

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Time zone directly from tzdata rules
2+
3+
This is an example of building your own `Temporal.TimeZone` object from [tzdata-compatible rules](https://data.iana.org/time-zones/tz-how-to.html).
4+
5+
This could be useful for testing, for example, or for using other versions of the tzdata than are installed on the host system.
6+
7+
The code in this example is inefficient.
8+
In real production code, it would make more sense to load the data from a compiled form, not directly from the rules themselves.
9+
10+
> **NOTE**: This is a very specialized use of Temporal and is not something you would normally need to do.
11+
12+
```javascript
13+
{{cookbook/getTimeZoneObjectFromRules.mjs}}
14+
```

docs/cookbook.md

+6
Original file line numberDiff line numberDiff line change
@@ -471,3 +471,9 @@ Extend Temporal to support arbitrarily-large years (e.g., **+635427810-02-02**)
471471
An example of using `Temporal.TimeZone` for other purposes than a standard time zne.
472472

473473
[NYSE time zone](cookbook-nyse.md)
474+
475+
### Time zone directly from tzdata rules
476+
477+
An example of building your own `Temporal.TimeZone` object from [tzdata-compatible rules](https://data.iana.org/time-zones/tz-how-to.html).
478+
479+
[Time zone from tzdata](cookbook-tzdata.md)

docs/cookbook/all.mjs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import './getParseableZonedStringAtInstant.mjs';
1818
import './getSortedLocalDateTimes.mjs';
1919
import './getTimeStamp.mjs';
2020
import './getTimeZoneObjectFromIanaName.mjs';
21+
import './getTimeZoneObjectFromRules.mjs';
2122
import './getTripDurationInHrMinSec.mjs';
2223
import './getUtcOffsetDifferenceSecondsAtInstant.mjs';
2324
import './getUtcOffsetSecondsAtInstant.mjs';

0 commit comments

Comments
 (0)