Skip to content

Commit

Permalink
Temporal: Remove tests using relativeTo in Duration.p.add/subtract
Browse files Browse the repository at this point in the history
See tc39/proposal-temporal#2825. This is a mass removal of tests that use
this functionality, in a separate commit for ease of review. Further
adjustments will be made in the following commit.
  • Loading branch information
ptomato committed Jun 13, 2024
1 parent ba9c397 commit ea4945c
Show file tree
Hide file tree
Showing 139 changed files with 25 additions and 4,736 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,6 @@ features: [Temporal]
const instance = new Temporal.Duration();

const cases = [
// 2^32 = 4294967296
["P4294967296Y", "string with years > max"],
[{ years: 4294967296 }, "property bag with years > max"],
["-P4294967296Y", "string with years < min"],
[{ years: -4294967296 }, "property bag with years < min"],
["P4294967296M", "string with months > max"],
[{ months: 4294967296 }, "property bag with months > max"],
["-P4294967296M", "string with months < min"],
[{ months: -4294967296 }, "property bag with months < min"],
["P4294967296W", "string with weeks > max"],
[{ weeks: 4294967296 }, "property bag with weeks > max"],
["-P4294967296W", "string with weeks < min"],
[{ weeks: -4294967296 }, "property bag with weeks < min"],

// ceil(max safe integer / 86400) = 104249991375
["P104249991375D", "string with days > max"],
[{ days: 104249991375 }, "property bag with days > max"],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,7 @@

/*---
esid: sec-temporal.duration.prototype.add
description: A negative duration result is balanced correctly by the modulo operation in NanosecondsToDays
info: |
sec-temporal-nanosecondstodays step 6:
6. If Type(_relativeTo_) is not Object or _relativeTo_ does not have an [[InitializedTemporalZonedDateTime]] internal slot, then
a. Return the new Record { ..., [[Nanoseconds]]: abs(_nanoseconds_) modulo _dayLengthNs_ × _sign_, ... }.
sec-temporal-balanceduration step 4:
4. If _largestUnit_ is one of *"year"*, *"month"*, *"week"*, or *"day"*, then
a. Let _result_ be ? NanosecondsToDays(_nanoseconds_, _relativeTo_).
sec-temporal-addduration steps 5–6:
5. If _relativeTo_ is *undefined*, then
...
b. Let _result_ be ! BalanceDuration(_d1_ + _d2_, _h1_ + _h2_, _min1_ + _min2_, _s1_ + _s2_, _ms1_ + _ms2_, _mus1_ + _mus2_, _ns1_ + _ns2_, _largestUnit_).
...
6. Else if _relativeTo_ has an [[InitializedTemporalPlainDateTime]] internal slot, then
...
n. Let _result_ be ! BalanceDuration(_dateDifference_.[[Days]], _h1_ + _h2_, _min1_ + _min2_, _s1_ + _s2_, _ms1_ + _ms2_, _mus1_ + _mus2_, _ns1_ + _ns2_, _largestUnit_).
sec-temporal.duration.prototype.add step 6:
6. Let _result_ be ? AddDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], _other_.[[Years]], _other_.[[Months]], _other_.[[Weeks]], _other_.[[Days]], _other_.[[Hours]], _other_.[[Minutes]], _other_.[[Seconds]], _other_.[[Milliseconds]], _other_.[[Microseconds]], _other_.[[Nanoseconds]], _relativeTo_).
description: A negative duration result is balanced only up to hours
includes: [temporalHelpers.js]
features: [Temporal]
---*/
Expand All @@ -30,7 +13,3 @@ const duration2 = new Temporal.Duration(0, 0, 0, -1);

const resultNotRelative = duration1.add(duration2);
TemporalHelpers.assertDuration(resultNotRelative, 0, 0, 0, -3, -12, 0, 0, 0, 0, 0);

const relativeTo = new Temporal.PlainDateTime(2000, 1, 1);
const resultRelative = duration1.add(duration2, { relativeTo });
TemporalHelpers.assertDuration(resultRelative, 0, 0, 0, -3, -12, 0, 0, 0, 0, 0);
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,27 @@

/*---
esid: sec-temporal.duration.prototype.add
description: Negative time fields in relativeTo are balanced upwards
info: |
sec-temporal-balancetime steps 3–14:
3. Set _microsecond_ to _microsecond_ + floor(_nanosecond_ / 1000).
4. Set _nanosecond_ to _nanosecond_ modulo 1000.
5. Set _millisecond_ to _millisecond_ + floor(_microsecond_ / 1000).
6. Set _microsecond_ to _microsecond_ modulo 1000.
7. Set _second_ to _second_ + floor(_millisecond_ / 1000).
8. Set _millisecond_ to _millisecond_ modulo 1000.
9. Set _minute_ to _minute_ + floor(_second_ / 60).
10. Set _second_ to _second_ modulo 60.
11. Set _hour_ to _hour_ + floor(_minute_ / 60).
12. Set _minute_ to _minute_ modulo 60.
13. Let _days_ be floor(_hour_ / 24).
14. Set _hour_ to _hour_ modulo 24.
sec-temporal-differencetime step 8:
8. Let _bt_ be ? BalanceTime(_hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_).
sec-temporal-differenceisodatetime step 2:
2. Let _timeDifference_ be ? DifferenceTime(_h1_, _min1_, _s1_, _ms1_, _mus1_, _ns1_, _h2_, _min2_, _s2_, _ms2_, _mus2_, _ns2_).
sec-temporal-differencezoneddatetime step 7:
7. Let _dateDifference_ be ? DifferenceISODateTime(_startDateTime_.[[ISOYear]], _startDateTime_.[[ISOMonth]], _startDateTime_.[[ISODay]], _startDateTime_.[[ISOHour]], _startDateTime_.[[ISOMinute]], _startDateTime_.[[ISOSecond]], _startDateTime_.[[ISOMillisecond]], _startDateTime_.[[ISOMicrosecond]], _startDateTime_.[[ISONanosecond]], _endDateTime_.[[ISOYear]], _endDateTime_.[[ISOMonth]], _endDateTime_.[[ISODay]], _endDateTime_.[[ISOHour]], _endDateTime_.[[ISOMinute]], _endDateTime_.[[ISOSecond]], _endDateTime_.[[ISOMillisecond]], _endDateTime_.[[ISOMicrosecond]], _endDateTime_.[[ISONanosecond]], _calendar_, _largestUnit_, _options_).
sec-temporal-addduration step 7.g.i:
i. Let _result_ be ? DifferenceZonedDateTime(_relativeTo_.[[Nanoseconds]], _endNs_, _timeZone_, _calendar_, _largestUnit_).
sec-temporal.duration.prototype.add step 6:
6. Let _result_ be ? AddDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], _other_.[[Years]], _other_.[[Months]], _other_.[[Weeks]], _other_.[[Days]], _other_.[[Hours]], _other_.[[Minutes]], _other_.[[Seconds]], _other_.[[Milliseconds]], _other_.[[Microseconds]], _other_.[[Nanoseconds]], _relativeTo_).
description: Negative time fields are balanced upwards
includes: [temporalHelpers.js]
features: [Temporal]
---*/

const duration = new Temporal.Duration(0, 0, 0, 0, 1, 1, 1, 1, 1, 1);

const timeZone = new Temporal.TimeZone("UTC");
const relativeTo = new Temporal.ZonedDateTime(830998861_000_000_000n, timeZone);
// This code path is encountered if largestUnit is years, months, weeks, or days
// and relativeTo is a ZonedDateTime
const options = { largestUnit: "days", relativeTo };

const result1 = duration.add(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -2), options);
const result1 = duration.add(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, -2));
TemporalHelpers.assertDuration(result1, 0, 0, 0, 0, 1, 1, 1, 1, 0, 999, "nanoseconds balance");

