Skip to content

Add thorough tests for time zone transitions#3295

Merged
ptomato merged 1 commit intomainfrom
exhaustive-time-zone-testing
Mar 17, 2026
Merged

Add thorough tests for time zone transitions#3295
ptomato merged 1 commit intomainfrom
exhaustive-time-zone-testing

Conversation

@ptomato
Copy link
Copy Markdown
Collaborator

@ptomato ptomato commented Mar 10, 2026

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

@ptomato ptomato requested review from Ms2ger and justingrant March 10, 2026 02:34
@ptomato ptomato added the run snapshot tests Add this label to a PR if you want the snapshot tests to run on it. label Mar 10, 2026
@ptomato
Copy link
Copy Markdown
Collaborator Author

ptomato commented Mar 10, 2026

@justingrant Can you think of any more time zone invariants that should be tested here?

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.83%. Comparing base (48bd5b2) to head (d66e781).
⚠️ Report is 1 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ptomato ptomato force-pushed the exhaustive-time-zone-testing branch from a9b6568 to 5e301d0 Compare March 10, 2026 02:52
Copy link
Copy Markdown
Collaborator

@Ms2ger Ms2ger left a comment

Choose a reason for hiding this comment

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

This seems reasonable; I'll leave it open in case Justin wants to comment but otherwise feel free to merge

Copy link
Copy Markdown
Collaborator

@justingrant justingrant left a comment

Choose a reason for hiding this comment

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

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
@ptomato ptomato force-pushed the exhaustive-time-zone-testing branch from 5e301d0 to d66e781 Compare March 17, 2026 21:02
@ptomato
Copy link
Copy Markdown
Collaborator Author

ptomato commented Mar 17, 2026

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.

@ptomato ptomato merged commit d27503d into main Mar 17, 2026
10 checks passed
@ptomato ptomato deleted the exhaustive-time-zone-testing branch March 17, 2026 21:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run snapshot tests Add this label to a PR if you want the snapshot tests to run on it.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants