Conversation
Codecov Report
@@ Coverage Diff @@
## main #811 +/- ##
==========================================
+ Coverage 92.74% 92.89% +0.15%
==========================================
Files 17 17
Lines 4881 5055 +174
Branches 754 773 +19
==========================================
+ Hits 4527 4696 +169
- Misses 347 352 +5
Partials 7 7
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
|
Nice! I left a few comments, mostly on the docs. Nothing major. I didn't dig deeply into the polyfill implementation or the specs. It's nice to see how much simpler a few of the cookbook samples got with negative durations. Thanks for doing this-- huge improvement! |
c7fd2d9 to
5df5d82
Compare
|
Thanks for the reviews! There were definitely some good catches in there. |
5df5d82 to
51a801c
Compare
51a801c to
05a2b14
Compare
|
This now requires #826. |
ryzokuken
left a comment
There was a problem hiding this comment.
Partially reviewed, and wow, it's huge.
84bed92 to
9d9326a
Compare
|
Thanks for the review, definitely caught some stuff I didn't see! I believe it's ready for review again. |
da69c47 to
cebc5f6
Compare
2944709 to
ebd4aa0
Compare
sffc
left a comment
There was a problem hiding this comment.
It looks good from spot-checking, but I didn't do a thorough review.
| <emu-clause id="sec-temporal-durationsign" aoid="DurationSign"> | ||
| <h1>DurationSign ( _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_ )</h1> | ||
| <emu-alg> | ||
| 1. For each value _v_ of _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_, do |
There was a problem hiding this comment.
| 1. For each value _v_ of _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_, do | |
| 1. For each value _v_ of « _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_ », do |
There was a problem hiding this comment.
I'm not sure what the correct spec language is, but there seems to be a precedent for not using the angle brackets: https://tc39.es/ecma402/#sec-todatetimeoptions
| <h1>RejectDurationSign ( _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_ )</h1> | ||
| <emu-alg> | ||
| 1. Let _sign_ be ! DurationSign(_years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_). | ||
| 1. For each value _v_ of _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_, do |
| <emu-alg> | ||
| 1. For each of _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_, if any of the values is negative or infinite, return *false*. | ||
| 1. Let _sign_ be ! DurationSign(_years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_). | ||
| 1. For each value _v_ of _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_, do |
| 1. Else if _disambiguation_ is *"constrain"*, then | ||
| 1. For each of _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_, if any of the values is negative, throw a *RangeError* exception. | ||
| 1. For each of _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_, if any of the values is infinite, let it be the largest possible finite value of the Number type. | ||
| 1. For each of _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_, if any of the values is infinite, let it be the sign of that value times the largest possible finite value of the Number type. |
There was a problem hiding this comment.
Does the last comment apply here too? Not sure, but maybe.
It's odd that we have AddTime but not SubtractTime. Regardless, we'll need to have it as a separate operation since it will be used from two places for negative duration support.
Changes Temporal.Duration to allow negative values in the fields, as long as all the fields have the same sign. Adds negated() and abs() methods to Temporal.Duration, and a sign property. On all types with arithmetic, subtracting a negative duration is equivalent to adding the absolute value of that duration, and adding a negative duration is equivalent to subtracting the absolute value of that duration. Closes: #782
This undoes the work in commit d84653e although it's not exactly a revert, because the situation before that was that durations were always positive. We also don't reinstate the behaviour of never returning a duration larger than 12 hours. Now, for all types, calling smaller.difference(larger) will result in a negative duration. See: #782
ebd4aa0 to
93c64e2
Compare
This is a huge pull request; I'd suggest reviewing it commit by commit.
The first two commits are small unrelated fixes. The third is a small rearrangement. The fourth actually allows negative durations, but the difference() methods still throw if called on two objects in the wrong order. The fifth commit fixes that and allows all the difference() methods to return negative durations.
Closes: #558
Closes: #782
Closes: #645