-
Notifications
You must be signed in to change notification settings - Fork 153
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: Disallow negative day lengths #2261
Conversation
User-defined time zones can produce negative day lengths. ```js class TimeZone extends Temporal.TimeZone { #count = 0; #nanoseconds; constructor(nanoseconds) { super("UTC"); this.#nanoseconds = nanoseconds; } getPossibleInstantsFor(dateTime) { if (++this.#count === 2) { return [new Temporal.Instant(this.#nanoseconds)]; } return super.getPossibleInstantsFor(dateTime); } } function test(epochNanoseconds, tomorrowEpochNanoseconds, testCases) { for (let [roundingMode, expected] of Object.entries(testCases)) { let timeZone = new TimeZone(tomorrowEpochNanoseconds); let zoned = new Temporal.ZonedDateTime(epochNanoseconds, timeZone); let result = zoned.round({ smallestUnit: "days", roundingMode }); console.log(result.epochNanoseconds, expected); } } const oneDay = 24n * 60n * 60n * 1000n * 1000n * 1000n; test(3n, -10n, { ceil: 0n, floor: -oneDay, trunc: 0n, halfExpand: 0n, }); test(-3n, -10n, { ceil: oneDay, floor: 0n, trunc: 0n, halfExpand: 0n, }); ```
Codecov Report
@@ Coverage Diff @@
## main #2261 +/- ##
=======================================
Coverage 91.16% 91.16%
=======================================
Files 19 19
Lines 10524 10524
Branches 1688 1688
=======================================
Hits 9594 9594
Misses 918 918
Partials 12 12
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, good catch. I'll convert this to draft in advance of presenting it to TC39.
This change reached consensus in the July 2022 TC39 plenary meeting. Tests are in tc39/test262#3610. |
Whoops, I merged the wrong PR in reference to the above test262 pull request. This change does not yet have tests. |
Negative day lengths are no longer valid after <tc39/proposal-temporal#2261>.
Negative day lengths are no longer valid after <tc39/proposal-temporal#2261>.
(To close the loop, now it has tests.) |
This is the corresponding polyfill change to the spec change made in #2261
This is the corresponding polyfill change to the spec change made in #2261
Disallow negative day lengths as round result PR tc39/proposal-temporal#2261 Also fix the missing extraValues=<"day"> to GetTemporalUnit Spec Text: https://tc39.es/proposal-temporal/#sec-temporal.zoneddatetime.prototype.round Bug: v8:11544 Change-Id: Ibc963d5d93dde30f29df707ef3b3ecea99cd4a60 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3855704 Reviewed-by: Shu-yu Guo <syg@chromium.org> Commit-Queue: Frank Tang <ftang@chromium.org> Cr-Commit-Position: refs/heads/main@{#82798}
This is the corresponding polyfill change to the spec change made in tc39/proposal-temporal#2261 UPSTREAM_COMMIT=a1314bd0a47ecf2f41b85d5888a233d15e8a62a8
This is the corresponding polyfill change to the spec change made in tc39/proposal-temporal#2261 UPSTREAM_COMMIT=a1314bd0a47ecf2f41b85d5888a233d15e8a62a8
This is the corresponding polyfill change to the spec change made in tc39/proposal-temporal#2261 UPSTREAM_COMMIT=a1314bd0a47ecf2f41b85d5888a233d15e8a62a8
This is the corresponding polyfill change to the spec change made in tc39/proposal-temporal#2261 UPSTREAM_COMMIT=a1314bd0a47ecf2f41b85d5888a233d15e8a62a8
This is the corresponding polyfill change to the spec change made in tc39/proposal-temporal#2261 UPSTREAM_COMMIT=a1314bd0a47ecf2f41b85d5888a233d15e8a62a8
User-defined time zones can produce negative day lengths.