mirror of
https://github.com/tc39/test262.git
synced 2025-07-26 07:25:15 +02:00
Temporal: updates tests for balancing ordering change in Temporal.Duration.prototype.round
Fixes some tests which are observing side effects of round().
This commit is contained in:
parent
13778441ad
commit
da56f5e2b2
@ -20,17 +20,16 @@ const relativeTo = new Temporal.ZonedDateTime(0n, timeZone, calendar);
|
|||||||
// RoundDuration ->
|
// RoundDuration ->
|
||||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
||||||
// NanosecondsToDays -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
// NanosecondsToDays -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
||||||
// BalanceDurationRelative ->
|
|
||||||
// MoveRelativeDate -> calendar.dateAdd() (2x)
|
|
||||||
// calendar.dateAdd()
|
|
||||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
|
||||||
// BalanceDuration ->
|
// BalanceDuration ->
|
||||||
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
// AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
||||||
// NanosecondsToDays -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() (2x)
|
// NanosecondsToDays -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd() (2x)
|
||||||
|
// BalanceDurationRelative ->
|
||||||
|
// MoveRelativeDate -> calendar.dateAdd() (2x)
|
||||||
|
// calendar.dateAdd()
|
||||||
|
|
||||||
const instance1 = new Temporal.Duration(1, 1, 1, 1, 1);
|
const instance1 = new Temporal.Duration(1, 1, 1, 1, 1);
|
||||||
instance1.round({ smallestUnit: "days", relativeTo });
|
instance1.round({ smallestUnit: "days", relativeTo });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 9, "rounding with calendar smallestUnit");
|
assert.sameValue(calendar.dateAddCallCount, 8, "rounding with calendar smallestUnit");
|
||||||
|
|
||||||
// Rounding with a non-default largestUnit to cover the path in
|
// Rounding with a non-default largestUnit to cover the path in
|
||||||
// UnbalanceDurationRelative where larger units are converted into smaller
|
// UnbalanceDurationRelative where larger units are converted into smaller
|
||||||
@ -40,7 +39,6 @@ assert.sameValue(calendar.dateAddCallCount, 9, "rounding with calendar smallestU
|
|||||||
// Duration.round() ->
|
// Duration.round() ->
|
||||||
// UnbalanceDurationRelative -> MoveRelativeDate -> calendar.dateAdd()
|
// UnbalanceDurationRelative -> MoveRelativeDate -> calendar.dateAdd()
|
||||||
// RoundDuration ->
|
// RoundDuration ->
|
||||||
// MoveRelativeZonedDateTime -> AddZonedDateTime -> BuiltinTimeZoneGetInstantFor -> calendar.dateAdd()
|
|
||||||
// MoveRelativeDate -> calendar.dateAdd() (5x)
|
// MoveRelativeDate -> calendar.dateAdd() (5x)
|
||||||
// BalanceDurationRelative
|
// BalanceDurationRelative
|
||||||
// MoveRelativeDate -> calendar.dateAdd()
|
// MoveRelativeDate -> calendar.dateAdd()
|
||||||
@ -50,7 +48,7 @@ calendar.dateAddCallCount = 0;
|
|||||||
|
|
||||||
const instance2 = new Temporal.Duration(0, 1, 1, 1);
|
const instance2 = new Temporal.Duration(0, 1, 1, 1);
|
||||||
instance2.round({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo });
|
instance2.round({ largestUnit: "weeks", smallestUnit: "weeks", relativeTo });
|
||||||
assert.sameValue(calendar.dateAddCallCount, 9, "rounding with non-default largestUnit and calendar smallestUnit");
|
assert.sameValue(calendar.dateAddCallCount, 8, "rounding with non-default largestUnit and calendar smallestUnit");
|
||||||
|
|
||||||
// Rounding with smallestUnit a non-calendar unit, and having the resulting time
|
// Rounding with smallestUnit a non-calendar unit, and having the resulting time
|
||||||
// difference be longer than a calendar day, covering the paths that go through
|
// difference be longer than a calendar day, covering the paths that go through
|
||||||
|
@ -5,13 +5,12 @@
|
|||||||
esid: sec-temporal.duration.prototype.round
|
esid: sec-temporal.duration.prototype.round
|
||||||
description: The options object passed to calendar.dateUntil has a largestUnit property with its value in the singular form
|
description: The options object passed to calendar.dateUntil has a largestUnit property with its value in the singular form
|
||||||
info: |
|
info: |
|
||||||
sec-temporal.duration.prototype.round steps 20–25:
|
sec-temporal.duration.prototype.round steps 23–27:
|
||||||
20. Let _unbalanceResult_ be ? UnbalanceDurationRelative(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _largestUnit_, _relativeTo_).
|
23. Let _unbalanceResult_ be ? UnbalanceDurationRelative(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _largestUnit_, _relativeTo_).
|
||||||
21. Let _roundResult_ be ? RoundDuration(_unbalanceResult_.[[Years]], _unbalanceResult_.[[Months]], _unbalanceResult_.[[Weeks]], _unbalanceResult_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_[[Seconds]], _duration_[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], _roundingIncrement_, _smallestUnit_, _roundingMode_, _relativeTo_).
|
24. Let _roundResult_ be (? RoundDuration(_unbalanceResult_.[[Years]], _unbalanceResult_.[[Months]], _unbalanceResult_.[[Weeks]], _unbalanceResult_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], _roundingIncrement_, _smallestUnit_, _roundingMode_, _relativeTo_)).[[DurationRecord]].
|
||||||
22. Let _adjustResult_ be ? AdjustRoundedDurationDays(_roundResult_.[[Years]], _roundResult_.[[Months]], _roundResult_.[[Weeks]], _roundResult_.[[Days]], _roundResult_.[[Hours]], _roundResult_.[[Minutes]], _roundResult_.[[Seconds]], _roundResult_.[[Milliseconds]], _roundResult_.[[Microseconds]], _roundResult_.[[Nanoseconds]], _roundingIncrement_, _smallestUnit_, _roundingMode_, _relativeTo_).
|
25. Let _adjustResult_ be ? AdjustRoundedDurationDays(_roundResult_.[[Years]], _roundResult_.[[Months]], _roundResult_.[[Weeks]], _roundResult_.[[Days]], _roundResult_.[[Hours]], _roundResult_.[[Minutes]], _roundResult_.[[Seconds]], _roundResult_.[[Milliseconds]], _roundResult_.[[Microseconds]], _roundResult_.[[Nanoseconds]], _roundingIncrement_, _smallestUnit_, _roundingMode_, _relativeTo_).
|
||||||
23. Let _balanceResult_ be ? BalanceDurationRelative(_adjustResult_.[[Years]], _adjustResult_.[[Months]], _adjustResult_.[[Weeks]], _adjustResult_.[[Days]], _largestUnit_, _relativeTo_).
|
26. Let _balanceResult_ be ? BalanceDuration(_adjustResult_.[[Days]], _adjustResult_.[[Hours]], _adjustResult_.[[Minutes]], _adjustResult_.[[Seconds]], _adjustResult_.[[Milliseconds]], _adjustResult_.[[Microseconds]], _adjustResult_.[[Nanoseconds]], _largestUnit_, _relativeTo_).
|
||||||
24. ...
|
27. Let _result_ be ? BalanceDurationRelative(_adjustResult_.[[Years]], _adjustResult_.[[Months]], _adjustResult_.[[Weeks]], _balanceResult_.[[Days]], _largestUnit_, _relativeTo_).
|
||||||
25. Let _result_ be ? BalanceDuration(_balanceResult_.[[Days]], _adjustResult_.[[Hours]], _adjustResult_.[[Minutes]], _adjustResult_.[[Seconds]], _adjustResult_.[[Milliseconds]], _adjustResult_.[[Microseconds]], _adjustResult.[[Nanoseconds]], _largestUnit_, _relativeTo_).
|
|
||||||
sec-temporal-unbalancedurationrelative steps 1 and 9.d.iii–v:
|
sec-temporal-unbalancedurationrelative steps 1 and 9.d.iii–v:
|
||||||
1. If _largestUnit_ is *"year"*, or _years_, _months_, _weeks_, and _days_ are all 0, then
|
1. If _largestUnit_ is *"year"*, or _years_, _months_, _weeks_, and _days_ are all 0, then
|
||||||
a. Return ...
|
a. Return ...
|
||||||
@ -105,7 +104,7 @@ TemporalHelpers.checkCalendarDateUntilLargestUnitSingular(
|
|||||||
duration.round({ largestUnit, roundingIncrement: 2, roundingMode: 'ceil', relativeTo });
|
duration.round({ largestUnit, roundingIncrement: 2, roundingMode: 'ceil', relativeTo });
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
years: ["year", "day", "month", "day"],
|
years: ["year", "day", "day", "month"],
|
||||||
months: ["month", "day", "day"],
|
months: ["month", "day", "day"],
|
||||||
weeks: ["week", "day", "day"],
|
weeks: ["week", "day", "day"],
|
||||||
days: ["day", "day", "day"],
|
days: ["day", "day", "day"],
|
||||||
|
@ -36,7 +36,6 @@ const expected = [
|
|||||||
"2000-01-01T00:00:00", // called once on the input relativeTo object
|
"2000-01-01T00:00:00", // called once on the input relativeTo object
|
||||||
"2001-02-09T00:00:00", // called once on relativeTo plus years, months, weeks, days from the receiver
|
"2001-02-09T00:00:00", // called once on relativeTo plus years, months, weeks, days from the receiver
|
||||||
"2001-02-10T00:00:00", // called once on the previous value plus the calendar days difference between that and the time part of the duration
|
"2001-02-10T00:00:00", // called once on the previous value plus the calendar days difference between that and the time part of the duration
|
||||||
"2001-02-01T00:00:00", // called once on relativeTo plus the years, months, and weeks part of the balance result
|
|
||||||
];
|
];
|
||||||
|
|
||||||
TemporalHelpers.checkTimeZonePossibleInstantsIterable((timeZone) => {
|
TemporalHelpers.checkTimeZonePossibleInstantsIterable((timeZone) => {
|
||||||
|
@ -14,15 +14,15 @@ const instance = new Temporal.Duration(1, 0, 0, 0, 24);
|
|||||||
|
|
||||||
let relativeTo = "2019-11-01T00:00[America/Vancouver]";
|
let relativeTo = "2019-11-01T00:00[America/Vancouver]";
|
||||||
const result4 = instance.round({ largestUnit: "years", relativeTo });
|
const result4 = instance.round({ largestUnit: "years", relativeTo });
|
||||||
TemporalHelpers.assertDuration(result4, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo");
|
TemporalHelpers.assertDuration(result4, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo");
|
||||||
|
|
||||||
relativeTo = "2019-11-01T00:00Z[America/Vancouver]";
|
relativeTo = "2019-11-01T00:00Z[America/Vancouver]";
|
||||||
const result5 = instance.round({ largestUnit: "years", relativeTo });
|
const result5 = instance.round({ largestUnit: "years", relativeTo });
|
||||||
TemporalHelpers.assertDuration(result5, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo");
|
TemporalHelpers.assertDuration(result5, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo");
|
||||||
|
|
||||||
relativeTo = "2019-11-01T00:00-07:00[America/Vancouver]";
|
relativeTo = "2019-11-01T00:00-07:00[America/Vancouver]";
|
||||||
const result6 = instance.round({ largestUnit: "years", relativeTo });
|
const result6 = instance.round({ largestUnit: "years", relativeTo });
|
||||||
TemporalHelpers.assertDuration(result6, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo");
|
TemporalHelpers.assertDuration(result6, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo");
|
||||||
|
|
||||||
relativeTo = "2019-11-01T00:00+04:15[America/Vancouver]";
|
relativeTo = "2019-11-01T00:00+04:15[America/Vancouver]";
|
||||||
assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch");
|
assert.throws(RangeError, () => instance.round({ largestUnit: "years", relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user