Skip to content

Commit 1b7980c

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 da53e9a commit 1b7980c

File tree

4 files changed

+566
-0
lines changed

4 files changed

+566
-0
lines changed

docs/cookbook-tzdata.md

Lines changed: 14 additions & 0 deletions
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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,3 +567,9 @@ Extend `Temporal` to support arbitrarily-large years (e.g., **+635427810-02-02**
567567
Extend `Temporal` to support adjustment days for the Hijri calendars, which are sometimes required when the start of the month is based on astronomical observations.
568568

569569
[Adjustable Hijri calendar](hijri-days-adjustments.md)
570+
571+
### Time zone directly from tzdata rules
572+
573+
An example of building your own `Temporal.TimeZone` object from [tzdata-compatible rules](https://data.iana.org/time-zones/tz-how-to.html).
574+
575+
[Time zone from tzdata](cookbook-tzdata.md)

docs/cookbook/all.mjs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import './getNextOffsetTransitionFromExactTime.mjs';
1717
import './getParseableZonedStringAtInstant.mjs';
1818
import './getSortedLocalDateTimes.mjs';
1919
import './getTimeStamp.mjs';
20+
import './getTimeZoneObjectFromRules.mjs';
2021
import './getTripDurationInHrMinSec.mjs';
2122
import './getUtcOffsetDifferenceSecondsAtInstant.mjs';
2223
import './getUtcOffsetSecondsAtInstant.mjs';

0 commit comments

Comments
 (0)