mirror of https://github.com/tc39/test262.git
Temporal: Add test for last step of UnbalanceDateDurationRelative throwing
Based on a test case by Anba. See https://github.com/tc39/proposal-temporal/pull/2690#issuecomment-1938768702
This commit is contained in:
parent
f4f33d272c
commit
8b781361a9
|
@ -0,0 +1,27 @@
|
|||
// Copyright (C) 2024 Igalia, S.L. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-temporal.duration.compare
|
||||
description: RangeError thrown when calendar part of duration added to relativeTo is out of range
|
||||
features: [Temporal]
|
||||
info: |
|
||||
UnbalanceDateDurationRelative:
|
||||
11. Let _yearsMonthsWeeksDuration_ be ! CreateTemporalDuration(_years_, _months_, _weeks_, 0, 0, 0, 0, 0, 0, 0).
|
||||
12. Let _later_ be ? CalendarDateAdd(_calendaRec_, _plainRelativeTo_, _yearsMonthsWeeksDuration_).
|
||||
13. Let _yearsMonthsWeeksInDays_ be DaysUntil(_plainRelativeTo_, _later_).
|
||||
14. Return ? CreateDateDurationRecord(0, 0, 0, _days_ + _yearsMonthsWeeksInDays_).
|
||||
---*/
|
||||
|
||||
// Based on a test case by André Bargull <andre.bargull@gmail.com>
|
||||
|
||||
const relativeTo = new Temporal.PlainDate(2000, 1, 1);
|
||||
const zero = new Temporal.Duration();
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, /* weeks = */ 1, /* days = */ Math.trunc((2 ** 53) / 86_400));
|
||||
assert.throws(RangeError, () => Temporal.Duration.compare(instance, zero, {relativeTo}), "weeks + days out of range, positive, first argument");
|
||||
assert.throws(RangeError, () => Temporal.Duration.compare(zero, instance, {relativeTo}), "weeks + days out of range, positive, second argument");
|
||||
|
||||
const negInstance = new Temporal.Duration(0, 0, /* weeks = */ -1, /* days = */ -Math.trunc((2 ** 53) / 86_400));
|
||||
assert.throws(RangeError, () => Temporal.Duration.compare(negInstance, zero, {relativeTo}), "weeks + days out of range, negative, first argument");
|
||||
assert.throws(RangeError, () => Temporal.Duration.compare(zero, negInstance, {relativeTo}), "weeks + days out of range, negative, second argument");
|
|
@ -7,19 +7,42 @@ description: RangeError thrown when calendar part of duration added to relativeT
|
|||
features: [Temporal]
|
||||
info: |
|
||||
RoundDuration:
|
||||
8.k. Let _isoResult_ be ! AddISODate(_plainRelativeTo_.[[ISOYear]]. _plainRelativeTo_.[[ISOMonth]], _plainRelativeTo_.[[ISODay]], 0, 0, 0, truncate(_fractionalDays_), *"constrain"*).
|
||||
l. Let _wholeDaysLater_ be ? CreateTemporalDate(_isoResult_.[[Year]], _isoResult_.[[Month]], _isoResult_.[[Day]], _calendar_).
|
||||
10.h. Let _isoResult_ be ! AddISODate(_plainRelativeTo_.[[ISOYear]]. _plainRelativeTo_.[[ISOMonth]], _plainRelativeTo_.[[ISODay]], 0, 0, 0, truncate(_fractionalDays_), *"constrain"*).
|
||||
i. Let _wholeDaysLater_ be ? CreateTemporalDate(_isoResult_.[[Year]], _isoResult_.[[Month]], _isoResult_.[[Day]], _calendar_).
|
||||
...
|
||||
11.h. Let _isoResult_ be ! AddISODate(_plainRelativeTo_.[[ISOYear]]. _plainRelativeTo_.[[ISOMonth]], _plainRelativeTo_.[[ISODay]], 0, 0, 0, truncate(_fractionalDays_), *"constrain"*).
|
||||
i. Let _wholeDaysLater_ be ? CreateTemporalDate(_isoResult_.[[Year]], _isoResult_.[[Month]], _isoResult_.[[Day]], _calendar_).
|
||||
...
|
||||
12.a. Let _isoResult_ be ! AddISODate(_plainRelativeTo_.[[ISOYear]]. _plainRelativeTo_.[[ISOMonth]], _plainRelativeTo_.[[ISODay]], 0, 0, 0, truncate(_fractionalDays_), *"constrain"*).
|
||||
b. Let _wholeDaysLater_ be ? CreateTemporalDate(_isoResult_.[[Year]], _isoResult_.[[Month]], _isoResult_.[[Day]], _calendar_).
|
||||
|
||||
UnbalanceDateDurationRelative:
|
||||
11. Let _yearsMonthsWeeksDuration_ be ! CreateTemporalDuration(_years_, _months_, _weeks_, 0, 0, 0, 0, 0, 0, 0).
|
||||
12. Let _later_ be ? CalendarDateAdd(_calendaRec_, _plainRelativeTo_, _yearsMonthsWeeksDuration_).
|
||||
13. Let _yearsMonthsWeeksInDays_ be DaysUntil(_plainRelativeTo_, _later_).
|
||||
14. Return ? CreateDateDurationRecord(0, 0, 0, _days_ + _yearsMonthsWeeksInDays_).
|
||||
---*/
|
||||
|
||||
// Based on a test case by André Bargull <andre.bargull@gmail.com>
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, /* days = */ 500_000_000);
|
||||
const relativeTo = new Temporal.PlainDate(2000, 1, 1);
|
||||
assert.throws(RangeError, () => instance.round({relativeTo, smallestUnit: "years"}));
|
||||
assert.throws(RangeError, () => instance.round({relativeTo, smallestUnit: "months"}));
|
||||
assert.throws(RangeError, () => instance.round({relativeTo, smallestUnit: "weeks"}));
|
||||
|
||||
const negInstance = new Temporal.Duration(0, 0, 0, /* days = */ -500_000_000);
|
||||
assert.throws(RangeError, () => negInstance.round({relativeTo, smallestUnit: "years"}));
|
||||
assert.throws(RangeError, () => negInstance.round({relativeTo, smallestUnit: "months"}));
|
||||
assert.throws(RangeError, () => negInstance.round({relativeTo, smallestUnit: "weeks"}));
|
||||
{
|
||||
const instance = new Temporal.Duration(0, 0, 0, /* days = */ 500_000_000);
|
||||
assert.throws(RangeError, () => instance.round({relativeTo, smallestUnit: "years"}), "days out of range, positive, smallestUnit years");
|
||||
assert.throws(RangeError, () => instance.round({relativeTo, smallestUnit: "months"}), "days out of range, positive, smallestUnit months");
|
||||
assert.throws(RangeError, () => instance.round({relativeTo, smallestUnit: "weeks"}), "days out of range, positive, smallestUnit weeks");
|
||||
|
||||
const negInstance = new Temporal.Duration(0, 0, 0, /* days = */ -500_000_000);
|
||||
assert.throws(RangeError, () => negInstance.round({relativeTo, smallestUnit: "years"}), "days out of range, negative, smallestUnit years");
|
||||
assert.throws(RangeError, () => negInstance.round({relativeTo, smallestUnit: "months"}), "days out of range, negative, smallestUnit months");
|
||||
assert.throws(RangeError, () => negInstance.round({relativeTo, smallestUnit: "weeks"}), "days out of range, negative, smallestUnit weeks");
|
||||
}
|
||||
|
||||
{
|
||||
const instance = new Temporal.Duration(0, 0, /* weeks = */ 1, /* days = */ Math.trunc((2 ** 53) / 86_400));
|
||||
assert.throws(RangeError, () => instance.round({relativeTo, largestUnit: "days"}), "weeks + days out of range, positive");
|
||||
|
||||
const negInstance = new Temporal.Duration(0, 0, /* weeks = */ -1, /* days = */ -Math.trunc((2 ** 53) / 86_400));
|
||||
assert.throws(RangeError, () => instance.round({relativeTo, largestUnit: "days"}), "weeks + days out of range, negative");
|
||||
}
|
||||
|
|
|
@ -7,19 +7,42 @@ description: RangeError thrown when calendar part of duration added to relativeT
|
|||
features: [Temporal]
|
||||
info: |
|
||||
RoundDuration:
|
||||
8.k. Let _isoResult_ be ! AddISODate(_plainRelativeTo_.[[ISOYear]]. _plainRelativeTo_.[[ISOMonth]], _plainRelativeTo_.[[ISODay]], 0, 0, 0, truncate(_fractionalDays_), *"constrain"*).
|
||||
l. Let _wholeDaysLater_ be ? CreateTemporalDate(_isoResult_.[[Year]], _isoResult_.[[Month]], _isoResult_.[[Day]], _calendar_).
|
||||
10.h. Let _isoResult_ be ! AddISODate(_plainRelativeTo_.[[ISOYear]]. _plainRelativeTo_.[[ISOMonth]], _plainRelativeTo_.[[ISODay]], 0, 0, 0, truncate(_fractionalDays_), *"constrain"*).
|
||||
i. Let _wholeDaysLater_ be ? CreateTemporalDate(_isoResult_.[[Year]], _isoResult_.[[Month]], _isoResult_.[[Day]], _calendar_).
|
||||
...
|
||||
11.h. Let _isoResult_ be ! AddISODate(_plainRelativeTo_.[[ISOYear]]. _plainRelativeTo_.[[ISOMonth]], _plainRelativeTo_.[[ISODay]], 0, 0, 0, truncate(_fractionalDays_), *"constrain"*).
|
||||
i. Let _wholeDaysLater_ be ? CreateTemporalDate(_isoResult_.[[Year]], _isoResult_.[[Month]], _isoResult_.[[Day]], _calendar_).
|
||||
...
|
||||
12.a. Let _isoResult_ be ! AddISODate(_plainRelativeTo_.[[ISOYear]]. _plainRelativeTo_.[[ISOMonth]], _plainRelativeTo_.[[ISODay]], 0, 0, 0, truncate(_fractionalDays_), *"constrain"*).
|
||||
b. Let _wholeDaysLater_ be ? CreateTemporalDate(_isoResult_.[[Year]], _isoResult_.[[Month]], _isoResult_.[[Day]], _calendar_).
|
||||
|
||||
UnbalanceDateDurationRelative:
|
||||
11. Let _yearsMonthsWeeksDuration_ be ! CreateTemporalDuration(_years_, _months_, _weeks_, 0, 0, 0, 0, 0, 0, 0).
|
||||
12. Let _later_ be ? CalendarDateAdd(_calendaRec_, _plainRelativeTo_, _yearsMonthsWeeksDuration_).
|
||||
13. Let _yearsMonthsWeeksInDays_ be DaysUntil(_plainRelativeTo_, _later_).
|
||||
14. Return ? CreateDateDurationRecord(0, 0, 0, _days_ + _yearsMonthsWeeksInDays_).
|
||||
---*/
|
||||
|
||||
// Based on a test case by André Bargull <andre.bargull@gmail.com>
|
||||
|
||||
const instance = new Temporal.Duration(0, 0, 0, /* days = */ 500_000_000);
|
||||
const relativeTo = new Temporal.PlainDate(2000, 1, 1);
|
||||
assert.throws(RangeError, () => instance.total({relativeTo, unit: "years"}));
|
||||
assert.throws(RangeError, () => instance.total({relativeTo, unit: "months"}));
|
||||
assert.throws(RangeError, () => instance.total({relativeTo, unit: "weeks"}));
|
||||
|
||||
const negInstance = new Temporal.Duration(0, 0, 0, /* days = */ -500_000_000);
|
||||
assert.throws(RangeError, () => negInstance.total({relativeTo, unit: "years"}));
|
||||
assert.throws(RangeError, () => negInstance.total({relativeTo, unit: "months"}));
|
||||
assert.throws(RangeError, () => negInstance.total({relativeTo, unit: "weeks"}));
|
||||
{
|
||||
const instance = new Temporal.Duration(0, 0, 0, /* days = */ 500_000_000);
|
||||
assert.throws(RangeError, () => instance.total({relativeTo, unit: "years"}), "days out of range, positive, unit years");
|
||||
assert.throws(RangeError, () => instance.total({relativeTo, unit: "months"}), "days out of range, positive, unit months");
|
||||
assert.throws(RangeError, () => instance.total({relativeTo, unit: "weeks"}), "days out of range, positive, unit weeks");
|
||||
|
||||
const negInstance = new Temporal.Duration(0, 0, 0, /* days = */ -500_000_000);
|
||||
assert.throws(RangeError, () => negInstance.total({relativeTo, unit: "years"}), "days out of range, negative, unit years");
|
||||
assert.throws(RangeError, () => negInstance.total({relativeTo, unit: "months"}), "days out of range, negative, unit months");
|
||||
assert.throws(RangeError, () => negInstance.total({relativeTo, unit: "weeks"}), "days out of range, negative, unit weeks");
|
||||
}
|
||||
|
||||
{
|
||||
const instance = new Temporal.Duration(0, 0, /* weeks = */ 1, /* days = */ Math.trunc((2 ** 53) / 86_400));
|
||||
assert.throws(RangeError, () => instance.total({relativeTo, unit: "days"}), "weeks + days out of range, positive");
|
||||
|
||||
const negInstance = new Temporal.Duration(0, 0, /* weeks = */ -1, /* days = */ -Math.trunc((2 ** 53) / 86_400));
|
||||
assert.throws(RangeError, () => instance.total({relativeTo, unit: "days"}), "weeks + days out of range, negative");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue