Skip to content

Commit

Permalink
cookbook: Add "Time zone from tzdata rules" example
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ptomato committed Feb 19, 2021
1 parent 3b9e891 commit 8f1d8f2
Show file tree
Hide file tree
Showing 4 changed files with 513 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/cookbook-tzdata.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
## Time zone directly from tzdata rules

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).

This could be useful for testing, for example, or for using other versions of the tzdata than are installed on the host system.

The code in this example is inefficient.
In real production code, it would make more sense to load the data from a compiled form, not directly from the rules themselves.

> **NOTE**: This is a very specialized use of Temporal and is not something you would normally need to do.
```javascript
{{cookbook/getTimeZoneObjectFromRules.mjs}}
```
6 changes: 6 additions & 0 deletions docs/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -471,3 +471,9 @@ Extend Temporal to support arbitrarily-large years (e.g., **+635427810-02-02**)
An example of using `Temporal.TimeZone` for other purposes than a standard time zne.

[NYSE time zone](cookbook-nyse.md)

### Time zone directly from tzdata rules

An example of building your own `Temporal.TimeZone` object from [tzdata-compatible rules](https://data.iana.org/time-zones/tz-how-to.html).

[Time zone from tzdata](cookbook-tzdata.md)
1 change: 1 addition & 0 deletions docs/cookbook/all.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import './getParseableZonedStringAtInstant.mjs';
import './getSortedLocalDateTimes.mjs';
import './getTimeStamp.mjs';
import './getTimeZoneObjectFromIanaName.mjs';
import './getTimeZoneObjectFromRules.mjs';
import './getTripDurationInHrMinSec.mjs';
import './getUtcOffsetDifferenceSecondsAtInstant.mjs';
import './getUtcOffsetSecondsAtInstant.mjs';
Expand Down
Loading

0 comments on commit 8f1d8f2

Please sign in to comment.