From 8dd16259287f58f9273002717ec4d27e97127719 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 12 Jun 2024 07:43:14 +0200 Subject: Merging upstream version 127.0. Signed-off-by: Daniel Baumann --- ...cezoneddatetime-inconsistent-custom-calendar.js | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 js/src/tests/test262/built-ins/Temporal/Duration/prototype/subtract/differencezoneddatetime-inconsistent-custom-calendar.js (limited to 'js/src/tests/test262/built-ins/Temporal/Duration/prototype/subtract/differencezoneddatetime-inconsistent-custom-calendar.js') diff --git a/js/src/tests/test262/built-ins/Temporal/Duration/prototype/subtract/differencezoneddatetime-inconsistent-custom-calendar.js b/js/src/tests/test262/built-ins/Temporal/Duration/prototype/subtract/differencezoneddatetime-inconsistent-custom-calendar.js new file mode 100644 index 0000000000..e2c543c7d2 --- /dev/null +++ b/js/src/tests/test262/built-ins/Temporal/Duration/prototype/subtract/differencezoneddatetime-inconsistent-custom-calendar.js @@ -0,0 +1,55 @@ +// |reftest| skip-if(!this.hasOwnProperty('Temporal')) -- Temporal is not enabled unconditionally +// 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.prototype.subtract +description: > + Throws a RangeError when custom calendar method returns inconsistent result +info: | + DifferenceZonedDateTime ( ... ) + 8. Repeat 3 times: + ... + g. If _sign_ = 0, or _timeSign_ = 0, or _sign_ = _timeSign_, then + ... + viii. Return ? CreateNormalizedDurationRecord(_dateDifference_.[[Years]], + _dateDifference_.[[Months]], _dateDifference_.[[Weeks]], + _dateDifference_.[[Days]], _norm_). + h. Set _dayCorrection_ to _dayCorrection_ + 1. + 9. NOTE: This step is only reached when custom calendar or time zone methods + return inconsistent values. + 10. Throw a *RangeError* exception. +features: [Temporal] +---*/ + +// Based partly on a test case by André Bargull + +const duration1 = new Temporal.Duration(0, 0, /* weeks = */ 7, 0, /* hours = */ 12); +const duration2 = new Temporal.Duration(0, 0, 0, /* days = */ -1); + +{ + const tz = new (class extends Temporal.TimeZone { + getPossibleInstantsFor(dateTime) { + return super.getPossibleInstantsFor(dateTime.add({ days: 3 })); + } + })("UTC"); + + const relativeTo = new Temporal.ZonedDateTime(0n, tz); + + assert.throws(RangeError, () => duration1.subtract(duration2, { relativeTo }), + "Calendar calculation where more than 2 days correction is needed should cause RangeError"); +} + +{ + const cal = new (class extends Temporal.Calendar { + dateUntil(one, two, options) { + return super.dateUntil(one, two, options).negated(); + } + })("iso8601"); + + const relativeTo = new Temporal.ZonedDateTime(0n, "UTC", cal); + + assert.throws(RangeError, () => duration1.subtract(duration2, { relativeTo }), + "Calendar calculation causing mixed-sign values should cause RangeError"); +} + +reportCompare(0, 0); -- cgit v1.2.3