const result2 = duration.add(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -2), options);
const result2 = duration.add(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, -2));
TemporalHelpers.assertDuration(result2, 0, 0, 0, 0, 1, 1, 1, 0, 999, 1, "microseconds balance");

const result3 = duration.add(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, -2), options);
const result3 = duration.add(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, -2));
TemporalHelpers.assertDuration(result3, 0, 0, 0, 0, 1, 1, 0, 999, 1, 1, "milliseconds balance");

const result4 = duration.add(new Temporal.Duration(0, 0, 0, 0, 0, 0, -2), options);
const result4 = duration.add(new Temporal.Duration(0, 0, 0, 0, 0, 0, -2));
TemporalHelpers.assertDuration(result4, 0, 0, 0, 0, 1, 0, 59, 1, 1, 1, "seconds balance");

const result5 = duration.add(new Temporal.Duration(0, 0, 0, 0, 0, -2), options);
const result5 = duration.add(new Temporal.Duration(0, 0, 0, 0, 0, -2));
TemporalHelpers.assertDuration(result5, 0, 0, 0, 0, 0, 59, 1, 1, 1, 1, "minutes balance");

// This one is different because hours are later balanced again in BalanceDuration
const result6 = duration.add(new Temporal.Duration(0, 0, 0, 0, -2), options);
const result6 = duration.add(new Temporal.Duration(0, 0, 0, 0, -2));
TemporalHelpers.assertDuration(result6, 0, 0, 0, 0, 0, -58, -58, -998, -998, -999, "hours balance");

This file was deleted.

This file was deleted.

40 changes: 0 additions & 40 deletions test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd.js

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit ea4945c

Please sign in to comment.