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

Editorial: Simplify date/time range validation #2658

Merged
merged 2 commits into from
Aug 23, 2023

Conversation

justingrant
Copy link
Collaborator

@justingrant justingrant commented Aug 19, 2023

This PR refactors several operations related to range validation of Temporal.PlainDateTime and Temporal.Instant.

commit 1: remove the ! from existing calls to IsValidEpochNanoseconds which is infallible.

commit 2:

  • Makes polyfill GetUTCEpochNanoseconds infallible, like in the spec, using @ptomato's year % 400 trick to avoid overflows.
  • Simplifies the polyfill's GetNamedTimeZoneOffsetNanoseconds by using the now-infallible GetUTCEpochNanoseconds.
  • Adds optional _offsetNanoseconds_ parameter to GetUTCEpochNanoseconds, and uses it in call sites of GetUTCEpochNanoseconds where an offset was previously applied to its result.
  • Simplifies the polyfill's GetNamedTimeZoneOffsetNanoseconds by using the now-infallible GetUTCEpochNanoseconds.
  • Simplifies the polyfill's PlainDateTime range validation in RejectDateTimeRange.
  • Clarifies the PlainDateTime docs about that type's valid range.
  • Removes non-parsing logic from ParseTemporalInstantString, aligning Instant parsing with the parsing pattern used in other Temporal types where parsing AOs contain only parsing without interpretation.
  • Inlines the single-caller ParseTemporalInstant into ToTemporalInstant, matching the pattern used by ToTemporalYearMonth, ToTemporalTime, etc.
  • Marks ParseDateTimeUTCOffset as infallible after parsing instant strings, because ParseTemporalInstantString guarantees that the offset is valid. Fixes ParseTemporalInstant: ParseDateTimeUTCOffset is infallible #2637.
  • Aligns polyfill more closely to spec for Instant parsing.

@justingrant justingrant added non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE! editorial labels Aug 19, 2023
@justingrant justingrant force-pushed the range-validation-refactor branch from ac60dfc to f6efff3 Compare August 19, 2023 06:42
@codecov
Copy link

codecov bot commented Aug 19, 2023

Codecov Report

Merging #2658 (a1f2a9f) into main (3ca02f1) will increase coverage by 0.02%.
Report is 2 commits behind head on main.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##             main    #2658      +/-   ##
==========================================
+ Coverage   96.07%   96.10%   +0.02%     
==========================================
  Files          20       20              
  Lines       11676    11697      +21     
  Branches     2203     2186      -17     
==========================================
+ Hits        11218    11241      +23     
+ Misses        394      392       -2     
  Partials       64       64              
Files Changed Coverage Δ
polyfill/lib/ecmascript.mjs 98.45% <100.00%> (+0.04%) ⬆️
polyfill/lib/timezone.mjs 100.00% <100.00%> (ø)

Copy link
Collaborator

@gibson042 gibson042 left a comment

Choose a reason for hiding this comment

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

I like inlining the offset arithmetic!

spec/instant.html Outdated Show resolved Hide resolved
polyfill/lib/ecmascript.mjs Outdated Show resolved Hide resolved
polyfill/lib/ecmascript.mjs Outdated Show resolved Hide resolved
spec/instant.html Outdated Show resolved Hide resolved
polyfill/lib/ecmascript.mjs Show resolved Hide resolved
@justingrant justingrant force-pushed the range-validation-refactor branch 4 times, most recently from 8caefac to f541879 Compare August 19, 2023 21:54
@justingrant
Copy link
Collaborator Author

@gibson042 - I think all your review comments are addressed, want to take another look? Thanks!

spec/timezone.html Outdated Show resolved Hide resolved
spec/mainadditions.html Outdated Show resolved Hide resolved
spec/instant.html Outdated Show resolved Hide resolved
@justingrant justingrant force-pushed the range-validation-refactor branch 5 times, most recently from 146f909 to 4f79012 Compare August 20, 2023 02:08
Copy link
Collaborator

@ptomato ptomato 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, I just had a few stylistic nits to pick. Thanks!

spec/abstractops.html Outdated Show resolved Hide resolved
spec/abstractops.html Outdated Show resolved Hide resolved
spec/mainadditions.html Outdated Show resolved Hide resolved
spec/mainadditions.html Show resolved Hide resolved
spec/instant.html Outdated Show resolved Hide resolved
Removes `!` from calls of IsValidEpochNanoseconds, because that AO is
infallible.
@justingrant justingrant force-pushed the range-validation-refactor branch from 4f79012 to 911cf9f Compare August 23, 2023 03:40
This commit refactors several operations related to range validation of
Temporal.PlainDateTime and Temporal.Instant.

* Adds optional _offsetNanoseconds_ parameter to GetUTCEpochNanoseconds,
  and uses it in call sites of GetUTCEpochNanoseconds where an offset
  was previously applied to its result.
* Makes polyfill GetUTCEpochNanoseconds infallible, like in the spec.
* Simplifies the polyfill's GetNamedTimeZoneOffsetNanoseconds by using
  the now-infallible GetUTCEpochNanoseconds.
* Simplifies the polyfill's PlainDateTime range validation in
  RejectDateTimeRange.
* Clarifies the PlainDateTime docs about that type's valid range.
* Removes non-parsing logic from ParseTemporalInstantString, aligning
  Instant parsing with the parsing pattern used in other Temporal
  types where parsing AOs contain only parsing without interpretation.
* Inlines the single-caller ParseTemporalInstant into ToTemporalInstant,
  matching the pattern used by ToTemporalYearMonth, ToTemporalTime, etc.
* Marks ParseDateTimeUTCOffset as infallible after parsing instant
  strings, because ParseTemporalInstantString guarantees that the
  offset is valid. Fixes tc39#2637.
* Aligns polyfill more closely to spec for Instant parsing.
@justingrant justingrant force-pushed the range-validation-refactor branch from 911cf9f to a1f2a9f Compare August 23, 2023 03:45
@justingrant justingrant merged commit 0dfd93a into tc39:main Aug 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
editorial non-prod-polyfill THIS POLYFILL IS NOT FOR PRODUCTION USE!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ParseTemporalInstant: ParseDateTimeUTCOffset is infallible
3 participants