Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookbook example for compiling time zone from tzdata rules #1370

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reason to this is split into a separate md file? The other examples all embed directly.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two reasons: one is that these last few examples are much larger than the other cookbook snippets, so for practicality they can live on their own pages. The other reason is that these last few examples are not so much intended as "copy this recipe if you want to do X" but more like "here's something esoteric that Temporal is capable of, that you probably won't need to do, but you might adapt this recipe for something else".

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