Skip to content

Fix TimeZone::get_possible_epoch_ns at date-time limits#580

Merged
nekevss merged 2 commits intoboa-dev:mainfrom
ptomato:fix-getpossibleepochns-at-limits
Sep 17, 2025
Merged

Fix TimeZone::get_possible_epoch_ns at date-time limits#580
nekevss merged 2 commits intoboa-dev:mainfrom
ptomato:fix-getpossibleepochns-at-limits

Conversation

@ptomato
Copy link
Copy Markdown
Contributor

@ptomato ptomato commented Sep 16, 2025

The is_valid_day_range() check was based on an erroneous line in the Temporal spec, see tc39/proposal-temporal#3151. This PR removes that check, and adds a get_possible_epoch_ns unit test for the affected cases.

For the unit test it was convenient to have CandidateEpochNanoseconds and EpochNanosecondsAndOffset implement PartialEq. Please let me know if that's not desired and I'll do it another way.

The second commit is a cleanup, not necessary for the bug fix. Feel free to drop it if you prefer not to have it. While I was fixing the above, I noticed that in most places the to_epoch_days value is cast to i32 and then immediately back to i64, so I changed the return type to i64 and instead moved the cast to the place where i32 is actually needed.

Copy link
Copy Markdown
Member

@nekevss nekevss left a comment

Choose a reason for hiding this comment

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

Thanks for working on this! I have a couple of nits. But then this should be good to go.

Comment thread src/iso.rs
Comment thread src/builtins/core/time_zone.rs Outdated
Comment thread src/builtins/core/time_zone.rs
@ptomato ptomato force-pushed the fix-getpossibleepochns-at-limits branch from 869dc22 to 25023bb Compare September 16, 2025 23:07
@ptomato ptomato requested a review from nekevss September 16, 2025 23:07
@ptomato
Copy link
Copy Markdown
Contributor Author

ptomato commented Sep 16, 2025

@nekevss Thanks for the review, done!

Copy link
Copy Markdown
Member

@nekevss nekevss 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! Thanks for working on this!

Just needs the cfg flag and cargo fmt --all, then this should be good to merge.

Comment thread src/builtins/core/time_zone.rs
There is no need to cast to i32 because in most of the places where it
is used, it is cast back to i64 anyway. In PlainDate::days_until, where
both IsoDate instances can be assumed to be within the valid range, we
can cast the difference to i32 instead, since it cannot be larger than
2e8 + 2.
@ptomato ptomato force-pushed the fix-getpossibleepochns-at-limits branch from 25023bb to 28719fa Compare September 17, 2025 17:01
@nekevss
Copy link
Copy Markdown
Member

nekevss commented Sep 17, 2025

Thanks for working on this!

@nekevss nekevss merged commit 58dacbe into boa-dev:main Sep 17, 2025
8 checks passed
@ptomato ptomato deleted the fix-getpossibleepochns-at-limits branch September 17, 2025 17:38
@Manishearth
Copy link
Copy Markdown
Contributor

Confirmed that this introduces no changes to V8's tests.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants