Skip to content
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

Normative: Validation of NanosecondsToDays and getOffsetNanoseconds #2387

Merged
merged 3 commits into from
Oct 20, 2022

Conversation

ptomato
Copy link
Collaborator

@ptomato ptomato commented Aug 26, 2022

  • Stricter validation for values returned from NanosecondsToDays AO, to protect against custom time zones / calendars doing inconsistent things
  • Removal of 24-hour limit for getOffsetNanoseconds - this limit was leading to inconsistencies in custom time zones (see cookbook example)
  • Add some code to the NYSE custom time zone cookbook example that exercises these corners

Closes: #2357

@ptomato ptomato marked this pull request as draft August 26, 2022 17:28
@ptomato
Copy link
Collaborator Author

ptomato commented Aug 26, 2022

I'm not sure if we want all of these, especially the third commit.

cc @anba

@codecov
Copy link

codecov bot commented Aug 26, 2022

Codecov Report

Merging #2387 (1f500a5) into main (af8c764) will decrease coverage by 0.04%.
The diff coverage is 33.33%.

@@            Coverage Diff             @@
##             main    #2387      +/-   ##
==========================================
- Coverage   94.70%   94.65%   -0.05%     
==========================================
  Files          20       20              
  Lines       11053    11062       +9     
  Branches     1965     1969       +4     
==========================================
+ Hits        10468    10471       +3     
- Misses        540      544       +4     
- Partials       45       47       +2     
Impacted Files Coverage Δ
polyfill/lib/ecmascript.mjs 98.35% <33.33%> (-0.12%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@anba
Copy link
Contributor

anba commented Aug 26, 2022

I'm not sure if we want all of these, especially the third commit.

I don't think we should take the third commit. Are we sure that all callers of GetOffsetNanosecondsFor work correctly when the offset nanoseconds can be any value, including values like Number.MAX_VALUE?

@ptomato ptomato force-pushed the 2357-strict-nanosecondstodays branch from 922add3 to 37df41b Compare August 30, 2022 00:10
@ptomato
Copy link
Collaborator Author

ptomato commented Aug 30, 2022

I've removed the third commit for now, and plan to present this at the September TC39 plenary. We can decide later about the advantages and disadvantages of removing the limit on the return value of getOffsetNanosecondsFor.

@ptomato ptomato force-pushed the 2357-strict-nanosecondstodays branch from 37df41b to 8996c4d Compare September 20, 2022 23:47
@ptomato
Copy link
Collaborator Author

ptomato commented Sep 20, 2022

You're right, those were left over from a different way that I originally tried to do this.

@ptomato ptomato marked this pull request as ready for review October 19, 2022 21:20
When converting a number of nanoseconds to a number of days and a
nanoseconds remainder, neither the resulting number of days nor the
nanoseconds remainder should have the opposite sign as the original number
of nanoseconds.

This could happen due to shenanigans in a custom time zone's
getOffsetNanosecondsFor or getPossibleInstantsFor methods, or a custom
calendar's dateAdd method.

See: #2357
When converting a number of nanoseconds to a number of days and a
nanoseconds remainder, the remainder shouldn't be longer than the length
of the last day.

This could happen due to shenanigans in a custom time zone's
getOffsetNanosecondsFor or getPossibleInstantsFor methods, or a custom
calendar's dateAdd method.

See: #2357
Adds code to the NYSE time zone example in the cookbook which exercises
the interaction between ZonedDateTime arithmetic and time zone UTC offset
changes.
@ptomato ptomato force-pushed the 2357-strict-nanosecondstodays branch from 8996c4d to 1f500a5 Compare October 19, 2022 22:08
@ptomato ptomato mentioned this pull request Oct 19, 2022
44 tasks
@ptomato ptomato requested review from Ms2ger and Aditi-1400 October 19, 2022 22:16
@ptomato
Copy link
Collaborator Author

ptomato commented Oct 19, 2022

I'm probably not going to get a chance to write test262 tests for this for another couple of weeks, as I'll be occupied with other things. So I've added it to the general "test262 work items" list (#1398). I think we should go ahead and review and merge this now, as it's the last of the normative changes that were already approved in July and it's already been quite a while that it hasn't been reflected in the official proposal text.

Copy link
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.

Aaah, shenanigans

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.

Stricter requirements for NanosecondsToDays return values?
4 participants