-
Notifications
You must be signed in to change notification settings - Fork 152
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1370 +/- ##
=======================================
Coverage 95.36% 95.36%
=======================================
Files 19 19
Lines 11123 11123
Branches 1826 1826
=======================================
Hits 10607 10607
Misses 511 511
Partials 5 5
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Huh, I thought we had private fields in Node 12, but I guess it was literally only fields and not methods. I'll rewrite the example not to use them. |
adb5a64
to
8f1d8f2
Compare
Private methods and accessors only landed in node 14 something. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pending moving the ES.TemporalDurationToString
fixes out from here per #1375, lgtm! (only separate them if you still want to - I'm fine shipping them as part of this).
I think it could be nice adding a quick test case for Pacific/Apia's day skip as well since we reference that example elsewhere in the docs a lot, but it's fine without it too.
|
||
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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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".
Is this intended to be a general-purpose tzdata parser, or just the minimum needed for the |
equal() was forgotten here, leading to these tests always passing.
These tests called getNextTransition() and getPreviousTransition() four times on the same instant, instead of chaining four calls.
getPreviousTransition() returns the last transition before the instant passed into it, not the last transition before or equal to. Otherwise, you would have to manually subtract a nanosecond in between each call if you wanted to get a series of previous transitions. Add similar tests for getNextTransition(), although that wasn't broken. No change needed to the spec text or documentation, which are already correct.
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
8f1d8f2
to
4fc9cf5
Compare
This is done, and it uncovered several bugs. So thanks for the suggestion. For ease of review, here's a list of what I had to change:
I wouldn't go so far as to claim that it's general purpose; that said, what does it fail on? I'd like to investigate that, even if not now then some other time. I have actually measured getNextTransition()/getPreviousTransition() to be faster using this code than the polyfill's current approach of using Intl to get the offset and bisecting, so it might come in handy when working on a production-quality polyfill. |
I tried it with the A couple of things still remain, though. The
The third line has a rule of There's also a subtle bug lurking in that example above. The
Agreed on this. I noticed the difference when stepping through the code in a debugger while trying to pinpoint the case above. This new code is definitely faster. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for forgetting about this one; I didn't previously re-review because of @gilmoreorless' assertion that some bugs remain, but then I forgot about it for quite a while as a result. If it's not intended to be general and just an example that works only with the included data, then I'm still good with shipping it! No new comments on the changes since prior review, still looks good to me.
Oh, I am still planning to address those, but it's on a lower priority right now until we get all the changes from the March TC39 plenary landed. |
An example of parsing the rules from the tzdata rules (sometimes called "Olson database") directly, and creating a Temporal.TimeZone object out of them. By far the longest cookbook example.
A few additional bug fixes in the polyfill, as well.
Closes: #605