Skip to content

Comments

fix: use dynamic UTC expectations in date_proto_set_utc_hours test for timezone portability#4660

Open
Deepak-negi11 wants to merge 2 commits intoboa-dev:mainfrom
Deepak-negi11:fix/date-utc-hours-test-timezone
Open

fix: use dynamic UTC expectations in date_proto_set_utc_hours test for timezone portability#4660
Deepak-negi11 wants to merge 2 commits intoboa-dev:mainfrom
Deepak-negi11:fix/date-utc-hours-test-timezone

Conversation

@Deepak-negi11
Copy link
Contributor

@Deepak-negi11 Deepak-negi11 commented Feb 21, 2026

Fixes #4678

Problem

Some tests in builtins::date::tests were constructing dates using the
local-time Date constructor:

new Date(2020, 6, 8, 9, 16, 15, 779)

This interprets arguments as local time, so the resulting UTC components
vary depending on the timezone of the machine running the tests.

For example, in IST (UTC+5:30), local 9:16 becomes UTC 3:46 — the minutes
shift by 30. This caused date_proto_set_utc_hours to fail because the test
expected UTC minutes to be 16, but they were actually 46.

Fix

Replaced the local-time constructor with Date.UTC():

new Date(Date.UTC(2020, 6, 8, 9, 16, 15, 779))

Date.UTC() always interprets its arguments as UTC directly, so the UTC
components are consistent regardless of the machine's timezone.

Testing

  • date_proto_set_month
  • date_proto_set_utc_hours

Tested on IST (UTC+5:30) where the bug was originally discovered.

@github-actions
Copy link

github-actions bot commented Feb 21, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,862 52,862 0
Passed 49,497 49,497 0
Ignored 2,261 2,261 0
Failed 1,104 1,104 0
Panics 0 0 0
Conformance 93.63% 93.63% 0.00%

@jedel1043
Copy link
Member

I don't think this is the correct fix; we cannot just leave local time resolution untested. A correct fix would fetch the current datetime externally (maybe with the time crate?), then check equality with the date returned by Date.

You pushed an unrelated commit btw 😅

@jedel1043
Copy link
Member

But I guess we could also apply this and have a separate set of tests for local date + setUTC.

@jedel1043 jedel1043 added the waiting-on-author Waiting on PR changes from the author label Feb 22, 2026
@Deepak-negi11 Deepak-negi11 force-pushed the fix/date-utc-hours-test-timezone branch from abd803f to a5cad20 Compare February 22, 2026 22:25
@Deepak-negi11 Deepak-negi11 changed the title fix: use Date.UTC() in UTC date tests to avoid timezone sensitivity fix: use dynamic UTC expectations in date_proto_set_utc_hours test for timezone portability Feb 24, 2026
@Deepak-negi11 Deepak-negi11 force-pushed the fix/date-utc-hours-test-timezone branch from a5cad20 to 24ec184 Compare February 24, 2026 13:33
@Deepak-negi11
Copy link
Contributor Author

@jedel1043 can you please review it again

@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 56.94%. Comparing base (6ddc2b4) to head (c62bcbe).
⚠️ Report is 673 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4660      +/-   ##
==========================================
+ Coverage   47.24%   56.94%   +9.69%     
==========================================
  Files         476      549      +73     
  Lines       46892    60129   +13237     
==========================================
+ Hits        22154    34238   +12084     
- Misses      24738    25891    +1153     

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-on-author Waiting on PR changes from the author

Projects

None yet

Development

Successfully merging this pull request may close these issues.

date_proto_set_utc_hours test fails on non-UTC timezones

2 participants