Add thorough tests for time zone transitions#3295
Conversation
|
@justingrant Can you think of any more time zone invariants that should be tested here? |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3295 +/- ##
=======================================
Coverage 97.83% 97.83%
=======================================
Files 22 22
Lines 10725 10725
Branches 1856 1856
=======================================
Hits 10493 10493
Misses 215 215
Partials 17 17 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
a9b6568 to
5e301d0
Compare
Ms2ger
left a comment
There was a problem hiding this comment.
This seems reasonable; I'll leave it open in case Justin wants to comment but otherwise feel free to merge
justingrant
left a comment
There was a problem hiding this comment.
Looks good. The only change I'd consider would be to apply some limit on the difference between the earlier and later instants. Other than the weird Samoa 2011 instance which could be special-cased, we should verify that the difference is not larger than N hours, which we could derive experimentally. I suspect cases > 2 hours could likely be counted on one hand.
This adds test/thorough/timezones.mjs which tests certain invariants for
time zone transitions in every supported time zone. (It doesn't use
snapshots, because those might have to be updated when the IANA database
updates.)
For every time zone, it takes the first five transitions after 1850
(which was about when time zones started being used) and the last two
transitions before 2000 (which should cover one spring-forward and one
fall-back transition in zones that use DST), and for each of those seven
transitions, tests
- That each `disambiguation` value has the expected effect
- That .with({ offset }) works to switch between the two repeated times
in a fall-back transition
This covers many different sizes of UTC offset shift, from 24 hours down
to 4 seconds, with the most common being -1 hour and +1 hour.
See: #556, tc39/test262#3002
5e301d0 to
d66e781
Compare
|
Yep, 2 hours seems about right. I'll verify these later against the implementations. There are some divergences but I'm not sure if it's because of bugs or just TZDB version discrepancies. |
This adds test/thorough/timezones.mjs which tests certain invariants for time zone transitions in every supported time zone. (It doesn't use snapshots, because those might have to be updated when the IANA database updates.)
For every time zone, it takes the first five transitions after 1850 (which was about when time zones started being used) and the last two transitions before 2000 (which should cover one spring-forward and one fall-back transition in zones that use DST), and for each of those seven transitions, tests
disambiguationvalue has the expected effectThis covers many different sizes of UTC offset shift, from 24 hours down to 4 seconds, with the most common being -1 hour and +1 hour.
See: #556, tc39/test262#3002