From ea4945c66f029077d2b9e8c7882364016a38ed1a Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Tue, 7 May 2024 17:17:26 -0700 Subject: [PATCH] Temporal: Remove tests using relativeTo in Duration.p.add/subtract 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. --- .../add/argument-duration-out-of-range.js | 14 - .../prototype/add/balance-negative-result.js | 23 +- .../add/balance-negative-time-units.js | 45 +- ...r-dateadd-called-with-options-undefined.js | 17 - ...-dateadd-called-with-plaindate-instance.js | 18 - .../prototype/add/calendar-dateadd.js | 40 -- ...euntil-called-with-singular-largestunit.js | 78 ---- .../prototype/add/calendar-fields-iterable.js | 32 -- .../prototype/add/calendar-temporal-object.js | 27 -- .../add/constructor-in-calendar-fields.js | 14 - ...eddatetime-inconsistent-custom-calendar.js | 52 --- .../add/duplicate-calendar-fields.js | 16 - .../add/infinity-throws-rangeerror.js | 5 +- ...te-instant-too-large-with-zoneddatetime.js | 18 - .../nanoseconds-is-number-max-safe-integer.js | 29 -- .../negative-infinity-throws-rangeerror.js | 5 +- .../Duration/prototype/add/options-object.js | 23 - .../prototype/add/options-undefined.js | 32 -- .../prototype/add/options-wrong-type.js | 23 - .../prototype/add/order-of-operations.js | 419 +----------------- .../add/precision-no-floating-point-loss.js | 21 - .../prototype/add/proto-in-calendar-fields.js | 14 - .../read-time-fields-before-datefromfields.js | 22 - .../relativeto-infinity-throws-rangeerror.js | 23 - .../prototype/add/relativeto-leap-second.js | 43 -- .../prototype/add/relativeto-month.js | 18 - .../prototype/add/relativeto-number.js | 25 -- .../prototype/add/relativeto-order.js | 16 - ...o-propertybag-ambiguous-wall-clock-time.js | 89 ---- ...bag-builtin-calendar-no-array-iteration.js | 22 - ...ields-called-with-null-prototype-fields.js | 16 - .../relativeto-propertybag-calendar-number.js | 26 -- .../relativeto-propertybag-calendar-string.js | 26 -- ...ativeto-propertybag-calendar-wrong-type.js | 45 -- ...nstantsfor-called-with-iso8601-calendar.js | 56 --- ...iveto-propertybag-invalid-offset-string.js | 29 -- .../relativeto-propertybag-no-time-units.js | 15 - ...ybag-out-of-range-backward-offset-shift.js | 47 -- ...tybag-out-of-range-forward-offset-shift.js | 42 -- ...one-getoffsetnanosecondsfor-non-integer.js | 16 - ...ne-getoffsetnanosecondsfor-not-callable.js | 20 - ...ne-getoffsetnanosecondsfor-out-of-range.js | 16 - ...zone-getoffsetnanosecondsfor-wrong-type.js | 25 -- ...to-propertybag-timezone-string-datetime.js | 63 --- ...propertybag-timezone-string-leap-second.js | 19 - ...o-propertybag-timezone-string-year-zero.js | 21 - .../relativeto-propertybag-timezone-string.js | 37 -- ...ativeto-propertybag-timezone-wrong-type.js | 39 -- .../prototype/add/relativeto-required.js | 33 -- .../add/relativeto-string-datetime.js | 38 -- .../add/relativeto-string-invalid.js | 13 - .../add/relativeto-string-plaindatetime.js | 15 - ...iveto-string-zoneddatetime-wrong-offset.js | 16 - .../add/relativeto-string-zoneddatetime.js | 20 - .../add/relativeto-sub-minute-offset.js | 25 -- .../prototype/add/relativeto-wrong-type.js | 43 -- .../Duration/prototype/add/relativeto-year.js | 16 - ...zoneddatetime-negative-epochnanoseconds.js | 24 - ...one-getoffsetnanosecondsfor-non-integer.js | 17 - ...ne-getoffsetnanosecondsfor-not-callable.js | 21 - ...ne-getoffsetnanosecondsfor-out-of-range.js | 17 - ...zone-getoffsetnanosecondsfor-wrong-type.js | 26 -- .../prototype/add/result-out-of-range-1.js | 11 - ...imezone-getpossibleinstantsfor-iterable.js | 43 -- .../Duration/prototype/add/year-zero.js | 17 - .../argument-duration-out-of-range.js | 14 - .../subtract/balance-negative-result.js | 21 - .../subtract/balance-negative-time-units.js | 43 +- ...r-dateadd-called-with-options-undefined.js | 17 - ...-dateadd-called-with-plaindate-instance.js | 18 - .../prototype/subtract/calendar-dateadd.js | 40 -- ...euntil-called-with-singular-largestunit.js | 78 ---- .../subtract/calendar-fields-iterable.js | 32 -- .../subtract/calendar-temporal-object.js | 27 -- .../constructor-in-calendar-fields.js | 14 - ...eddatetime-inconsistent-custom-calendar.js | 52 --- .../subtract/duplicate-calendar-fields.js | 16 - .../subtract/infinity-throws-rangeerror.js | 5 +- ...te-instant-too-large-with-zoneddatetime.js | 19 - .../nanoseconds-is-number-max-safe-integer.js | 29 -- .../negative-infinity-throws-rangeerror.js | 5 +- .../prototype/subtract/options-object.js | 23 - .../prototype/subtract/options-undefined.js | 32 -- .../prototype/subtract/options-wrong-type.js | 23 - .../prototype/subtract/order-of-operations.js | 419 +----------------- .../precision-no-floating-point-loss.js | 21 - .../subtract/proto-in-calendar-fields.js | 14 - .../read-time-fields-before-datefromfields.js | 22 - .../relativeto-infinity-throws-rangeerror.js | 23 - .../subtract/relativeto-leap-second.js | 43 -- .../prototype/subtract/relativeto-month.js | 18 - .../prototype/subtract/relativeto-number.js | 25 -- .../prototype/subtract/relativeto-order.js | 16 - ...o-propertybag-ambiguous-wall-clock-time.js | 89 ---- ...bag-builtin-calendar-no-array-iteration.js | 22 - ...ields-called-with-null-prototype-fields.js | 16 - .../relativeto-propertybag-calendar-number.js | 26 -- .../relativeto-propertybag-calendar-string.js | 26 -- ...ativeto-propertybag-calendar-wrong-type.js | 45 -- ...nstantsfor-called-with-iso8601-calendar.js | 56 --- ...iveto-propertybag-invalid-offset-string.js | 29 -- .../relativeto-propertybag-no-time-units.js | 15 - ...ybag-out-of-range-backward-offset-shift.js | 47 -- ...tybag-out-of-range-forward-offset-shift.js | 42 -- ...one-getoffsetnanosecondsfor-non-integer.js | 16 - ...ne-getoffsetnanosecondsfor-not-callable.js | 20 - ...ne-getoffsetnanosecondsfor-out-of-range.js | 16 - ...zone-getoffsetnanosecondsfor-wrong-type.js | 25 -- ...to-propertybag-timezone-string-datetime.js | 63 --- ...propertybag-timezone-string-leap-second.js | 19 - ...o-propertybag-timezone-string-year-zero.js | 21 - .../relativeto-propertybag-timezone-string.js | 37 -- ...ativeto-propertybag-timezone-wrong-type.js | 39 -- .../prototype/subtract/relativeto-required.js | 33 -- .../subtract/relativeto-string-datetime.js | 38 -- .../subtract/relativeto-string-invalid.js | 13 - .../relativeto-string-plaindatetime.js | 15 - ...iveto-string-zoneddatetime-wrong-offset.js | 16 - .../relativeto-string-zoneddatetime.js | 20 - .../subtract/relativeto-sub-minute-offset.js | 26 -- .../subtract/relativeto-wrong-type.js | 47 -- .../prototype/subtract/relativeto-year.js | 16 - ...zoneddatetime-negative-epochnanoseconds.js | 24 - ...one-getoffsetnanosecondsfor-non-integer.js | 17 - ...ne-getoffsetnanosecondsfor-not-callable.js | 21 - ...ne-getoffsetnanosecondsfor-out-of-range.js | 17 - ...zone-getoffsetnanosecondsfor-wrong-type.js | 26 -- .../subtract/result-out-of-range-1.js | 11 - ...imezone-getpossibleinstantsfor-iterable.js | 43 -- .../Duration/prototype/subtract/year-zero.js | 17 - .../relativeto-infinity-throws-rangeerror.js | 21 - .../add/relativeto-string-datetime.js | 28 -- .../add/relativeto-sub-minute-offset.js | 25 -- .../relativeto-infinity-throws-rangeerror.js | 21 - .../subtract/relativeto-string-datetime.js | 28 -- .../subtract/relativeto-sub-minute-offset.js | 26 -- .../Temporal/old/duration-arithmetic-dst.js | 19 - test/staging/Temporal/Duration/old/add.js | 137 ------ .../staging/Temporal/Duration/old/subtract.js | 102 ----- 139 files changed, 25 insertions(+), 4736 deletions(-) delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd-called-with-options-undefined.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd-called-with-plaindate-instance.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/calendar-dateuntil-called-with-singular-largestunit.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/calendar-fields-iterable.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/calendar-temporal-object.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/constructor-in-calendar-fields.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/differencezoneddatetime-inconsistent-custom-calendar.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/duplicate-calendar-fields.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/intermediate-instant-too-large-with-zoneddatetime.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/options-object.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/options-undefined.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/options-wrong-type.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/proto-in-calendar-fields.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/read-time-fields-before-datefromfields.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-infinity-throws-rangeerror.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-leap-second.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-month.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-number.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-order.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-ambiguous-wall-clock-time.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-builtin-calendar-no-array-iteration.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-datefromfields-called-with-null-prototype-fields.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-string.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-wrong-type.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-no-time-units.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-out-of-range-backward-offset-shift.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-out-of-range-forward-offset-shift.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-non-integer.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-not-callable.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-out-of-range.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-wrong-type.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string-datetime.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string-leap-second.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string-year-zero.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-wrong-type.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-required.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-string-datetime.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-string-invalid.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-string-plaindatetime.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-string-zoneddatetime-wrong-offset.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-string-zoneddatetime.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-sub-minute-offset.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-wrong-type.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-year.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-negative-epochnanoseconds.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/timezone-getpossibleinstantsfor-iterable.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/add/year-zero.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateadd-called-with-options-undefined.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateadd-called-with-plaindate-instance.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateadd.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateuntil-called-with-singular-largestunit.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/calendar-fields-iterable.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/calendar-temporal-object.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/constructor-in-calendar-fields.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/differencezoneddatetime-inconsistent-custom-calendar.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/duplicate-calendar-fields.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/intermediate-instant-too-large-with-zoneddatetime.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/options-object.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/options-undefined.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/options-wrong-type.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/proto-in-calendar-fields.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/read-time-fields-before-datefromfields.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-infinity-throws-rangeerror.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-leap-second.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-month.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-number.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-order.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-ambiguous-wall-clock-time.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-builtin-calendar-no-array-iteration.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-datefromfields-called-with-null-prototype-fields.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-string.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-wrong-type.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-invalid-offset-string.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-no-time-units.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-out-of-range-backward-offset-shift.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-out-of-range-forward-offset-shift.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-non-integer.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-not-callable.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-out-of-range.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-wrong-type.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string-datetime.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string-leap-second.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string-year-zero.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-wrong-type.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-required.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-datetime.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-invalid.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-plaindatetime.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-zoneddatetime-wrong-offset.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-zoneddatetime.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-sub-minute-offset.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-wrong-type.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-year.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-negative-epochnanoseconds.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/timezone-getpossibleinstantsfor-iterable.js delete mode 100644 test/built-ins/Temporal/Duration/prototype/subtract/year-zero.js delete mode 100644 test/intl402/Temporal/Duration/prototype/add/relativeto-infinity-throws-rangeerror.js delete mode 100644 test/intl402/Temporal/Duration/prototype/add/relativeto-string-datetime.js delete mode 100644 test/intl402/Temporal/Duration/prototype/add/relativeto-sub-minute-offset.js delete mode 100644 test/intl402/Temporal/Duration/prototype/subtract/relativeto-infinity-throws-rangeerror.js delete mode 100644 test/intl402/Temporal/Duration/prototype/subtract/relativeto-string-datetime.js delete mode 100644 test/intl402/Temporal/Duration/prototype/subtract/relativeto-sub-minute-offset.js delete mode 100644 test/staging/Temporal/Duration/old/add.js delete mode 100644 test/staging/Temporal/Duration/old/subtract.js diff --git a/test/built-ins/Temporal/Duration/prototype/add/argument-duration-out-of-range.js b/test/built-ins/Temporal/Duration/prototype/add/argument-duration-out-of-range.js index 76bdd35586c..b4882359973 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/argument-duration-out-of-range.js +++ b/test/built-ins/Temporal/Duration/prototype/add/argument-duration-out-of-range.js @@ -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"], diff --git a/test/built-ins/Temporal/Duration/prototype/add/balance-negative-result.js b/test/built-ins/Temporal/Duration/prototype/add/balance-negative-result.js index 30c164f7968..02b8b83d23f 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/balance-negative-result.js +++ b/test/built-ins/Temporal/Duration/prototype/add/balance-negative-result.js @@ -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] ---*/ @@ -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); diff --git a/test/built-ins/Temporal/Duration/prototype/add/balance-negative-time-units.js b/test/built-ins/Temporal/Duration/prototype/add/balance-negative-time-units.js index 06c068e210e..5f0bedba60b 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/balance-negative-time-units.js +++ b/test/built-ins/Temporal/Duration/prototype/add/balance-negative-time-units.js @@ -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"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd-called-with-options-undefined.js deleted file mode 100644 index 8b4e9a63538..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd-called-with-options-undefined.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - BuiltinTimeZoneGetInstantFor calls Calendar.dateAdd with undefined as the - options value -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarDateAddUndefinedOptions(); -const timeZone = TemporalHelpers.oneShiftTimeZone(new Temporal.Instant(0n), 3600e9); -const instance = new Temporal.Duration(1, 1, 1, 1); -instance.add(instance, { relativeTo: new Temporal.ZonedDateTime(0n, timeZone, calendar) }); -assert.sameValue(calendar.dateAddCallCount, 2); diff --git a/test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd-called-with-plaindate-instance.js b/test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd-called-with-plaindate-instance.js deleted file mode 100644 index 186703a0abb..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd-called-with-plaindate-instance.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - relativeTo parameters that are not ZonedDateTime or undefined, are always - converted to PlainDate for observable calendar calls -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarDateAddPlainDateInstance(); -const instance = new Temporal.Duration(1, 1, 1, 1); -const relativeTo = new Temporal.PlainDate(2000, 1, 1, calendar); -calendar.specificPlainDate = relativeTo; -instance.add(instance, { relativeTo }); -assert(calendar.dateAddCallCount > 0, "assertions in calendar.dateAdd() should have been tested"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd.js b/test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd.js deleted file mode 100644 index a81d1a379b0..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/calendar-dateadd.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Duration.prototype.add should call dateAdd with the appropriate values. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -let calls = 0; -const expected = [ - { - plainDate: [1920, 5, "M05", 3], - duration: [2, 0, 0, 4, 0, 0, 0, 0, 0, 0], - }, - { - plainDate: [1922, 5, "M05", 7], - duration: [0, 10, 0, 0, 0, 0, 0, 0, 0, 0], - }, -]; -class CustomCalendar extends Temporal.Calendar { - constructor() { - super("iso8601"); - } - dateAdd(plainDate, duration, options) { - TemporalHelpers.assertPlainDate(plainDate, ...expected[calls].plainDate, - `plainDate argument ${calls}`); - TemporalHelpers.assertDuration(duration, ...expected[calls].duration, - `duration argument ${calls}`); - assert.sameValue(options, undefined, "options argument"); - ++calls; - return super.dateAdd(plainDate, duration, options); - } -} -const relativeTo = new Temporal.PlainDate(1920, 5, 3, new CustomCalendar()); -const duration = new Temporal.Duration(2, 0, 0, 4, 2); -const result = duration.add({ months: 10, hours: 14 }, { relativeTo }); -TemporalHelpers.assertDuration(result, 2, 10, 0, 4, 16, 0, 0, 0, 0, 0, "result"); -assert.sameValue(calls, 2, "should have called dateAdd"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/calendar-dateuntil-called-with-singular-largestunit.js b/test/built-ins/Temporal/Duration/prototype/add/calendar-dateuntil-called-with-singular-largestunit.js deleted file mode 100644 index b773dc7c978..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/calendar-dateuntil-called-with-singular-largestunit.js +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: The options object passed to calendar.dateUntil has a largestUnit property with its value in the singular form -info: | - 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_). - sec-temporal-addduration steps 6-7: - 6. If _relativeTo_ has an [[InitializedTemporalPlainDateTime]] internal slot, then - ... - j. Let _dateLargestUnit_ be ! LargerOfTwoTemporalUnits(*"day"*, _largestUnit_). - k. Let _differenceOptions_ be ! OrdinaryObjectCreate(*null*). - l. Perform ! CreateDataPropertyOrThrow(_differenceOptions_, *"largestUnit"*, _dateLargestUnit_). - m. Let _dateDifference_ be ? CalendarDateUntil(_calendar_, _datePart_, _end_, _differenceOptions_). - ... - 7. Else, - a. Assert: _relativeTo_ has an [[IntializedTemporalZonedDateTime]] internal slot. - ... - f. If _largestUnit_ is not one of *"year"*, *"month"*, *"week"*, or *"day"*, then - ... - g. Else, - i. Let _result_ be ? DifferenceZonedDateTime(_relativeTo_.[[Nanoseconds]], _endNs_, _timeZone_, _calendar_, _largestUnit_). - sec-temporal-differencezoneddatetime steps 7 and 11: - 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_). - 11. Let _result_ be ? NanosecondsToDays(_timeRemainderNs_, _intermediate_). - sec-temporal-nanosecondstodays step 11: - 11. 1. 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]], _relativeTo_.[[Calendar]], *"day"*). - sec-temporal-differenceisodatetime steps 9–11: - 9. Let _dateLargestUnit_ be ! LargerOfTwoTemporalUnits(*"day"*, _largestUnit_). - 10. Let _untilOptions_ be ? MergeLargestUnitOption(_options_, _dateLargestUnit_). - 11. Let _dateDifference_ be ? CalendarDateUntil(_calendar_, _date1_, _date2_, _untilOptions_). -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -TemporalHelpers.checkCalendarDateUntilLargestUnitSingular( - (calendar, largestUnit, index) => { - const one = new Temporal.Duration(...[...Array(index).fill(0), ...Array(10 - index).fill(1)]); - const two = new Temporal.Duration(...[...Array(index).fill(0), ...Array(10 - index).fill(2)]); - const relativeTo = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar); - one.add(two, { relativeTo, largestUnit }); - }, - { - years: ["year"], - months: ["month"], - weeks: ["week"], - days: [], - hours: [], - minutes: [], - seconds: [], - milliseconds: [], - microseconds: [], - nanoseconds: [] - } -); - -TemporalHelpers.checkCalendarDateUntilLargestUnitSingular( - (calendar, largestUnit, index) => { - const one = new Temporal.Duration(...[...Array(index).fill(0), ...Array(10 - index).fill(1)]); - const two = new Temporal.Duration(...[...Array(index).fill(0), ...Array(10 - index).fill(2)]); - const relativeTo = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC", calendar); - one.add(two, { relativeTo, largestUnit }); - }, - { - years: ["year"], - months: ["month"], - weeks: ["week"], - days: [], - hours: [], - minutes: [], - seconds: [], - milliseconds: [], - microseconds: [], - nanoseconds: [] - } -); diff --git a/test/built-ins/Temporal/Duration/prototype/add/calendar-fields-iterable.js b/test/built-ins/Temporal/Duration/prototype/add/calendar-fields-iterable.js deleted file mode 100644 index 91309aa2a1f..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/calendar-fields-iterable.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Verify the result of calendar.fields() is treated correctly. -info: | - sec-temporal.duration.prototype.add step 5: - 5. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_). - sec-temporal-torelativetemporalobject step 4.c: - c. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"day"*, *"month"*, *"monthCode"*, *"year"* »). - sec-temporal-calendarfields step 4: - 4. Let _result_ be ? IterableToList(_fieldsArray_). -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -const expected = [ - "day", - "month", - "monthCode", - "year", -]; - -const calendar = TemporalHelpers.calendarFieldsIterable(); -const duration1 = new Temporal.Duration(1); -const duration2 = new Temporal.Duration(0, 12); -duration1.add(duration2, { relativeTo: { year: 2000, month: 1, day: 1, calendar } }); - -assert.sameValue(calendar.fieldsCallCount, 1, "fields() method called once"); -assert.compareArray(calendar.fieldsCalledWith[0], expected, "fields() method called with correct args"); -assert(calendar.iteratorExhausted[0], "iterated through the whole iterable"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/calendar-temporal-object.js b/test/built-ins/Temporal/Duration/prototype/add/calendar-temporal-object.js deleted file mode 100644 index aaa960358ad..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/calendar-temporal-object.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots -info: | - sec-temporal.duration.prototype.add step 5: - 5. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_). - sec-temporal-torelativetemporalobject step 4.b: - b. Let _calendar_ be ? GetTemporalCalendarWithISODefault(_item_). - sec-temporal-gettemporalcalendarwithisodefault step 2: - 2. Return ? ToTemporalCalendarWithISODefault(_calendar_). - sec-temporal-totemporalcalendarwithisodefault step 2b - 3. Return ? ToTemporalCalendar(_temporalCalendarLike_). - sec-temporal-totemporalcalendar step 1.a: - a. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then - i. Return _temporalCalendarLike_.[[Calendar]]. -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => { - const duration1 = new Temporal.Duration(1); - const duration2 = new Temporal.Duration(0, 12); - duration1.add(duration2, { relativeTo: { year: 2000, month: 1, day: 1, calendar: temporalObject } }); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/constructor-in-calendar-fields.js b/test/built-ins/Temporal/Duration/prototype/add/constructor-in-calendar-fields.js deleted file mode 100644 index f96a739fe58..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/constructor-in-calendar-fields.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2023 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-temporal.duration.prototype.add -description: If a calendar's fields() method returns a field named 'constructor', PrepareTemporalFields should throw a RangeError. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarWithExtraFields(['constructor']); -const relativeTo = { year: 2023, month: 5, monthCode: 'M05', day: 1, calendar: calendar, timeZone: 'Europe/Paris' }; -const instance = new Temporal.Duration(1, 0, 0, 1); - -assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo })); diff --git a/test/built-ins/Temporal/Duration/prototype/add/differencezoneddatetime-inconsistent-custom-calendar.js b/test/built-ins/Temporal/Duration/prototype/add/differencezoneddatetime-inconsistent-custom-calendar.js deleted file mode 100644 index 056e7186135..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/differencezoneddatetime-inconsistent-custom-calendar.js +++ /dev/null @@ -1,52 +0,0 @@ -// 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.add -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.add(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.add(duration2, { relativeTo }), - "Calendar calculation causing mixed-sign values should cause RangeError"); -} diff --git a/test/built-ins/Temporal/Duration/prototype/add/duplicate-calendar-fields.js b/test/built-ins/Temporal/Duration/prototype/add/duplicate-calendar-fields.js deleted file mode 100644 index f6feeb45d06..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/duplicate-calendar-fields.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2023 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-temporal.duration.prototype.add -description: If a calendar's fields() method returns duplicate field names, PrepareTemporalFields should throw a RangeError. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -for (const extra_fields of [['foo', 'foo'], ['day'], ['month'], ['monthCode'], ['year']]) { - const calendar = TemporalHelpers.calendarWithExtraFields(extra_fields); - const relativeTo = { year: 2023, month: 5, monthCode: 'M05', day: 1, calendar: calendar, timeZone: 'Europe/Paris' }; - const instance = new Temporal.Duration(1, 0, 0, 1); - - assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo })); -} diff --git a/test/built-ins/Temporal/Duration/prototype/add/infinity-throws-rangeerror.js b/test/built-ins/Temporal/Duration/prototype/add/infinity-throws-rangeerror.js index 502192562cb..ef57ab1ab30 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/infinity-throws-rangeerror.js +++ b/test/built-ins/Temporal/Duration/prototype/add/infinity-throws-rangeerror.js @@ -10,10 +10,9 @@ features: [Temporal] const fields = ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds', 'nanoseconds']; const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); -const relativeTo = new Temporal.PlainDateTime(2000, 1, 1); fields.forEach((field) => { - assert.throws(RangeError, () => instance.add({ [field]: Infinity }, { relativeTo })); + assert.throws(RangeError, () => instance.add({ [field]: Infinity })); }); let calls = 0; @@ -26,6 +25,6 @@ const obj = { fields.forEach((field) => { calls = 0; - assert.throws(RangeError, () => instance.add({ [field]: obj }, { relativeTo })); + assert.throws(RangeError, () => instance.add({ [field]: obj })); assert.sameValue(calls, 1, "it fails after fetching the primitive value"); }); diff --git a/test/built-ins/Temporal/Duration/prototype/add/intermediate-instant-too-large-with-zoneddatetime.js b/test/built-ins/Temporal/Duration/prototype/add/intermediate-instant-too-large-with-zoneddatetime.js deleted file mode 100644 index fcaa9210709..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/intermediate-instant-too-large-with-zoneddatetime.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2022 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - AddZonedDateTime throws a RangeError when the intermediate instant is too large. -features: [Temporal] ----*/ - -const plainDate = new Temporal.PlainDate(1970, 1, 1); -const zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC", "iso8601"); - -var duration = Temporal.Duration.from({days: 1, seconds: Number.MAX_SAFE_INTEGER - 86400}); - -var options = {relativeTo: zonedDateTime}; - -assert.throws(RangeError, () => duration.add(duration, options)); diff --git a/test/built-ins/Temporal/Duration/prototype/add/nanoseconds-is-number-max-safe-integer.js b/test/built-ins/Temporal/Duration/prototype/add/nanoseconds-is-number-max-safe-integer.js index c888faa6dbe..850ebe615a8 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/nanoseconds-is-number-max-safe-integer.js +++ b/test/built-ins/Temporal/Duration/prototype/add/nanoseconds-is-number-max-safe-integer.js @@ -9,9 +9,6 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const plainDate = new Temporal.PlainDate(1970, 1, 1); -const zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC", "iso8601"); - // Largest temporal unit is "day". const duration1 = Temporal.Duration.from({nanoseconds: Number.MAX_SAFE_INTEGER}); const duration2 = Temporal.Duration.from({nanoseconds: 2, days: 1}); @@ -29,29 +26,3 @@ TemporalHelpers.assertDuration( Number(nanos % 1000n), "duration1.add(duration2)" ); - -TemporalHelpers.assertDuration( - duration1.add(duration2, {relativeTo: plainDate}), - 0, 0, 0, - 1 + Number((nanos / (24n * 60n * 60n * 1_000_000_000n))), - Number((nanos / (60n * 60n * 1_000_000_000n)) % 24n), - Number((nanos / (60n * 1_000_000_000n)) % 60n), - Number((nanos / 1_000_000_000n) % 60n), - Number((nanos / 1_000_000n) % 1000n), - Number((nanos / 1000n) % 1000n), - Number(nanos % 1000n), - "duration1.add(duration2, {relativeTo: plainDate})" -); - -TemporalHelpers.assertDuration( - duration1.add(duration2, {relativeTo: zonedDateTime}), - 0, 0, 0, - 1 + Number((nanos / (24n * 60n * 60n * 1_000_000_000n))), - Number((nanos / (60n * 60n * 1_000_000_000n)) % 24n), - Number((nanos / (60n * 1_000_000_000n)) % 60n), - Number((nanos / 1_000_000_000n) % 60n), - Number((nanos / 1_000_000n) % 1000n), - Number((nanos / 1000n) % 1000n), - Number(nanos % 1000n), - "duration1.add(duration2, {relativeTo: zonedDateTime})" -); diff --git a/test/built-ins/Temporal/Duration/prototype/add/negative-infinity-throws-rangeerror.js b/test/built-ins/Temporal/Duration/prototype/add/negative-infinity-throws-rangeerror.js index 8ba38ab6bce..5e7ca3f91c2 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/negative-infinity-throws-rangeerror.js +++ b/test/built-ins/Temporal/Duration/prototype/add/negative-infinity-throws-rangeerror.js @@ -10,10 +10,9 @@ features: [Temporal] const fields = ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds', 'nanoseconds']; const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); -const relativeTo = new Temporal.PlainDateTime(2000, 1, 1); fields.forEach((field) => { - assert.throws(RangeError, () => instance.add({ [field]: -Infinity }, { relativeTo })); + assert.throws(RangeError, () => instance.add({ [field]: -Infinity })); }); let calls = 0; @@ -26,6 +25,6 @@ const obj = { fields.forEach((field) => { calls = 0; - assert.throws(RangeError, () => instance.add({ [field]: obj }, { relativeTo })); + assert.throws(RangeError, () => instance.add({ [field]: obj })); assert.sameValue(calls, 1, "it fails after fetching the primitive value"); }); diff --git a/test/built-ins/Temporal/Duration/prototype/add/options-object.js b/test/built-ins/Temporal/Duration/prototype/add/options-object.js deleted file mode 100644 index 420d16ea49a..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/options-object.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Empty or a function object may be used as options -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(0, 0, 0, 0, 1); - -const result1 = instance.add({ hours: 1 }, {}); -TemporalHelpers.assertDuration( - result1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, - "options may be an empty plain object" -); - -const result2 = instance.add({ hours: 1 }, () => {}); -TemporalHelpers.assertDuration( - result2, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, - "options may be a function object" -); diff --git a/test/built-ins/Temporal/Duration/prototype/add/options-undefined.js b/test/built-ins/Temporal/Duration/prototype/add/options-undefined.js deleted file mode 100644 index 1b58ed054c5..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/options-undefined.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Verify that undefined options are handled correctly. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const duration1 = new Temporal.Duration(1); -const duration2 = new Temporal.Duration(0, 12); -const duration3 = new Temporal.Duration(0, 0, 0, 1); -const duration4 = new Temporal.Duration(0, 0, 0, 0, 24); - -assert.throws(RangeError, () => duration1.add(duration2), "no options with years"); -TemporalHelpers.assertDuration(duration3.add(duration4), - 0, 0, 0, /* days = */ 2, 0, 0, 0, 0, 0, 0, - "no options with days"); - -const optionValues = [ - [undefined, "undefined"], - [{}, "plain object"], - [() => {}, "lambda"], -]; -for (const [options, description] of optionValues) { - assert.throws(RangeError, () => duration1.add(duration2, options), - `options ${description} with years`); - TemporalHelpers.assertDuration(duration3.add(duration4, options), - 0, 0, 0, /* days = */ 2, 0, 0, 0, 0, 0, 0, - `options ${description} with days`); -} diff --git a/test/built-ins/Temporal/Duration/prototype/add/options-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/add/options-wrong-type.js deleted file mode 100644 index 37500a0214b..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/options-wrong-type.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: TypeError thrown when options argument is a primitive -features: [BigInt, Symbol, Temporal] ----*/ - -const badOptions = [ - null, - true, - "some string", - Symbol(), - 1, - 2n, -]; - -const instance = new Temporal.Duration(0, 0, 0, 0, 1); -for (const value of badOptions) { - assert.throws(TypeError, () => instance.add({ hours: 1 }, value), - `TypeError on wrong options type ${typeof value}`); -}; diff --git a/test/built-ins/Temporal/Duration/prototype/add/order-of-operations.js b/test/built-ins/Temporal/Duration/prototype/add/order-of-operations.js index a8025e195c6..d2914eebe43 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/order-of-operations.js +++ b/test/built-ins/Temporal/Duration/prototype/add/order-of-operations.js @@ -40,8 +40,6 @@ const expected = [ "get fields.years", "get fields.years.valueOf", "call fields.years.valueOf", - // ToRelativeTemporalObject - "get options.relativeTo", ]; const actual = []; @@ -58,423 +56,8 @@ const simpleFields = TemporalHelpers.propertyBagObserver(actual, { nanoseconds: 1, }, "fields"); -function createOptionsObserver(relativeTo = undefined) { - return TemporalHelpers.propertyBagObserver(actual, { relativeTo }, "options"); -} - // basic order of observable operations, without any calendar units: const simpleInstance = new Temporal.Duration(0, 0, 0, 1, 1, 1, 1, 1, 1, 1); -simpleInstance.add(simpleFields, createOptionsObserver()); +simpleInstance.add(simpleFields); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -const expectedOpsForPlainRelativeTo = expected.concat([ - // ToRelativeTemporalObject - "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", - // PrepareTemporalFields - "get options.relativeTo.day", - "get options.relativeTo.day.valueOf", - "call options.relativeTo.day.valueOf", - "get options.relativeTo.hour", - "get options.relativeTo.microsecond", - "get options.relativeTo.millisecond", - "get options.relativeTo.minute", - "get options.relativeTo.month", - "get options.relativeTo.month.valueOf", - "call options.relativeTo.month.valueOf", - "get options.relativeTo.monthCode", - "get options.relativeTo.monthCode.toString", - "call options.relativeTo.monthCode.toString", - "get options.relativeTo.nanosecond", - "get options.relativeTo.offset", - "get options.relativeTo.second", - "get options.relativeTo.timeZone", - "get options.relativeTo.year", - "get options.relativeTo.year.valueOf", - "call options.relativeTo.year.valueOf", - // InterpretTemporalDateTimeFields - "call options.relativeTo.calendar.dateFromFields", - // lookup in AddDurationToOrSubtractDurationFromDuration - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", - // AddDuration - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateUntil", -]); - -const instance = new Temporal.Duration(1, 2, 0, 4, 5, 6, 7, 987, 654, 321); - -const fields = TemporalHelpers.propertyBagObserver(actual, { - years: 1, - months: 1, - weeks: 1, - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1, - nanoseconds: 1, -}, "fields"); - -const plainRelativeTo = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 1, - monthCode: "M01", - day: 1, - calendar: TemporalHelpers.calendarObserver(actual, "options.relativeTo.calendar"), -}, "options.relativeTo"); - -instance.add(fields, createOptionsObserver(plainRelativeTo)); -assert.compareArray(actual, expectedOpsForPlainRelativeTo, "order of operations with PlainDate relativeTo"); -actual.splice(0); // clear - -const expectedOpsForPlainRelativeToNoCalendarOperations = [ - // ToTemporalDurationRecord - "get fields.days", - "get fields.days.valueOf", - "call fields.days.valueOf", - "get fields.hours", - "get fields.hours.valueOf", - "call fields.hours.valueOf", - "get fields.microseconds", - "get fields.microseconds.valueOf", - "call fields.microseconds.valueOf", - "get fields.milliseconds", - "get fields.milliseconds.valueOf", - "call fields.milliseconds.valueOf", - "get fields.minutes", - "get fields.minutes.valueOf", - "call fields.minutes.valueOf", - "get fields.months", - "get fields.nanoseconds", - "get fields.nanoseconds.valueOf", - "call fields.nanoseconds.valueOf", - "get fields.seconds", - "get fields.seconds.valueOf", - "call fields.seconds.valueOf", - "get fields.weeks", - "get fields.years", - // ToRelativeTemporalObject - "get options.relativeTo", - "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", - // PrepareTemporalFields - "get options.relativeTo.day", - "get options.relativeTo.day.valueOf", - "call options.relativeTo.day.valueOf", - "get options.relativeTo.hour", - "get options.relativeTo.microsecond", - "get options.relativeTo.millisecond", - "get options.relativeTo.minute", - "get options.relativeTo.month", - "get options.relativeTo.month.valueOf", - "call options.relativeTo.month.valueOf", - "get options.relativeTo.monthCode", - "get options.relativeTo.monthCode.toString", - "call options.relativeTo.monthCode.toString", - "get options.relativeTo.nanosecond", - "get options.relativeTo.offset", - "get options.relativeTo.second", - "get options.relativeTo.timeZone", - "get options.relativeTo.year", - "get options.relativeTo.year.valueOf", - "call options.relativeTo.year.valueOf", - // InterpretTemporalDateTimeFields - "call options.relativeTo.calendar.dateFromFields", - // lookup in AddDurationToOrSubtractDurationFromDuration - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", -]; - -const noCalendarInstance = new Temporal.Duration(0, 0, 0, 4, 5, 6, 7, 987, 654, 321); - -const noCalendarFields = TemporalHelpers.propertyBagObserver(actual, { - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1, - nanoseconds: 1, -}, "fields"); - -noCalendarInstance.add(noCalendarFields, createOptionsObserver(plainRelativeTo)); -assert.compareArray(actual, expectedOpsForPlainRelativeToNoCalendarOperations, "order of operations with PlainDate relativeTo and no calendar units"); -actual.splice(0); // clear - -const expectedOpsForZonedRelativeTo = expected.concat([ - // ToRelativeTemporalObject - "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", - // PrepareTemporalFields - "get options.relativeTo.day", - "get options.relativeTo.day.valueOf", - "call options.relativeTo.day.valueOf", - "get options.relativeTo.hour", - "get options.relativeTo.hour.valueOf", - "call options.relativeTo.hour.valueOf", - "get options.relativeTo.microsecond", - "get options.relativeTo.microsecond.valueOf", - "call options.relativeTo.microsecond.valueOf", - "get options.relativeTo.millisecond", - "get options.relativeTo.millisecond.valueOf", - "call options.relativeTo.millisecond.valueOf", - "get options.relativeTo.minute", - "get options.relativeTo.minute.valueOf", - "call options.relativeTo.minute.valueOf", - "get options.relativeTo.month", - "get options.relativeTo.month.valueOf", - "call options.relativeTo.month.valueOf", - "get options.relativeTo.monthCode", - "get options.relativeTo.monthCode.toString", - "call options.relativeTo.monthCode.toString", - "get options.relativeTo.nanosecond", - "get options.relativeTo.nanosecond.valueOf", - "call options.relativeTo.nanosecond.valueOf", - "get options.relativeTo.offset", - "get options.relativeTo.offset.toString", - "call options.relativeTo.offset.toString", - "get options.relativeTo.second", - "get options.relativeTo.second.valueOf", - "call options.relativeTo.second.valueOf", - "get options.relativeTo.timeZone", - "get options.relativeTo.year", - "get options.relativeTo.year.valueOf", - "call options.relativeTo.year.valueOf", - // InterpretTemporalDateTimeFields - "call options.relativeTo.calendar.dateFromFields", - // ToRelativeTemporalObject again - "has options.relativeTo.timeZone.getOffsetNanosecondsFor", - "has options.relativeTo.timeZone.getPossibleInstantsFor", - "has options.relativeTo.timeZone.id", - // InterpretISODateTimeOffset - "get options.relativeTo.timeZone.getOffsetNanosecondsFor", - "get options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in AddDurationToOrSubtractDurationFromDuration - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", - // AddDuration - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // AddDuration → AddZonedDateTime 1 - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // AddDuration → AddZonedDateTime 2 - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // AddDuration → DifferenceZonedDateTime - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.calendar.dateUntil", -]); - -const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 1, - monthCode: "M01", - day: 1, - hour: 0, - minute: 0, - second: 0, - millisecond: 0, - microsecond: 0, - nanosecond: 0, - offset: "+00:00", - calendar: TemporalHelpers.calendarObserver(actual, "options.relativeTo.calendar"), - timeZone: TemporalHelpers.timeZoneObserver(actual, "options.relativeTo.timeZone"), -}, "options.relativeTo"); - -instance.add(fields, createOptionsObserver(zonedRelativeTo)); -assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations with ZonedDateTime relativeTo"); -actual.splice(0); // clear - -const expectedOpsForZonedRelativeToNoDaysOperations = [ - // ToTemporalDurationRecord - "get fields.days", - "get fields.hours", - "get fields.hours.valueOf", - "call fields.hours.valueOf", - "get fields.microseconds", - "get fields.microseconds.valueOf", - "call fields.microseconds.valueOf", - "get fields.milliseconds", - "get fields.milliseconds.valueOf", - "call fields.milliseconds.valueOf", - "get fields.minutes", - "get fields.minutes.valueOf", - "call fields.minutes.valueOf", - "get fields.months", - "get fields.nanoseconds", - "get fields.nanoseconds.valueOf", - "call fields.nanoseconds.valueOf", - "get fields.seconds", - "get fields.seconds.valueOf", - "call fields.seconds.valueOf", - "get fields.weeks", - "get fields.years", - // ToRelativeTemporalObject - "get options.relativeTo", - "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", - // PrepareTemporalFields - "get options.relativeTo.day", - "get options.relativeTo.day.valueOf", - "call options.relativeTo.day.valueOf", - "get options.relativeTo.hour", - "get options.relativeTo.hour.valueOf", - "call options.relativeTo.hour.valueOf", - "get options.relativeTo.microsecond", - "get options.relativeTo.microsecond.valueOf", - "call options.relativeTo.microsecond.valueOf", - "get options.relativeTo.millisecond", - "get options.relativeTo.millisecond.valueOf", - "call options.relativeTo.millisecond.valueOf", - "get options.relativeTo.minute", - "get options.relativeTo.minute.valueOf", - "call options.relativeTo.minute.valueOf", - "get options.relativeTo.month", - "get options.relativeTo.month.valueOf", - "call options.relativeTo.month.valueOf", - "get options.relativeTo.monthCode", - "get options.relativeTo.monthCode.toString", - "call options.relativeTo.monthCode.toString", - "get options.relativeTo.nanosecond", - "get options.relativeTo.nanosecond.valueOf", - "call options.relativeTo.nanosecond.valueOf", - "get options.relativeTo.offset", - "get options.relativeTo.offset.toString", - "call options.relativeTo.offset.toString", - "get options.relativeTo.second", - "get options.relativeTo.second.valueOf", - "call options.relativeTo.second.valueOf", - "get options.relativeTo.timeZone", - "get options.relativeTo.year", - "get options.relativeTo.year.valueOf", - "call options.relativeTo.year.valueOf", - // InterpretTemporalDateTimeFields - "call options.relativeTo.calendar.dateFromFields", - // ToRelativeTemporalObject again - "has options.relativeTo.timeZone.getOffsetNanosecondsFor", - "has options.relativeTo.timeZone.getPossibleInstantsFor", - "has options.relativeTo.timeZone.id", - // InterpretISODateTimeOffset - "get options.relativeTo.timeZone.getOffsetNanosecondsFor", - "get options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in AddDurationToOrSubtractDurationFromDuration - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", -]; - -const noDaysInstance = new Temporal.Duration(0, 0, 0, 0, 5, 6, 7, 987, 654, 321); - -const noDaysFields = TemporalHelpers.propertyBagObserver(actual, { - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1, - nanoseconds: 1, -}, "fields"); - -noDaysInstance.add(noDaysFields, createOptionsObserver(zonedRelativeTo)); -assert.compareArray(actual, expectedOpsForZonedRelativeToNoDaysOperations, "order of operations with ZonedDateTime relativeTo and no units above days"); -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/Duration/prototype/add/precision-no-floating-point-loss.js b/test/built-ins/Temporal/Duration/prototype/add/precision-no-floating-point-loss.js index 8fa281b455a..4adb79580ab 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/precision-no-floating-point-loss.js +++ b/test/built-ins/Temporal/Duration/prototype/add/precision-no-floating-point-loss.js @@ -9,9 +9,6 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const plainDate = new Temporal.PlainDate(1970, 1, 1); -const zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC", "iso8601"); - // Largest temporal unit is "day". const duration1 = Temporal.Duration.from({seconds: 4503599627370495, nanoseconds: 499_999_999}); const duration2 = Temporal.Duration.from({seconds: 4503599627370495 - 86400, nanoseconds: 499_999_999, days: 1}); @@ -29,21 +26,3 @@ TemporalHelpers.assertDuration( Number(nanos % 1000n), "duration1.add(duration2)" ); - -TemporalHelpers.assertDuration( - duration1.add(duration2, {relativeTo: plainDate}), - 0, 0, 0, - Number((nanos / (24n * 60n * 60n * 1_000_000_000n))), - Number((nanos / (60n * 60n * 1_000_000_000n)) % 24n), - Number((nanos / (60n * 1_000_000_000n)) % 60n), - Number((nanos / 1_000_000_000n) % 60n), - Number((nanos / 1_000_000n) % 1000n), - Number((nanos / 1000n) % 1000n), - Number(nanos % 1000n), - "duration1.add(duration2, {relativeTo: plainDate})" -); - -// Throws a RangeError because the intermediate instant is too large. -assert.throws(RangeError, () => { - duration1.add(duration2, {relativeTo: zonedDateTime}); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/proto-in-calendar-fields.js b/test/built-ins/Temporal/Duration/prototype/add/proto-in-calendar-fields.js deleted file mode 100644 index 0d05beff686..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/proto-in-calendar-fields.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2023 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. -/*--- -esid: sec-temporal.duration.prototype.add -description: If a calendar's fields() method returns a field named '__proto__', PrepareTemporalFields should throw a RangeError. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarWithExtraFields(['__proto__']); -const relativeTo = { year: 2023, month: 5, monthCode: 'M05', day: 1, calendar: calendar, timeZone: 'Europe/Paris' }; -const instance = new Temporal.Duration(1, 0, 0, 1); - -assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo })); diff --git a/test/built-ins/Temporal/Duration/prototype/add/read-time-fields-before-datefromfields.js b/test/built-ins/Temporal/Duration/prototype/add/read-time-fields-before-datefromfields.js deleted file mode 100644 index 0edbe3e00ac..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/read-time-fields-before-datefromfields.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: The time fields are read from the object before being passed to dateFromFields(). -info: | - sec-temporal.duration.prototype.add step 5: - 5. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_). - sec-temporal-torelativetemporalobject step 4.g: - g. Let _result_ be ? InterpretTemporalDateTimeFields(_calendar_, _fields_, _options_). - sec-temporal-interprettemporaldatetimefields steps 1–2: - 1. Let _timeResult_ be ? ToTemporalTimeRecord(_fields_). - 2. Let _temporalDate_ be ? DateFromFields(_calendar_, _fields_, _options_). -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarMakeInvalidGettersTime(); -const duration1 = new Temporal.Duration(1); -const duration2 = new Temporal.Duration(0, 12); -duration1.add(duration2, { relativeTo: { year: 2000, month: 1, day: 1, calendar } }); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-infinity-throws-rangeerror.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-infinity-throws-rangeerror.js deleted file mode 100644 index 187a3072001..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-infinity-throws-rangeerror.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Throws if any value in the property bag is Infinity or -Infinity -esid: sec-temporal.duration.prototype.add -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); -const base = { year: 2000, month: 5, day: 2, hour: 15, minute: 30, second: 45, millisecond: 987, microsecond: 654, nanosecond: 321 }; - -[Infinity, -Infinity].forEach((inf) => { - ["year", "month", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond"].forEach((prop) => { - assert.throws(RangeError, () => instance.add(instance, { relativeTo: { ...base, [prop]: inf } }), `${prop} property cannot be ${inf} in relativeTo`); - - const calls = []; - const obj = TemporalHelpers.toPrimitiveObserver(calls, inf, prop); - assert.throws(RangeError, () => instance.add(instance, { relativeTo: { ...base, [prop]: obj } })); - assert.compareArray(calls, [`get ${prop}.valueOf`, `call ${prop}.valueOf`], "it fails after fetching the primitive value"); - }); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-leap-second.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-leap-second.js deleted file mode 100644 index 8e392f0e9ca..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-leap-second.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Leap second is constrained in both an ISO string and a property bag -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let relativeTo = "2016-12-31T23:59:60"; -const result1 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration( - result1, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - "leap second is a valid ISO string for PlainDate relativeTo" -); - -relativeTo = "2016-12-31T23:59:60+00:00[UTC]"; -const result2 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration( - result2, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - "leap second is a valid ISO string for ZonedDateTime relativeTo" -); - -relativeTo = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60 }; -const result3 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration( - result3, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - "second: 60 is valid in a property bag for PlainDate relativeTo" -); - -relativeTo = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60, timeZone: "UTC" }; -const result4 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration( - result4, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - "second: 60 is valid in a property bag for ZonedDateTime relativeTo" -); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-month.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-month.js deleted file mode 100644 index 5523adcf709..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-month.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: relativeTo with months. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const oneMonth = new Temporal.Duration(0, 1); -const days30 = new Temporal.Duration(0, 0, 0, 30); -TemporalHelpers.assertDuration(oneMonth.add(days30, { relativeTo: Temporal.PlainDate.from('2018-01-01') }), - 0, 2, 0, 2, 0, 0, 0, 0, 0, 0, "January"); -TemporalHelpers.assertDuration(oneMonth.add(days30, { relativeTo: Temporal.PlainDate.from('2018-02-01') }), - 0, 1, 0, 30, 0, 0, 0, 0, 0, 0, "February"); -TemporalHelpers.assertDuration(oneMonth.add(days30, { relativeTo: Temporal.PlainDate.from('2018-03-01') }), - 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, "March"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-number.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-number.js deleted file mode 100644 index 7a40001dfcd..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-number.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: A number cannot be used in place of a relativeTo -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -const numbers = [ - 1, - -20191101, - 20191101, - 1234567890, -]; - -for (const relativeTo of numbers) { - assert.throws( - TypeError, - () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), - `A number (${relativeTo}) is not a valid ISO string for relativeTo` - ); -} diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-order.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-order.js deleted file mode 100644 index 3a00bd00e9a..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-order.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: relativeTo with years. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const d1 = new Temporal.Duration(0, 1, 0, 0); -const d2 = new Temporal.Duration(0, 0, 0, 30); -const relativeTo = new Temporal.PlainDate(2000, 1, 1); -TemporalHelpers.assertDuration(d1.add(d2, { relativeTo }), - 0, 2, 0, 1, 0, 0, 0, 0, 0, 0, - "first this is resolved against relativeTo, then the argument against relativeTo + this"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-ambiguous-wall-clock-time.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-ambiguous-wall-clock-time.js deleted file mode 100644 index c49734f3796..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-ambiguous-wall-clock-time.js +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2023 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - Correct time zone calls are made when converting a ZonedDateTime-like - relativeTo property bag denoting an ambiguous wall-clock time -includes: [temporalHelpers.js, compareArray.js] -features: [Temporal] ----*/ - -const actual = []; - -const dstTimeZone = TemporalHelpers.springForwardFallBackTimeZone(); -const dstTimeZoneObserver = TemporalHelpers.timeZoneObserver(actual, "timeZone", { - getOffsetNanosecondsFor: dstTimeZone.getOffsetNanosecondsFor.bind(dstTimeZone), - getPossibleInstantsFor: dstTimeZone.getPossibleInstantsFor.bind(dstTimeZone), -}); -const calendar = TemporalHelpers.calendarObserver(actual, "calendar"); - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let relativeTo = { year: 2000, month: 4, day: 2, hour: 2, minute: 30, timeZone: dstTimeZoneObserver, calendar }; -instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); - -const expected = [ - // GetTemporalCalendarSlotValueWithISODefault - "has calendar.dateAdd", - "has calendar.dateFromFields", - "has calendar.dateUntil", - "has calendar.day", - "has calendar.dayOfWeek", - "has calendar.dayOfYear", - "has calendar.daysInMonth", - "has calendar.daysInWeek", - "has calendar.daysInYear", - "has calendar.fields", - "has calendar.id", - "has calendar.inLeapYear", - "has calendar.mergeFields", - "has calendar.month", - "has calendar.monthCode", - "has calendar.monthDayFromFields", - "has calendar.monthsInYear", - "has calendar.weekOfYear", - "has calendar.year", - "has calendar.yearMonthFromFields", - "has calendar.yearOfWeek", - // lookup - "get calendar.dateFromFields", - "get calendar.fields", - // CalendarFields - "call calendar.fields", - // InterpretTemporalDateTimeFields - "call calendar.dateFromFields", - // ToTemporalTimeZoneSlotValue - "has timeZone.getOffsetNanosecondsFor", - "has timeZone.getPossibleInstantsFor", - "has timeZone.id", - // lookup - "get timeZone.getOffsetNanosecondsFor", - "get timeZone.getPossibleInstantsFor", - // InterpretISODateTimeOffset - "call timeZone.getPossibleInstantsFor", -]; - -const expectedSpringForward = expected.concat([ - // DisambiguatePossibleInstants - "call timeZone.getOffsetNanosecondsFor", - "call timeZone.getOffsetNanosecondsFor", - "call timeZone.getPossibleInstantsFor", -]); -assert.compareArray( - actual.slice(0, expectedSpringForward.length), // ignore operations after ToRelativeTemporalObject - expectedSpringForward, - "order of operations converting property bag at skipped wall-clock time" -); -actual.splice(0); // clear - -relativeTo = { year: 2000, month: 10, day: 29, hour: 1, minute: 30, timeZone: dstTimeZoneObserver, calendar }; -instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); - -assert.compareArray( - actual.slice(0, expected.length), // ignore operations after ToRelativeTemporalObject - expected, - "order of operations converting property bag at repeated wall-clock time" -); -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-builtin-calendar-no-array-iteration.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-builtin-calendar-no-array-iteration.js deleted file mode 100644 index 1bcc1772e9d..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-builtin-calendar-no-array-iteration.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2023 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - Calling the method with a relativeTo property bag with a builtin calendar - causes no observable array iteration when getting the calendar fields. -features: [Temporal] ----*/ - -const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator]; -Array.prototype[Symbol.iterator] = function arrayIterator() { - throw new Test262Error("Array should not be iterated"); -} - -const timeZone = "UTC"; -const instance = new Temporal.Duration(1, 0, 0, 1); -const relativeTo = { year: 2000, month: 5, day: 2, hour: 21, minute: 43, second: 5, timeZone, calendar: "iso8601" }; -instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); - -Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal; diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-datefromfields-called-with-null-prototype-fields.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-datefromfields-called-with-null-prototype-fields.js deleted file mode 100644 index fb97ee2f9e8..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-datefromfields-called-with-null-prototype-fields.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - Calendar.dateFromFields method is called with a null-prototype fields object -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarCheckFieldsPrototypePollution(); -const instance = new Temporal.Duration(1, 0, 0, 1); -const relativeTo = { year: 2000, month: 5, day: 2, calendar }; -instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -assert.sameValue(calendar.dateFromFieldsCallCount, 1, "dateFromFields should be called on the property bag's calendar"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number.js deleted file mode 100644 index 6be3b1dc628..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-number.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: A number as calendar in relativeTo property bag is invalid -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - TypeError, - () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), - `A number (${calendar}) is not a valid ISO string for relativeTo.calendar` - ); -} diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-string.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-string.js deleted file mode 100644 index 78af8044658..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-string.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2023 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - Builtin dateFromFields method is not observably called when the property bag - has a string-valued calendar property -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const dateFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateFromFields"); -Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", { - configurable: true, - enumerable: false, - get() { - TemporalHelpers.assertUnreachable("dateFromFields should not be looked up"); - }, -}); - -const instance = new Temporal.Duration(1, 0, 0, 1); -const relativeTo = { year: 2000, month: 5, day: 2, calendar: "iso8601" }; -instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); - -Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", dateFromFieldsOriginal); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-wrong-type.js deleted file mode 100644 index c916e994f78..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-calendar-wrong-type.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - Appropriate error thrown when relativeTo.calendar cannot be converted to a - calendar object or string -features: [BigInt, Symbol, Temporal] ----*/ - -const timeZone = new Temporal.TimeZone("UTC"); -const instance = new Temporal.Duration(1, 0, 0, 1); - -const primitiveTests = [ - [null, "null"], - [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], - [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ - [Symbol(), "symbol"], - [{}, "plain object that doesn't implement the protocol"], - [new Temporal.TimeZone("UTC"), "time zone instance"], - [Temporal.PlainDate, "Temporal.PlainDate, object"], - [Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"], - [Temporal.ZonedDateTime, "Temporal.ZonedDateTime, object"], - [Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"], -]; - -for (const [calendar, description] of typeErrorTests) { - const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), `${description} is not a valid property bag and does not convert to a string`); -} diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js deleted file mode 100644 index 0bf76744203..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2023 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - Time zone's getPossibleInstantsFor is called with a PlainDateTime with the - built-in ISO 8601 calendar -features: [Temporal] -info: | - DisambiguatePossibleInstants: - 2. Let _n_ be _possibleInstants_'s length. - ... - 5. Assert: _n_ = 0. - ... - 19. If _disambiguation_ is *"earlier"*, then - ... - c. Let _earlierDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). - d. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _earlierDateTime_). - ... - 20. Assert: _disambiguation_ is *"compatible"* or *"later"*. - ... - 23. Let _laterDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). - 24. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _laterDateTime_). ----*/ - -class SkippedDateTime extends Temporal.TimeZone { - constructor() { - super("UTC"); - this.calls = 0; - } - - getPossibleInstantsFor(dateTime) { - // Calls occur in pairs. For the first one return no possible instants so - // that DisambiguatePossibleInstants will call it again - if (this.calls++ % 2 == 0) { - return []; - } - - assert.sameValue( - dateTime.getISOFields().calendar, - "iso8601", - "getPossibleInstantsFor called with dateTime with built-in ISO 8601 calendar" - ); - return super.getPossibleInstantsFor(dateTime); - } -} - -const nonBuiltinISOCalendar = new Temporal.Calendar("iso8601"); -const timeZone = new SkippedDateTime(); -const relativeTo = { year: 2000, month: 5, day: 2, timeZone, calendar: nonBuiltinISOCalendar }; - -const instance = new Temporal.Duration(1, 0, 0, 1); -instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); - -assert.sameValue(timeZone.calls, 6, "getPossibleInstantsFor should have been called 6 times"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js deleted file mode 100644 index 17b1f87f212..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-invalid-offset-string.js +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: relativeTo property bag with offset property is rejected if offset is in the wrong format -features: [Temporal] ----*/ - -const timeZone = new Temporal.TimeZone("UTC"); -const instance = new Temporal.Duration(1, 0, 0, 1); - -const badOffsets = [ - "00:00", // missing sign - "+0", // too short - "-000:00", // too long - 0, // must be a string - null, // must be a string - true, // must be a string - 1000n, // must be a string -]; -badOffsets.forEach((offset) => { - const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; - assert.throws( - typeof(offset) === 'string' ? RangeError : TypeError, - () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), - `"${offset} is not a valid offset string` - ); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-no-time-units.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-no-time-units.js deleted file mode 100644 index 7a0899dabe1..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-no-time-units.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Missing time units in relativeTo property bag default to 0 -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let relativeTo = { year: 2000, month: 1, day: 1 }; -const result = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "missing time units default to 0"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-out-of-range-backward-offset-shift.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-out-of-range-backward-offset-shift.js deleted file mode 100644 index eabbfc9966f..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-out-of-range-backward-offset-shift.js +++ /dev/null @@ -1,47 +0,0 @@ -// 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.add -description: > - UTC offset shift returned by getPossibleInstantsFor can be at most 24 hours. -features: [Temporal] -info: | - GetPossibleInstantsFor: - 5.b.i. Let _numResults_ be _list_'s length. - ii. If _numResults_ > 1, then - 1. Let _epochNs_ be a new empty List. - 2. For each value _instant_ in list, do - a. Append _instant_.[[EpochNanoseconds]] to the end of the List _epochNs_. - 3. Let _min_ be the least element of the List _epochNs_. - 4. Let _max_ be the greatest element of the List _epochNs_. - 5. If abs(ℝ(_max_ - _min_)) > nsPerDay, throw a *RangeError* exception. ----*/ - -class ShiftLonger24Hour extends Temporal.TimeZone { - id = 'TestTimeZone'; - - constructor() { - super('UTC'); - } - - getOffsetNanosecondsFor(instant) { - return 0; - } - - getPossibleInstantsFor(plainDateTime) { - const utc = new Temporal.TimeZone("UTC"); - const [utcInstant] = utc.getPossibleInstantsFor(plainDateTime); - return [ - utcInstant.subtract({ hours: 12, nanoseconds: 1 }), - utcInstant.add({ hours: 12 }), - utcInstant, // add a third value in case the implementation doesn't sort - ]; - } -} - -const timeZone = new ShiftLonger24Hour(); -const relativeTo = { year: 1970, month: 1, day: 1, hour: 12, timeZone }; - -const instance = new Temporal.Duration(1, 0, 0, 1); -assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), "RangeError should be thrown"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-out-of-range-forward-offset-shift.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-out-of-range-forward-offset-shift.js deleted file mode 100644 index 5a01e8b4f46..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-out-of-range-forward-offset-shift.js +++ /dev/null @@ -1,42 +0,0 @@ -// 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.add -description: > - UTC offset shift returned by adjacent invocations of getOffsetNanosecondsFor - in DisambiguatePossibleInstants cannot be greater than 24 hours. -features: [Temporal] -info: | - DisambiguatePossibleInstants: - 18. If abs(_nanoseconds_) > nsPerDay, throw a *RangeError* exception. ----*/ - -class ShiftLonger24Hour extends Temporal.TimeZone { - id = 'TestTimeZone'; - _shiftEpochNs = 12n * 3600n * 1_000_000_000n; // 1970-01-01T12:00Z - - constructor() { - super('UTC'); - } - - getOffsetNanosecondsFor(instant) { - if (instant.epochNanoseconds < this._shiftEpochNs) return -12 * 3600e9; - return 12 * 3600e9 + 1; - } - - getPossibleInstantsFor(plainDateTime) { - const [utcInstant] = super.getPossibleInstantsFor(plainDateTime); - const { year, month, day } = plainDateTime; - - if (year < 1970) return [utcInstant.subtract({ hours: 12 })]; - if (year === 1970 && month === 1 && day === 1) return []; - return [utcInstant.add({ hours: 12, nanoseconds: 1 })]; - } -} - -const timeZone = new ShiftLonger24Hour(); -const relativeTo = { year: 1970, month: 1, day: 1, hour: 12, timeZone }; - -const instance = new Temporal.Duration(1, 0, 0, 1); -assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), "RangeError should be thrown"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-non-integer.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-non-integer.js deleted file mode 100644 index 6ff38ac14ec..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-non-integer.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[3600_000_000_000.5, NaN, -Infinity, Infinity].forEach((wrongOffset) => { - const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(2); - assert.throws(RangeError, () => duration.add(other, { relativeTo: { year: 2000, month: 5, day: 2, hour: 12, timeZone } })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-not-callable.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-not-callable.js deleted file mode 100644 index e09a5032c46..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-not-callable.js +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: TypeError thrown if timeZone.getOffsetNanosecondsFor is not callable -features: [BigInt, Symbol, Temporal, arrow-function] ----*/ - -[undefined, null, true, Math.PI, 'string', Symbol('sym'), 42n, {}].forEach((notCallable) => { - const timeZone = new Temporal.TimeZone("UTC"); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(2); - timeZone.getOffsetNanosecondsFor = notCallable; - assert.throws( - TypeError, - () => duration.add(other, { relativeTo: { year: 2000, month: 5, day: 2, hour: 12, timeZone } }), - `Uncallable ${notCallable === null ? 'null' : typeof notCallable} getOffsetNanosecondsFor should throw TypeError` - ); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-out-of-range.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-out-of-range.js deleted file mode 100644 index 8834694909d..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-out-of-range.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: RangeError thrown if time zone reports an offset that is out of range -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[-86400_000_000_000, 86400_000_000_000].forEach((wrongOffset) => { - const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(2); - assert.throws(RangeError, () => duration.add(other, { relativeTo: { year: 2000, month: 5, day: 2, hour: 12, timeZone } })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-wrong-type.js deleted file mode 100644 index 871d5f7dcc7..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-getoffsetnanosecondsfor-wrong-type.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: TypeError thrown if time zone reports an offset that is not a Number -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[ - undefined, - null, - true, - "+01:00", - Symbol(), - 3600_000_000_000n, - {}, - { valueOf() { return 3600_000_000_000; } }, -].forEach((wrongOffset) => { - const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(2); - assert.throws(TypeError, () => duration.add(other, { relativeTo: { year: 2000, month: 5, day: 2, hour: 12, timeZone } })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string-datetime.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string-datetime.js deleted file mode 100644 index 968c3f7a71b..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string-datetime.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Conversion of ISO date-time strings to Temporal.TimeZone instances -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1); - -let timeZone = "2021-08-19T17:30"; -assert.throws(RangeError, () => instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), "bare date-time string is not a time zone"); - -[ - "2021-08-19T17:30-07:00:01", - "2021-08-19T17:30-07:00:00", - "2021-08-19T17:30-07:00:00.1", - "2021-08-19T17:30-07:00:00.0", - "2021-08-19T17:30-07:00:00.01", - "2021-08-19T17:30-07:00:00.00", - "2021-08-19T17:30-07:00:00.001", - "2021-08-19T17:30-07:00:00.000", - "2021-08-19T17:30-07:00:00.0001", - "2021-08-19T17:30-07:00:00.0000", - "2021-08-19T17:30-07:00:00.00001", - "2021-08-19T17:30-07:00:00.00000", - "2021-08-19T17:30-07:00:00.000001", - "2021-08-19T17:30-07:00:00.000000", - "2021-08-19T17:30-07:00:00.0000001", - "2021-08-19T17:30-07:00:00.0000000", - "2021-08-19T17:30-07:00:00.00000001", - "2021-08-19T17:30-07:00:00.00000000", - "2021-08-19T17:30-07:00:00.000000001", - "2021-08-19T17:30-07:00:00.000000000", -].forEach((timeZone) => { - assert.throws( - RangeError, - () => instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), - `ISO string ${timeZone} with a sub-minute offset is not a valid time zone` - ); -}); - -// The following are all valid strings so should not throw: - -[ - "2021-08-19T17:30Z", - "2021-08-19T1730Z", - "2021-08-19T17:30-07:00", - "2021-08-19T1730-07:00", - "2021-08-19T17:30-0700", - "2021-08-19T1730-0700", - "2021-08-19T17:30[UTC]", - "2021-08-19T1730[UTC]", - "2021-08-19T17:30Z[UTC]", - "2021-08-19T1730Z[UTC]", - "2021-08-19T17:30-07:00[UTC]", - "2021-08-19T1730-07:00[UTC]", - "2021-08-19T17:30-0700[UTC]", - "2021-08-19T1730-0700[UTC]", -].forEach((timeZone) => { - instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string-leap-second.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string-leap-second.js deleted file mode 100644 index 4571c15e21b..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string-leap-second.js +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Leap second is a valid ISO string for TimeZone -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1); -let timeZone = "2016-12-31T23:59:60+00:00[UTC]"; - -// A string with a leap second is a valid ISO string, so the following -// operation should not throw - -instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); - -timeZone = "2021-08-19T17:30:45.123456789+23:59[+23:59:60]"; -assert.throws(RangeError, () => instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), "leap second in time zone name not valid"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string-year-zero.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string-year-zero.js deleted file mode 100644 index 75f689c3054..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string-year-zero.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Negative zero, as an extended year, is rejected -features: [Temporal, arrow-function] ----*/ - -const invalidStrings = [ - "-000000-10-31T17:45Z", - "-000000-10-31T17:45+00:00[UTC]", -]; -const instance = new Temporal.Duration(1); -invalidStrings.forEach((timeZone) => { - assert.throws( - RangeError, - () => instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), - "reject minus zero as extended year" - ); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string.js deleted file mode 100644 index 3b32cf8b245..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-string.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Time zone IDs are valid input for a time zone -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor"); -Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", { - configurable: true, - enumerable: false, - get() { - TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up"); - }, -}); -const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor"); -Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", { - configurable: true, - enumerable: false, - get() { - TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up"); - }, -}); - -const instance = new Temporal.Duration(1); - -// The following are all valid strings so should not throw: - -["UTC", "+01:00"].forEach((timeZone) => { - instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); -}); - -Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal); -Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-wrong-type.js deleted file mode 100644 index 3fb01906043..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-propertybag-timezone-wrong-type.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - Appropriate error thrown when argument cannot be converted to a valid string - or object for TimeZone -features: [BigInt, Symbol, Temporal] ----*/ - -const instance = new Temporal.Duration(1); - -const primitiveTests = [ - [null, "null"], - [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], - [19761118, "number that would convert to a valid ISO string in other contexts"], - [1n, "bigint"], -]; - -for (const [timeZone, description] of primitiveTests) { - assert.throws( - typeof timeZone === 'string' ? RangeError : TypeError, - () => instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ - [Symbol(), "symbol"], - [{}, "object not implementing time zone protocol"], - [new Temporal.Calendar("iso8601"), "calendar instance"], -]; - -for (const [timeZone, description] of typeErrorTests) { - assert.throws(TypeError, () => instance.add(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), `${description} is not a valid object and does not convert to a string`); -} diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-required.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-required.js deleted file mode 100644 index ae171e0f144..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-required.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: relativeTo is required if the largest unit is at least weeks. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const d = Temporal.Duration.from({ hours: 1 }); -const dy = Temporal.Duration.from({ years: 1 }); -const dm = Temporal.Duration.from({ months: 1 }); -const dw = Temporal.Duration.from({ weeks: 1 }); -assert.throws(RangeError, () => d.add(dy)); -assert.throws(RangeError, () => d.add(dm)); -assert.throws(RangeError, () => d.add(dw)); -assert.throws(RangeError, () => dy.add(d)); -assert.throws(RangeError, () => dm.add(d)); -assert.throws(RangeError, () => dw.add(d)); -const relativeTo = Temporal.PlainDate.from("2000-01-01"); -TemporalHelpers.assertDuration(d.add(dy, { relativeTo }), - 1, 0, 0, 0, 1, 0, 0, 0, 0, 0); -TemporalHelpers.assertDuration(d.add(dm, { relativeTo }), - 0, 1, 0, 0, 1, 0, 0, 0, 0, 0); -TemporalHelpers.assertDuration(d.add(dw, { relativeTo }), - 0, 0, 1, 0, 1, 0, 0, 0, 0, 0); -TemporalHelpers.assertDuration(dy.add(d, { relativeTo }), - 1, 0, 0, 0, 1, 0, 0, 0, 0, 0); -TemporalHelpers.assertDuration(dm.add(d, { relativeTo }), - 0, 1, 0, 0, 1, 0, 0, 0, 0, 0); -TemporalHelpers.assertDuration(dw.add(d, { relativeTo }), - 0, 0, 1, 0, 1, 0, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-datetime.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-datetime.js deleted file mode 100644 index 2172efa6743..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-datetime.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - Conversion of ISO date-time strings as relativeTo option to - Temporal.ZonedDateTime or Temporal.PlainDateTime instances -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let relativeTo = "2019-11-01T00:00"; -const result1 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bare date-time string is a plain relativeTo"); - -relativeTo = "2019-11-01T00:00-07:00"; -const result2 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + offset is a plain relativeTo"); - -relativeTo = "2019-11-01T00:00[-07:00]"; -const result3 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo"); - -relativeTo = "2019-11-01T00:00Z[-07:00]"; -const result4 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo"); - -relativeTo = "2019-11-01T00:00+00:00[UTC]"; -const result5 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo"); - -relativeTo = "2019-11-01T00:00Z"; -assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), "date-time + Z throws without an IANA annotation"); -relativeTo = "2019-11-01T00:00+04:15[UTC]"; -assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-invalid.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-invalid.js deleted file mode 100644 index bea9914cd45..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-invalid.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: RangeError thrown if relativeTo is a string with the wrong format -features: [Temporal] ----*/ - -['bad string', '15:30:45.123456', 'iso8601', 'UTC', 'P1YT1H'].forEach((relativeTo) => { - const duration = new Temporal.Duration(1, 0, 0, 15); - assert.throws(RangeError, () => duration.add(new Temporal.Duration(0, 0, 0, 16), { relativeTo })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-plaindatetime.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-plaindatetime.js deleted file mode 100644 index 5a806a826df..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-plaindatetime.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: The relativeTo option accepts a PlainDateTime-like ISO 8601 string -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -['2000-01-01', '2000-01-01T00:00', '2000-01-01T00:00[u-ca=iso8601]'].forEach((relativeTo) => { - const duration = new Temporal.Duration(1, 0, 0, 15); - const result = duration.add(new Temporal.Duration(0, 0, 0, 16), { relativeTo }); - TemporalHelpers.assertDuration(result, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-zoneddatetime-wrong-offset.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-zoneddatetime-wrong-offset.js deleted file mode 100644 index cf8d26038cf..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-zoneddatetime-wrong-offset.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Throws if a ZonedDateTime-like relativeTo string has the wrong UTC offset -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); -const relativeTo = "2000-01-01T00:00+05:30[UTC]"; -assert.throws( - RangeError, - () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), - "add should throw RangeError on a string with UTC offset mismatch" -); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-zoneddatetime.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-zoneddatetime.js deleted file mode 100644 index 0bc5351320d..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-string-zoneddatetime.js +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: The relativeTo option accepts a ZonedDateTime-like ISO 8601 string -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[ - '2000-01-01[UTC]', - '2000-01-01T00:00[UTC]', - '2000-01-01T00:00+00:00[UTC]', - '2000-01-01T00:00+00:00[UTC][u-ca=iso8601]', -].forEach((relativeTo) => { - const duration = new Temporal.Duration(1, 0, 0, 15); - const result = duration.add(new Temporal.Duration(0, 0, 0, 16), { relativeTo }); - TemporalHelpers.assertDuration(result, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-sub-minute-offset.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-sub-minute-offset.js deleted file mode 100644 index b80d60831a3..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-sub-minute-offset.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: relativeTo string accepts trailing zeroes in sub-minute UTC offset -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); -let result; -let relativeTo; -const action = (relativeTo) => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); - -relativeTo = "1970-01-01T00:00-00:45:00[-00:45]"; -result = action(relativeTo); -TemporalHelpers.assertDateDuration(result, 1, 0, 0, 0, "ISO string offset accepted with zero seconds (string)"); - -relativeTo = { year: 1970, month: 1, day: 1, offset: "+00:45:00.000000000", timeZone: "+00:45" }; -result = action(relativeTo); -TemporalHelpers.assertDateDuration(result, 1, 0, 0, 0, "ISO string offset accepted with zero seconds (property bag)"); - -relativeTo = "1970-01-01T00:00+00:44:30.123456789[+00:45]"; -assert.throws(RangeError, () => action(relativeTo), "rounding is not accepted between ISO offset and time zone"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-wrong-type.js deleted file mode 100644 index 80e7507074e..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-wrong-type.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - Appropriate error thrown when relativeTo cannot be converted to a valid - relativeTo string or property bag -features: [BigInt, Symbol, Temporal] ----*/ - -const timeZone = new Temporal.TimeZone("UTC"); -const instance = new Temporal.Duration(1, 0, 0, 1); - -const primitiveTests = [ - [undefined, "undefined"], - [null, "null"], - [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], - [1n, "bigint"], -]; - -for (const [relativeTo, description] of primitiveTests) { - assert.throws( - typeof relativeTo === 'string' || typeof relativeTo === 'undefined' ? RangeError : TypeError, - () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), - `${description} does not convert to a valid ISO string (first argument)` - ); -} - -const typeErrorTests = [ - [Symbol(), "symbol"], - [{}, "plain object"], - [Temporal.PlainDate, "Temporal.PlainDate, object"], - [Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"], - [Temporal.ZonedDateTime, "Temporal.ZonedDateTime, object"], - [Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"], -]; - -for (const [relativeTo, description] of typeErrorTests) { - assert.throws(TypeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), `${description} is not a valid property bag and does not convert to a string`); -} diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-year.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-year.js deleted file mode 100644 index 1c59f3dff7d..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-year.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: relativeTo with years. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const oneYear = new Temporal.Duration(1); -const days365 = new Temporal.Duration(0, 0, 0, 365); -TemporalHelpers.assertDuration(oneYear.add(days365, { relativeTo: Temporal.PlainDate.from("2016-01-01") }), - 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "non-leap year"); -TemporalHelpers.assertDuration(oneYear.add(days365, { relativeTo: Temporal.PlainDate.from("2015-01-01") }), - 1, 11, 0, 30, 0, 0, 0, 0, 0, 0, "leap year"); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-negative-epochnanoseconds.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-negative-epochnanoseconds.js deleted file mode 100644 index 377a02df2a5..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-negative-epochnanoseconds.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: A pre-epoch value is handled correctly by the modulo operation in GetISOPartsFromEpoch -info: | - sec-temporal-getisopartsfromepoch step 1: - 1. Let _remainderNs_ be the mathematical value whose sign is the sign of _epochNanoseconds_ and whose magnitude is abs(_epochNanoseconds_) modulo 106. - sec-temporal-builtintimezonegetplaindatetimefor step 2: - 2. Let _result_ be ! GetISOPartsFromEpoch(_instant_.[[Nanoseconds]]). -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -const relativeTo = new Temporal.ZonedDateTime(-13849764_999_999_999n, "UTC"); -const duration = new Temporal.Duration(0, 0, 0, 1); - -// This code path shows up anywhere we convert an exact time, before the Unix -// epoch, with nonzero microseconds or nanoseconds, into a wall time; in this -// case via relativeTo. - -const result = duration.add(duration, { relativeTo }); -TemporalHelpers.assertDuration(result, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js deleted file mode 100644 index c7d5ad54714..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[3600_000_000_000.5, NaN, -Infinity, Infinity].forEach((wrongOffset) => { - const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(2); - const relativeTo = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone); - assert.throws(RangeError, () => duration.add(other, { relativeTo })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js deleted file mode 100644 index 4770e82c6de..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: TypeError thrown if timeZone.getOffsetNanosecondsFor is not callable -features: [BigInt, Symbol, Temporal, arrow-function] ----*/ - -[undefined, null, true, Math.PI, 'string', Symbol('sym'), 42n, {}].forEach((notCallable) => { - const timeZone = new Temporal.TimeZone("UTC"); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(2); - const relativeTo = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone); - timeZone.getOffsetNanosecondsFor = notCallable; - assert.throws( - TypeError, - () => duration.add(other, { relativeTo }), - `Uncallable ${notCallable === null ? 'null' : typeof notCallable} getOffsetNanosecondsFor should throw TypeError` - ); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js deleted file mode 100644 index 937d960d6f0..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: RangeError thrown if time zone reports an offset that is out of range -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[-86400_000_000_000, 86400_000_000_000].forEach((wrongOffset) => { - const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(2); - const relativeTo = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone); - assert.throws(RangeError, () => duration.add(other, { relativeTo })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js deleted file mode 100644 index 6e86c2ffc77..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: TypeError thrown if time zone reports an offset that is not a Number -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[ - undefined, - null, - true, - "+01:00", - Symbol(), - 3600_000_000_000n, - {}, - { valueOf() { return 3600_000_000_000; } }, -].forEach((wrongOffset) => { - const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(2); - const relativeTo = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone); - assert.throws(TypeError, () => duration.add(other, { relativeTo })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/result-out-of-range-1.js b/test/built-ins/Temporal/Duration/prototype/add/result-out-of-range-1.js index b9c5f09a491..3b2d1691e70 100644 --- a/test/built-ins/Temporal/Duration/prototype/add/result-out-of-range-1.js +++ b/test/built-ins/Temporal/Duration/prototype/add/result-out-of-range-1.js @@ -8,20 +8,9 @@ description: > features: [Temporal] ---*/ -const plainDate = new Temporal.PlainDate(1970, 1, 1); -const zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC", "iso8601"); - // Largest temporal unit is "second". const duration = Temporal.Duration.from({seconds: Number.MAX_SAFE_INTEGER}); assert.throws(RangeError, () => { duration.add(duration); }); - -assert.throws(RangeError, () => { - duration.add(duration, {relativeTo: plainDate}); -}); - -assert.throws(RangeError, () => { - duration.add(duration, {relativeTo: zonedDateTime}); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/add/timezone-getpossibleinstantsfor-iterable.js b/test/built-ins/Temporal/Duration/prototype/add/timezone-getpossibleinstantsfor-iterable.js deleted file mode 100644 index 0443b1c47b3..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/timezone-getpossibleinstantsfor-iterable.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: An iterable returned from timeZone.getPossibleInstantsFor is consumed after each call -info: | - sec-temporal.duration.prototype.add steps 5–6: - 5. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_). - 6. Let _result_ be ? AddDuration(_duration_.[[Years]], [...], _duration_.[[Nanoseconds]], _other_.[[Years]], [...], _other_.[[Nanoseconds]], _relativeTo_). - sec-temporal-torelativetemporalobject step 6.d: - d. Let _epochNanoseconds_ be ? InterpretISODateTimeOffset(_result_.[[Year]], [...], _result_.[[Nanosecond]], _offsetNs_, _timeZone_, *"compatible"*, *"reject"*). - sec-temporal-interpretisodatetimeoffset step 7: - 7. Let _possibleInstants_ be ? GetPossibleInstantsFor(_timeZone_, _dateTime_). - sec-temporal-addduration steps 7.d–e and 7.g.i: - d. Let _intermediateNs_ be ? AddZonedDateTime(_relativeTo_.[[Nanoseconds]], _timeZone_, _calendar_, _y1_, [...], _ns1_). - e. Let _endNs_ be ? AddZonedDateTime(_intermediateNs_, _timeZone_, _calendar_, _y2_, [...], _ns2_). - [...] - i. Let _result_ be ? DifferenceZonedDateTime(_relativeTo_.[[Nanoseconds]], _endNs_, _timeZone_, _calendar_, _largestUnit_). - sec-temporal-differencezoneddatetime step 8: - 8. Let _intermediateNs_ be ? AddZonedDateTime(_ns1_, _timeZone_, _calendar_, _dateDifference_.[[Years]], _dateDifference_.[[Months]], _dateDifference_.[[Weeks]], 0, 0, 0, 0, 0, 0, 0). - sec-temporal-addzoneddatetime step 8: - 8. Let _intermediateInstant_ be ? BuiltinTimeZoneGetInstantFor(_timeZone_, _intermediateDateTime_, *"compatible"*). - sec-temporal-builtintimezonegetinstantfor step 1: - 1. Let _possibleInstants_ be ? GetPossibleInstantsFor(_timeZone_, _dateTime_). - sec-temporal-getpossibleinstantsfor step 2: - 2. Let _list_ be ? IterableToList(_possibleInstants_). -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const expected = [ - "2000-01-01T09:00:00", // called once on the input relativeTo object - "2001-01-01T09:00:00", // called once on relativeTo plus the receiver - "2002-01-01T09:00:00", // called once on relativeTo plus the receiver plus the argument - "2002-01-01T09:00:00", // called once on relativeTo plus the years, months, and weeks from the difference of relativeTo minus endNs -]; - -TemporalHelpers.checkTimeZonePossibleInstantsIterable((timeZone) => { - const duration1 = new Temporal.Duration(1); - const duration2 = new Temporal.Duration(0, 12); - duration1.add(duration2, { relativeTo: { year: 2000, month: 1, day: 1, hour: 9, timeZone } }); -}, expected); diff --git a/test/built-ins/Temporal/Duration/prototype/add/year-zero.js b/test/built-ins/Temporal/Duration/prototype/add/year-zero.js deleted file mode 100644 index cf807d355bb..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/add/year-zero.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: Negative zero, as an extended year, is rejected -features: [Temporal, arrow-function] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let relativeTo = "-000000-11-04T00:00"; -assert.throws( - RangeError, - () => { instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); }, - "reject minus zero as extended year" -); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/argument-duration-out-of-range.js b/test/built-ins/Temporal/Duration/prototype/subtract/argument-duration-out-of-range.js index 17b79fcc516..704a1e6f646 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/argument-duration-out-of-range.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/argument-duration-out-of-range.js @@ -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"], diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/balance-negative-result.js b/test/built-ins/Temporal/Duration/prototype/subtract/balance-negative-result.js index 3f393551325..3913519c971 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/balance-negative-result.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/balance-negative-result.js @@ -4,23 +4,6 @@ /*--- esid: sec-temporal.duration.prototype.subtract 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.subtract 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_). includes: [temporalHelpers.js] features: [Temporal] ---*/ @@ -30,7 +13,3 @@ const duration2 = new Temporal.Duration(0, 0, 0, -1); const resultNotRelative = duration1.subtract(duration2); TemporalHelpers.assertDuration(resultNotRelative, 0, 0, 0, -1, -12, 0, 0, 0, 0, 0); - -const relativeTo = new Temporal.PlainDateTime(2000, 1, 1); -const resultRelative = duration1.subtract(duration2, { relativeTo }); -TemporalHelpers.assertDuration(resultRelative, 0, 0, 0, -1, -12, 0, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/balance-negative-time-units.js b/test/built-ins/Temporal/Duration/prototype/subtract/balance-negative-time-units.js index 81a022ec9ed..bc27237bf3c 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/balance-negative-time-units.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/balance-negative-time-units.js @@ -3,58 +3,29 @@ /*--- esid: sec-temporal.duration.prototype.subtract -description: Negative time fields in relativeTo are balanced upwards +description: Negative time fields 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.subtract 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_). 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.subtract(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 0, 2), options); +const result1 = duration.subtract(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.subtract(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 0, 2), options); +const result2 = duration.subtract(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.subtract(new Temporal.Duration(0, 0, 0, 0, 0, 0, 0, 2), options); +const result3 = duration.subtract(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.subtract(new Temporal.Duration(0, 0, 0, 0, 0, 0, 2), options); +const result4 = duration.subtract(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.subtract(new Temporal.Duration(0, 0, 0, 0, 0, 2), options); +const result5 = duration.subtract(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.subtract(new Temporal.Duration(0, 0, 0, 0, 2), options); +const result6 = duration.subtract(new Temporal.Duration(0, 0, 0, 0, 2)); TemporalHelpers.assertDuration(result6, 0, 0, 0, 0, 0, -58, -58, -998, -998, -999, "hours balance"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateadd-called-with-options-undefined.js b/test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateadd-called-with-options-undefined.js deleted file mode 100644 index 941bee531a7..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateadd-called-with-options-undefined.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2021 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: > - BuiltinTimeZoneGetInstantFor calls Calendar.dateAdd with undefined as the - options value -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarDateAddUndefinedOptions(); -const timeZone = TemporalHelpers.oneShiftTimeZone(new Temporal.Instant(0n), 3600e9); -const instance = new Temporal.Duration(1, 1, 1, 1); -instance.subtract(new Temporal.Duration(-1, -1, -1, -1), { relativeTo: new Temporal.ZonedDateTime(0n, timeZone, calendar) }); -assert.sameValue(calendar.dateAddCallCount, 2); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateadd-called-with-plaindate-instance.js b/test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateadd-called-with-plaindate-instance.js deleted file mode 100644 index 0fba3ac82c8..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateadd-called-with-plaindate-instance.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2021 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: > - relativeTo parameters that are not ZonedDateTime or undefined, are always - converted to PlainDate for observable calendar calls -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarDateAddPlainDateInstance(); -const instance = new Temporal.Duration(1, 1, 1, 1); -const relativeTo = new Temporal.PlainDate(2000, 1, 1, calendar); -calendar.specificPlainDate = relativeTo; -instance.subtract(new Temporal.Duration(-1, -1, -1, -1), { relativeTo }); -assert(calendar.dateAddCallCount > 0, "assertions in calendar.dateAdd() should have been tested"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateadd.js b/test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateadd.js deleted file mode 100644 index d405c26fd2f..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateadd.js +++ /dev/null @@ -1,40 +0,0 @@ -// Copyright (C) 2022 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: Duration.prototype.subtract should call dateAdd with the appropriate values. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -let calls = 0; -const expected = [ - { - plainDate: [1920, 5, "M05", 3], - duration: [2, 0, 0, 4, 0, 0, 0, 0, 0, 0], - }, - { - plainDate: [1922, 5, "M05", 7], - duration: [0, -10, 0, 0, 0, 0, 0, 0, 0, 0], - }, -]; -class CustomCalendar extends Temporal.Calendar { - constructor() { - super("iso8601"); - } - dateAdd(plainDate, duration, options) { - TemporalHelpers.assertPlainDate(plainDate, ...expected[calls].plainDate, - `plainDate argument ${calls}`); - TemporalHelpers.assertDuration(duration, ...expected[calls].duration, - `duration argument ${calls}`); - assert.sameValue(options, undefined, "options argument"); - ++calls; - return super.dateAdd(plainDate, duration, options); - } -} -const relativeTo = new Temporal.PlainDate(1920, 5, 3, new CustomCalendar()); -const duration = new Temporal.Duration(2, 0, 0, 4, 2); -const result = duration.subtract({ months: 10, hours: 14 }, { relativeTo }); -TemporalHelpers.assertDuration(result, 1, 2, 0, 3, 12, 0, 0, 0, 0, 0, "result"); -assert.sameValue(calls, 2, "should have called dateAdd"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateuntil-called-with-singular-largestunit.js b/test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateuntil-called-with-singular-largestunit.js deleted file mode 100644 index 0f4ac38f2e4..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/calendar-dateuntil-called-with-singular-largestunit.js +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (C) 2021 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: The options object passed to calendar.dateUntil has a largestUnit property with its value in the singular form -info: | - sec-temporal.duration.prototype.subtract 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_). - sec-temporal-addduration steps 6-7: - 6. If _relativeTo_ has an [[InitializedTemporalPlainDateTime]] internal slot, then - ... - j. Let _dateLargestUnit_ be ! LargerOfTwoTemporalUnits(*"day"*, _largestUnit_). - k. Let _differenceOptions_ be ! OrdinaryObjectCreate(*null*). - l. Perform ! CreateDataPropertyOrThrow(_differenceOptions_, *"largestUnit"*, _dateLargestUnit_). - m. Let _dateDifference_ be ? CalendarDateUntil(_calendar_, _datePart_, _end_, _differenceOptions_). - ... - 7. Else, - a. Assert: _relativeTo_ has an [[IntializedTemporalZonedDateTime]] internal slot. - ... - f. If _largestUnit_ is not one of *"year"*, *"month"*, *"week"*, or *"day"*, then - ... - g. Else, - i. Let _result_ be ? DifferenceZonedDateTime(_relativeTo_.[[Nanoseconds]], _endNs_, _timeZone_, _calendar_, _largestUnit_). - sec-temporal-differencezoneddatetime steps 7 and 11: - 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_). - 11. Let _result_ be ? NanosecondsToDays(_timeRemainderNs_, _intermediate_). - sec-temporal-nanosecondstodays step 11: - 11. 1. 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]], _relativeTo_.[[Calendar]], *"day"*). - sec-temporal-differenceisodatetime steps 9–11: - 9. Let _dateLargestUnit_ be ! LargerOfTwoTemporalUnits(*"day"*, _largestUnit_). - 10. Let _untilOptions_ be ? MergeLargestUnitOption(_options_, _dateLargestUnit_). - 11. Let _dateDifference_ be ? CalendarDateUntil(_calendar_, _date1_, _date2_, _untilOptions_). -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -TemporalHelpers.checkCalendarDateUntilLargestUnitSingular( - (calendar, largestUnit, index) => { - const one = new Temporal.Duration(...[...Array(index).fill(0), ...Array(10 - index).fill(1)]); - const two = new Temporal.Duration(...[...Array(index).fill(0), ...Array(10 - index).fill(2)]); - const relativeTo = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, calendar); - two.subtract(one, { relativeTo }); - }, - { - years: ["year"], - months: ["month"], - weeks: ["week"], - days: [], - hours: [], - minutes: [], - seconds: [], - milliseconds: [], - microseconds: [], - nanoseconds: [] - } -); - -TemporalHelpers.checkCalendarDateUntilLargestUnitSingular( - (calendar, largestUnit, index) => { - const one = new Temporal.Duration(...[...Array(index).fill(0), ...Array(10 - index).fill(1)]); - const two = new Temporal.Duration(...[...Array(index).fill(0), ...Array(10 - index).fill(2)]); - const relativeTo = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, "UTC", calendar); - two.subtract(one, { relativeTo }); - }, - { - years: ["year"], - months: ["month"], - weeks: ["week"], - days: [], - hours: [], - minutes: [], - seconds: [], - milliseconds: [], - microseconds: [], - nanoseconds: [] - } -); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/calendar-fields-iterable.js b/test/built-ins/Temporal/Duration/prototype/subtract/calendar-fields-iterable.js deleted file mode 100644 index b9d887416ff..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/calendar-fields-iterable.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2021 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: Verify the result of calendar.fields() is treated correctly. -info: | - sec-temporal.duration.prototype.subtract step 5: - 5. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_). - sec-temporal-torelativetemporalobject step 4.c: - c. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"day"*, *"month"*, *"monthCode"*, *"year"* »). - sec-temporal-calendarfields step 4: - 4. Let _result_ be ? IterableToList(_fieldsArray_). -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -const expected = [ - "day", - "month", - "monthCode", - "year", -]; - -const calendar = TemporalHelpers.calendarFieldsIterable(); -const duration1 = new Temporal.Duration(1); -const duration2 = new Temporal.Duration(0, 12); -duration1.subtract(duration2, { relativeTo: { year: 2000, month: 1, day: 1, calendar } }); - -assert.sameValue(calendar.fieldsCallCount, 1, "fields() method called once"); -assert.compareArray(calendar.fieldsCalledWith[0], expected, "fields() method called with correct args"); -assert(calendar.iteratorExhausted[0], "iterated through the whole iterable"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/calendar-temporal-object.js b/test/built-ins/Temporal/Duration/prototype/subtract/calendar-temporal-object.js deleted file mode 100644 index c870c1690fc..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/calendar-temporal-object.js +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright (C) 2021 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: Fast path for converting other Temporal objects to Temporal.Calendar by reading internal slots -info: | - sec-temporal.duration.prototype.subtract step 5: - 5. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_). - sec-temporal-torelativetemporalobject step 4.b: - b. Let _calendar_ be ? GetTemporalCalendarWithISODefault(_item_). - sec-temporal-gettemporalcalendarwithisodefault step 2: - 2. Return ? ToTemporalCalendarWithISODefault(_calendar_). - sec-temporal-totemporalcalendarwithisodefault step 2: - 3. Return ? ToTemporalCalendar(_temporalCalendarLike_). - sec-temporal-totemporalcalendar step 1.a: - a. If _temporalCalendarLike_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then - i. Return _temporalCalendarLike_.[[Calendar]]. -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -TemporalHelpers.checkToTemporalCalendarFastPath((temporalObject) => { - const duration1 = new Temporal.Duration(1); - const duration2 = new Temporal.Duration(0, 12); - duration1.subtract(duration2, { relativeTo: { year: 2000, month: 1, day: 1, calendar: temporalObject } }); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/constructor-in-calendar-fields.js b/test/built-ins/Temporal/Duration/prototype/subtract/constructor-in-calendar-fields.js deleted file mode 100644 index 57fdb7666df..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/constructor-in-calendar-fields.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2023 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: If a calendar's fields() method returns a field named 'constructor', PrepareTemporalFields should throw a RangeError. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarWithExtraFields(['constructor']); -const relativeTo = { year: 2023, month: 5, monthCode: 'M05', day: 1, calendar: calendar, timeZone: 'Europe/Paris' }; -const instance = new Temporal.Duration(1, 0, 0, 1); - -assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo })); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/differencezoneddatetime-inconsistent-custom-calendar.js b/test/built-ins/Temporal/Duration/prototype/subtract/differencezoneddatetime-inconsistent-custom-calendar.js deleted file mode 100644 index 7be8462702e..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/differencezoneddatetime-inconsistent-custom-calendar.js +++ /dev/null @@ -1,52 +0,0 @@ -// 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"); -} diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/duplicate-calendar-fields.js b/test/built-ins/Temporal/Duration/prototype/subtract/duplicate-calendar-fields.js deleted file mode 100644 index 67687b8a7f4..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/duplicate-calendar-fields.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2023 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: If a calendar's fields() method returns duplicate field names, PrepareTemporalFields should throw a RangeError. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -for (const extra_fields of [['foo', 'foo'], ['day'], ['month'], ['monthCode'], ['year']]) { - const calendar = TemporalHelpers.calendarWithExtraFields(extra_fields); - const relativeTo = { year: 2023, month: 5, monthCode: 'M05', day: 1, calendar: calendar, timeZone: 'Europe/Paris' }; - const instance = new Temporal.Duration(1, 0, 0, 1); - - assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo })); -} diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/infinity-throws-rangeerror.js b/test/built-ins/Temporal/Duration/prototype/subtract/infinity-throws-rangeerror.js index e02d93c5adf..9edcab06306 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/infinity-throws-rangeerror.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/infinity-throws-rangeerror.js @@ -10,10 +10,9 @@ features: [Temporal] const fields = ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds', 'nanoseconds']; const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); -const relativeTo = new Temporal.PlainDateTime(2000, 1, 1); fields.forEach((field) => { - assert.throws(RangeError, () => instance.subtract({ [field]: Infinity }, { relativeTo })); + assert.throws(RangeError, () => instance.subtract({ [field]: Infinity })); }); let calls = 0; @@ -26,6 +25,6 @@ const obj = { fields.forEach((field) => { calls = 0; - assert.throws(RangeError, () => instance.subtract({ [field]: obj }, { relativeTo })); + assert.throws(RangeError, () => instance.subtract({ [field]: obj })); assert.sameValue(calls, 1, "it fails after fetching the primitive value"); }); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/intermediate-instant-too-large-with-zoneddatetime.js b/test/built-ins/Temporal/Duration/prototype/subtract/intermediate-instant-too-large-with-zoneddatetime.js deleted file mode 100644 index ba9ad133c08..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/intermediate-instant-too-large-with-zoneddatetime.js +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2022 André Bargull. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.subtract -description: > - AddZonedDateTime throws a RangeError when the intermediate instant is too large. -features: [Temporal] ----*/ - -const plainDate = new Temporal.PlainDate(1970, 1, 1); -const zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC", "iso8601"); - -var duration1 = Temporal.Duration.from({days: 1, seconds: Number.MAX_SAFE_INTEGER - 86400}); -var duration2 = Temporal.Duration.from({days: -1, seconds: -Number.MAX_SAFE_INTEGER + 86400}); - -var options = {relativeTo: zonedDateTime}; - -assert.throws(RangeError, () => duration1.subtract(duration2, options)); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/nanoseconds-is-number-max-safe-integer.js b/test/built-ins/Temporal/Duration/prototype/subtract/nanoseconds-is-number-max-safe-integer.js index 34f8b85c71d..3a704d69524 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/nanoseconds-is-number-max-safe-integer.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/nanoseconds-is-number-max-safe-integer.js @@ -9,9 +9,6 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const plainDate = new Temporal.PlainDate(1970, 1, 1); -const zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC", "iso8601"); - // Largest temporal unit is "day". const duration1 = Temporal.Duration.from({nanoseconds: Number.MAX_SAFE_INTEGER}); const duration2 = Temporal.Duration.from({nanoseconds: -2, days: -1}); @@ -29,29 +26,3 @@ TemporalHelpers.assertDuration( Number(nanos % 1000n), "duration1.subtract(duration2)" ); - -TemporalHelpers.assertDuration( - duration1.subtract(duration2, {relativeTo: plainDate}), - 0, 0, 0, - 1 + Number((nanos / (24n * 60n * 60n * 1_000_000_000n))), - Number((nanos / (60n * 60n * 1_000_000_000n)) % 24n), - Number((nanos / (60n * 1_000_000_000n)) % 60n), - Number((nanos / 1_000_000_000n) % 60n), - Number((nanos / 1_000_000n) % 1000n), - Number((nanos / 1000n) % 1000n), - Number(nanos % 1000n), - "duration1.subtract(duration2, {relativeTo: plainDate})" -); - -TemporalHelpers.assertDuration( - duration1.subtract(duration2, {relativeTo: zonedDateTime}), - 0, 0, 0, - 1 + Number((nanos / (24n * 60n * 60n * 1_000_000_000n))), - Number((nanos / (60n * 60n * 1_000_000_000n)) % 24n), - Number((nanos / (60n * 1_000_000_000n)) % 60n), - Number((nanos / 1_000_000_000n) % 60n), - Number((nanos / 1_000_000n) % 1000n), - Number((nanos / 1000n) % 1000n), - Number(nanos % 1000n), - "duration1.subtract(duration2, {relativeTo: zonedDateTime})" -); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/negative-infinity-throws-rangeerror.js b/test/built-ins/Temporal/Duration/prototype/subtract/negative-infinity-throws-rangeerror.js index f798ed52a29..57650d01e0a 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/negative-infinity-throws-rangeerror.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/negative-infinity-throws-rangeerror.js @@ -10,10 +10,9 @@ features: [Temporal] const fields = ['years', 'months', 'weeks', 'days', 'hours', 'minutes', 'seconds', 'milliseconds', 'microseconds', 'nanoseconds']; const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); -const relativeTo = new Temporal.PlainDateTime(2000, 1, 1); fields.forEach((field) => { - assert.throws(RangeError, () => instance.subtract({ [field]: -Infinity }, { relativeTo })); + assert.throws(RangeError, () => instance.subtract({ [field]: -Infinity })); }); let calls = 0; @@ -26,6 +25,6 @@ const obj = { fields.forEach((field) => { calls = 0; - assert.throws(RangeError, () => instance.subtract({ [field]: obj }, { relativeTo })); + assert.throws(RangeError, () => instance.subtract({ [field]: obj })); assert.sameValue(calls, 1, "it fails after fetching the primitive value"); }); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/options-object.js b/test/built-ins/Temporal/Duration/prototype/subtract/options-object.js deleted file mode 100644 index ff7c0e9abb7..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/options-object.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2022 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: Empty or a function object may be used as options -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(0, 0, 0, 0, 1); - -const result1 = instance.subtract({ hours: 1 }, {}); -TemporalHelpers.assertDuration( - result1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - "options may be an empty plain object" -); - -const result2 = instance.subtract({ hours: 1 }, () => {}); -TemporalHelpers.assertDuration( - result2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - "options may be a function object" -); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/options-undefined.js b/test/built-ins/Temporal/Duration/prototype/subtract/options-undefined.js deleted file mode 100644 index 0f6e4ac0e49..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/options-undefined.js +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (C) 2021 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: Verify that undefined options are handled correctly. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const duration1 = new Temporal.Duration(1); -const duration2 = new Temporal.Duration(0, 24); -const duration3 = new Temporal.Duration(0, 0, 0, 1); -const duration4 = new Temporal.Duration(0, 0, 0, 0, 48); - -assert.throws(RangeError, () => duration1.subtract(duration2), "no options with years"); -TemporalHelpers.assertDuration(duration3.subtract(duration4), - 0, 0, 0, /* days = */ -1, 0, 0, 0, 0, 0, 0, - "no options with days"); - -const optionValues = [ - [undefined, "undefined"], - [{}, "plain object"], - [() => {}, "lambda"], -]; -for (const [options, description] of optionValues) { - assert.throws(RangeError, () => duration1.subtract(duration2, options), - `options ${description} with years`); - TemporalHelpers.assertDuration(duration3.subtract(duration4, options), - 0, 0, 0, /* days = */ -1, 0, 0, 0, 0, 0, 0, - `options ${description} with days`); -} diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/options-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/subtract/options-wrong-type.js deleted file mode 100644 index 4bb257b88b2..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/options-wrong-type.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2022 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: TypeError thrown when options argument is a primitive -features: [BigInt, Symbol, Temporal] ----*/ - -const badOptions = [ - null, - true, - "some string", - Symbol(), - 1, - 2n, -]; - -const instance = new Temporal.Duration(0, 0, 0, 0, 1); -for (const value of badOptions) { - assert.throws(TypeError, () => instance.subtract({ hours: 1 }, value), - `TypeError on wrong options type ${typeof value}`); -}; diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/order-of-operations.js b/test/built-ins/Temporal/Duration/prototype/subtract/order-of-operations.js index b2fec25b20e..51729329f7f 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/order-of-operations.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/order-of-operations.js @@ -40,8 +40,6 @@ const expected = [ "get fields.years", "get fields.years.valueOf", "call fields.years.valueOf", - // ToRelativeTemporalObject - "get options.relativeTo", ]; const actual = []; @@ -58,423 +56,8 @@ const simpleFields = TemporalHelpers.propertyBagObserver(actual, { nanoseconds: 1, }, "fields"); -function createOptionsObserver(relativeTo = undefined) { - return TemporalHelpers.propertyBagObserver(actual, { relativeTo }, "options"); -} - // basic order of observable operations, without any calendar units: const simpleInstance = new Temporal.Duration(0, 0, 0, 1, 1, 1, 1, 1, 1, 1); -simpleInstance.subtract(simpleFields, createOptionsObserver()); +simpleInstance.subtract(simpleFields); assert.compareArray(actual, expected, "order of operations"); actual.splice(0); // clear - -const expectedOpsForPlainRelativeTo = expected.concat([ - // ToRelativeTemporalObject - "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", - // PrepareTemporalFields - "get options.relativeTo.day", - "get options.relativeTo.day.valueOf", - "call options.relativeTo.day.valueOf", - "get options.relativeTo.hour", - "get options.relativeTo.microsecond", - "get options.relativeTo.millisecond", - "get options.relativeTo.minute", - "get options.relativeTo.month", - "get options.relativeTo.month.valueOf", - "call options.relativeTo.month.valueOf", - "get options.relativeTo.monthCode", - "get options.relativeTo.monthCode.toString", - "call options.relativeTo.monthCode.toString", - "get options.relativeTo.nanosecond", - "get options.relativeTo.offset", - "get options.relativeTo.second", - "get options.relativeTo.timeZone", - "get options.relativeTo.year", - "get options.relativeTo.year.valueOf", - "call options.relativeTo.year.valueOf", - // InterpretTemporalDateTimeFields - "call options.relativeTo.calendar.dateFromFields", - // lookup in AddDurationToOrSubtractDurationFromDuration - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", - // AddDuration - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.calendar.dateUntil", -]); - -const instance = new Temporal.Duration(1, 2, 1, 4, 5, 6, 7, 987, 654, 321); - -const fields = TemporalHelpers.propertyBagObserver(actual, { - years: 1, - months: 1, - weeks: 1, - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1, - nanoseconds: 1, -}, "fields"); - -const plainRelativeTo = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 1, - monthCode: "M01", - day: 1, - calendar: TemporalHelpers.calendarObserver(actual, "options.relativeTo.calendar"), -}, "options.relativeTo"); - -instance.subtract(fields, createOptionsObserver(plainRelativeTo)); -assert.compareArray(actual, expectedOpsForPlainRelativeTo, "order of operations with PlainDate relativeTo"); -actual.splice(0); // clear - -const expectedOpsForPlainRelativeToNoCalendarOperations = [ - // ToTemporalDurationRecord - "get fields.days", - "get fields.days.valueOf", - "call fields.days.valueOf", - "get fields.hours", - "get fields.hours.valueOf", - "call fields.hours.valueOf", - "get fields.microseconds", - "get fields.microseconds.valueOf", - "call fields.microseconds.valueOf", - "get fields.milliseconds", - "get fields.milliseconds.valueOf", - "call fields.milliseconds.valueOf", - "get fields.minutes", - "get fields.minutes.valueOf", - "call fields.minutes.valueOf", - "get fields.months", - "get fields.nanoseconds", - "get fields.nanoseconds.valueOf", - "call fields.nanoseconds.valueOf", - "get fields.seconds", - "get fields.seconds.valueOf", - "call fields.seconds.valueOf", - "get fields.weeks", - "get fields.years", - // ToRelativeTemporalObject - "get options.relativeTo", - "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", - // PrepareTemporalFields - "get options.relativeTo.day", - "get options.relativeTo.day.valueOf", - "call options.relativeTo.day.valueOf", - "get options.relativeTo.hour", - "get options.relativeTo.microsecond", - "get options.relativeTo.millisecond", - "get options.relativeTo.minute", - "get options.relativeTo.month", - "get options.relativeTo.month.valueOf", - "call options.relativeTo.month.valueOf", - "get options.relativeTo.monthCode", - "get options.relativeTo.monthCode.toString", - "call options.relativeTo.monthCode.toString", - "get options.relativeTo.nanosecond", - "get options.relativeTo.offset", - "get options.relativeTo.second", - "get options.relativeTo.timeZone", - "get options.relativeTo.year", - "get options.relativeTo.year.valueOf", - "call options.relativeTo.year.valueOf", - // InterpretTemporalDateTimeFields - "call options.relativeTo.calendar.dateFromFields", - // lookup in AddDurationToOrSubtractDurationFromDuration - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", -]; - -const noCalendarInstance = new Temporal.Duration(0, 0, 0, 4, 5, 6, 7, 987, 654, 321); - -const noCalendarFields = TemporalHelpers.propertyBagObserver(actual, { - days: 1, - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1, - nanoseconds: 1, -}, "fields"); - -noCalendarInstance.subtract(noCalendarFields, createOptionsObserver(plainRelativeTo)); -assert.compareArray(actual, expectedOpsForPlainRelativeToNoCalendarOperations, "order of operations with PlainDate relativeTo and no calendar units"); -actual.splice(0); // clear - -const expectedOpsForZonedRelativeTo = expected.concat([ - // ToRelativeTemporalObject - "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", - // PrepareTemporalFields - "get options.relativeTo.day", - "get options.relativeTo.day.valueOf", - "call options.relativeTo.day.valueOf", - "get options.relativeTo.hour", - "get options.relativeTo.hour.valueOf", - "call options.relativeTo.hour.valueOf", - "get options.relativeTo.microsecond", - "get options.relativeTo.microsecond.valueOf", - "call options.relativeTo.microsecond.valueOf", - "get options.relativeTo.millisecond", - "get options.relativeTo.millisecond.valueOf", - "call options.relativeTo.millisecond.valueOf", - "get options.relativeTo.minute", - "get options.relativeTo.minute.valueOf", - "call options.relativeTo.minute.valueOf", - "get options.relativeTo.month", - "get options.relativeTo.month.valueOf", - "call options.relativeTo.month.valueOf", - "get options.relativeTo.monthCode", - "get options.relativeTo.monthCode.toString", - "call options.relativeTo.monthCode.toString", - "get options.relativeTo.nanosecond", - "get options.relativeTo.nanosecond.valueOf", - "call options.relativeTo.nanosecond.valueOf", - "get options.relativeTo.offset", - "get options.relativeTo.offset.toString", - "call options.relativeTo.offset.toString", - "get options.relativeTo.second", - "get options.relativeTo.second.valueOf", - "call options.relativeTo.second.valueOf", - "get options.relativeTo.timeZone", - "get options.relativeTo.year", - "get options.relativeTo.year.valueOf", - "call options.relativeTo.year.valueOf", - // InterpretTemporalDateTimeFields - "call options.relativeTo.calendar.dateFromFields", - // ToRelativeTemporalObject again - "has options.relativeTo.timeZone.getOffsetNanosecondsFor", - "has options.relativeTo.timeZone.getPossibleInstantsFor", - "has options.relativeTo.timeZone.id", - // InterpretISODateTimeOffset - "get options.relativeTo.timeZone.getOffsetNanosecondsFor", - "get options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in AddDurationToOrSubtractDurationFromDuration - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", - // AddDuration - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // AddDuration → AddZonedDateTime 1 - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // AddDuration → AddZonedDateTime 2 - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - "call options.relativeTo.calendar.dateAdd", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - // AddDuration → DifferenceZonedDateTime - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.calendar.dateUntil", -]); - -const zonedRelativeTo = TemporalHelpers.propertyBagObserver(actual, { - year: 2000, - month: 1, - monthCode: "M01", - day: 1, - hour: 0, - minute: 0, - second: 0, - millisecond: 0, - microsecond: 0, - nanosecond: 0, - offset: "+00:00", - calendar: TemporalHelpers.calendarObserver(actual, "options.relativeTo.calendar"), - timeZone: TemporalHelpers.timeZoneObserver(actual, "options.relativeTo.timeZone"), -}, "options.relativeTo"); - -instance.subtract(fields, createOptionsObserver(zonedRelativeTo)); -assert.compareArray(actual, expectedOpsForZonedRelativeTo, "order of operations with ZonedDateTime relativeTo"); -actual.splice(0); // clear - -const expectedOpsForZonedRelativeToNoDaysOperations = [ - // ToTemporalDurationRecord - "get fields.days", - "get fields.hours", - "get fields.hours.valueOf", - "call fields.hours.valueOf", - "get fields.microseconds", - "get fields.microseconds.valueOf", - "call fields.microseconds.valueOf", - "get fields.milliseconds", - "get fields.milliseconds.valueOf", - "call fields.milliseconds.valueOf", - "get fields.minutes", - "get fields.minutes.valueOf", - "call fields.minutes.valueOf", - "get fields.months", - "get fields.nanoseconds", - "get fields.nanoseconds.valueOf", - "call fields.nanoseconds.valueOf", - "get fields.seconds", - "get fields.seconds.valueOf", - "call fields.seconds.valueOf", - "get fields.weeks", - "get fields.years", - // ToRelativeTemporalObject - "get options.relativeTo", - "get options.relativeTo.calendar", - "has options.relativeTo.calendar.dateAdd", - "has options.relativeTo.calendar.dateFromFields", - "has options.relativeTo.calendar.dateUntil", - "has options.relativeTo.calendar.day", - "has options.relativeTo.calendar.dayOfWeek", - "has options.relativeTo.calendar.dayOfYear", - "has options.relativeTo.calendar.daysInMonth", - "has options.relativeTo.calendar.daysInWeek", - "has options.relativeTo.calendar.daysInYear", - "has options.relativeTo.calendar.fields", - "has options.relativeTo.calendar.id", - "has options.relativeTo.calendar.inLeapYear", - "has options.relativeTo.calendar.mergeFields", - "has options.relativeTo.calendar.month", - "has options.relativeTo.calendar.monthCode", - "has options.relativeTo.calendar.monthDayFromFields", - "has options.relativeTo.calendar.monthsInYear", - "has options.relativeTo.calendar.weekOfYear", - "has options.relativeTo.calendar.year", - "has options.relativeTo.calendar.yearMonthFromFields", - "has options.relativeTo.calendar.yearOfWeek", - "get options.relativeTo.calendar.dateFromFields", - "get options.relativeTo.calendar.fields", - "call options.relativeTo.calendar.fields", - // PrepareTemporalFields - "get options.relativeTo.day", - "get options.relativeTo.day.valueOf", - "call options.relativeTo.day.valueOf", - "get options.relativeTo.hour", - "get options.relativeTo.hour.valueOf", - "call options.relativeTo.hour.valueOf", - "get options.relativeTo.microsecond", - "get options.relativeTo.microsecond.valueOf", - "call options.relativeTo.microsecond.valueOf", - "get options.relativeTo.millisecond", - "get options.relativeTo.millisecond.valueOf", - "call options.relativeTo.millisecond.valueOf", - "get options.relativeTo.minute", - "get options.relativeTo.minute.valueOf", - "call options.relativeTo.minute.valueOf", - "get options.relativeTo.month", - "get options.relativeTo.month.valueOf", - "call options.relativeTo.month.valueOf", - "get options.relativeTo.monthCode", - "get options.relativeTo.monthCode.toString", - "call options.relativeTo.monthCode.toString", - "get options.relativeTo.nanosecond", - "get options.relativeTo.nanosecond.valueOf", - "call options.relativeTo.nanosecond.valueOf", - "get options.relativeTo.offset", - "get options.relativeTo.offset.toString", - "call options.relativeTo.offset.toString", - "get options.relativeTo.second", - "get options.relativeTo.second.valueOf", - "call options.relativeTo.second.valueOf", - "get options.relativeTo.timeZone", - "get options.relativeTo.year", - "get options.relativeTo.year.valueOf", - "call options.relativeTo.year.valueOf", - // InterpretTemporalDateTimeFields - "call options.relativeTo.calendar.dateFromFields", - // ToRelativeTemporalObject again - "has options.relativeTo.timeZone.getOffsetNanosecondsFor", - "has options.relativeTo.timeZone.getPossibleInstantsFor", - "has options.relativeTo.timeZone.id", - // InterpretISODateTimeOffset - "get options.relativeTo.timeZone.getOffsetNanosecondsFor", - "get options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getPossibleInstantsFor", - "call options.relativeTo.timeZone.getOffsetNanosecondsFor", - // lookup in AddDurationToOrSubtractDurationFromDuration - "get options.relativeTo.calendar.dateAdd", - "get options.relativeTo.calendar.dateUntil", -]; - -const noDaysInstance = new Temporal.Duration(0, 0, 0, 0, 5, 6, 7, 987, 654, 321); - -const noDaysFields = TemporalHelpers.propertyBagObserver(actual, { - hours: 1, - minutes: 1, - seconds: 1, - milliseconds: 1, - microseconds: 1, - nanoseconds: 1, -}, "fields"); - -noDaysInstance.subtract(noDaysFields, createOptionsObserver(zonedRelativeTo)); -assert.compareArray(actual, expectedOpsForZonedRelativeToNoDaysOperations, "order of operations with ZonedDateTime relativeTo and no units above days"); -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/precision-no-floating-point-loss.js b/test/built-ins/Temporal/Duration/prototype/subtract/precision-no-floating-point-loss.js index f3c6e88bd53..07dd18644bb 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/precision-no-floating-point-loss.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/precision-no-floating-point-loss.js @@ -9,9 +9,6 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const plainDate = new Temporal.PlainDate(1970, 1, 1); -const zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC", "iso8601"); - // Largest temporal unit is "day". const duration1 = Temporal.Duration.from({seconds: 4503599627370495, nanoseconds: 499_999_999}); const duration2 = Temporal.Duration.from({seconds: -4503599627370495 + 86400, nanoseconds: -499_999_999, days: -1}); @@ -29,21 +26,3 @@ TemporalHelpers.assertDuration( Number(nanos % 1000n), "duration1.subtract(duration2)" ); - -TemporalHelpers.assertDuration( - duration1.subtract(duration2, {relativeTo: plainDate}), - 0, 0, 0, - Number((nanos / (24n * 60n * 60n * 1_000_000_000n))), - Number((nanos / (60n * 60n * 1_000_000_000n)) % 24n), - Number((nanos / (60n * 1_000_000_000n)) % 60n), - Number((nanos / 1_000_000_000n) % 60n), - Number((nanos / 1_000_000n) % 1000n), - Number((nanos / 1000n) % 1000n), - Number(nanos % 1000n), - "duration1.subtract(duration2, {relativeTo: plainDate})" -); - -// Throws a RangeError because the intermediate instant is too large. -assert.throws(RangeError, () => { - duration1.subtract(duration2, {relativeTo: zonedDateTime}); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/proto-in-calendar-fields.js b/test/built-ins/Temporal/Duration/prototype/subtract/proto-in-calendar-fields.js deleted file mode 100644 index 891959b8ad4..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/proto-in-calendar-fields.js +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (C) 2023 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: If a calendar's fields() method returns a field named '__proto__', PrepareTemporalFields should throw a RangeError. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarWithExtraFields(['__proto__']); -const relativeTo = { year: 2023, month: 5, monthCode: 'M05', day: 1, calendar: calendar, timeZone: 'Europe/Paris' }; -const instance = new Temporal.Duration(1, 0, 0, 1); - -assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo })); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/read-time-fields-before-datefromfields.js b/test/built-ins/Temporal/Duration/prototype/subtract/read-time-fields-before-datefromfields.js deleted file mode 100644 index 05efdc7fdd6..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/read-time-fields-before-datefromfields.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2021 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: The time fields are read from the object before being passed to dateFromFields(). -info: | - sec-temporal.duration.prototype.subtract step 5: - 5. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_). - sec-temporal-torelativetemporalobject step 4.g: - g. Let _result_ be ? InterpretTemporalDateTimeFields(_calendar_, _fields_, _options_). - sec-temporal-interprettemporaldatetimefields steps 1–2: - 1. Let _timeResult_ be ? ToTemporalTimeRecord(_fields_). - 2. Let _temporalDate_ be ? DateFromFields(_calendar_, _fields_, _options_). -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarMakeInvalidGettersTime(); -const duration1 = new Temporal.Duration(1); -const duration2 = new Temporal.Duration(0, 12); -duration1.subtract(duration2, { relativeTo: { year: 2000, month: 1, day: 1, calendar } }); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-infinity-throws-rangeerror.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-infinity-throws-rangeerror.js deleted file mode 100644 index 4461f31f2a7..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-infinity-throws-rangeerror.js +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Throws if any value in the property bag is Infinity or -Infinity -esid: sec-temporal.duration.prototype.subtract -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); -const base = { year: 2000, month: 5, day: 2, hour: 15, minute: 30, second: 45, millisecond: 987, microsecond: 654, nanosecond: 321 }; - -[Infinity, -Infinity].forEach((inf) => { - ["year", "month", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond"].forEach((prop) => { - assert.throws(RangeError, () => instance.subtract(instance, { relativeTo: { ...base, [prop]: inf } }), `${prop} property cannot be ${inf} in relativeTo`); - - const calls = []; - const obj = TemporalHelpers.toPrimitiveObserver(calls, inf, prop); - assert.throws(RangeError, () => instance.subtract(instance, { relativeTo: { ...base, [prop]: obj } })); - assert.compareArray(calls, [`get ${prop}.valueOf`, `call ${prop}.valueOf`], "it fails after fetching the primitive value"); - }); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-leap-second.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-leap-second.js deleted file mode 100644 index c9af63b33b1..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-leap-second.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2022 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: Leap second is constrained in both an ISO string and a property bag -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let relativeTo = "2016-12-31T23:59:60"; -const result1 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration( - result1, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - "leap second is a valid ISO string for PlainDate relativeTo" -); - -relativeTo = "2016-12-31T23:59:60+00:00[UTC]"; -const result2 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration( - result2, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - "leap second is a valid ISO string for ZonedDateTime relativeTo" -); - -relativeTo = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60 }; -const result3 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration( - result3, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - "second: 60 is valid in a property bag for PlainDate relativeTo" -); - -relativeTo = { year: 2016, month: 12, day: 31, hour: 23, minute: 59, second: 60, timeZone: "UTC" }; -const result4 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration( - result4, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - "second: 60 is valid in a property bag for ZonedDateTime relativeTo" -); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-month.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-month.js deleted file mode 100644 index e54edd86495..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-month.js +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (C) 2022 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: relativeTo with months. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const oneMonth = new Temporal.Duration(0, 1); -const days30 = new Temporal.Duration(0, 0, 0, 30); -TemporalHelpers.assertDuration(oneMonth.subtract(days30, { relativeTo: Temporal.PlainDate.from('2018-02-01') }), - 0, 0, 0, -2, 0, 0, 0, 0, 0, 0, "February"); -TemporalHelpers.assertDuration(oneMonth.subtract(days30, { relativeTo: Temporal.PlainDate.from('2018-03-01') }), - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "March"); -TemporalHelpers.assertDuration(oneMonth.subtract(days30, { relativeTo: Temporal.PlainDate.from('2018-04-01') }), - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "April"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-number.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-number.js deleted file mode 100644 index 0f8704afb20..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-number.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2022 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: A number cannot be used in place of a relativeTo -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -const numbers = [ - 1, - 20191101, - -20191101, - 1234567890, -]; - -for (const relativeTo of numbers) { - assert.throws( - TypeError, - () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), - `A number (${relativeTo}) is not a valid ISO string for relativeTo` - ); -} diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-order.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-order.js deleted file mode 100644 index cbb51076bc2..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-order.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2022 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: relativeTo with years. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const d1 = new Temporal.Duration(0, 2, 1, 4); -const d2 = new Temporal.Duration(0, 1, 1, 1); -const relativeTo = new Temporal.PlainDate(2000, 1, 1); -TemporalHelpers.assertDuration(d1.subtract(d2, { relativeTo }), - 0, 1, 0, 3, 0, 0, 0, 0, 0, 0, - "first this is resolved against relativeTo, then the argument against relativeTo + this"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-ambiguous-wall-clock-time.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-ambiguous-wall-clock-time.js deleted file mode 100644 index 0eb4c8992ca..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-ambiguous-wall-clock-time.js +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (C) 2023 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: > - Correct time zone calls are made when converting a ZonedDateTime-like - relativeTo property bag denoting an ambiguous wall-clock time -includes: [temporalHelpers.js, compareArray.js] -features: [Temporal] ----*/ - -const actual = []; - -const dstTimeZone = TemporalHelpers.springForwardFallBackTimeZone(); -const dstTimeZoneObserver = TemporalHelpers.timeZoneObserver(actual, "timeZone", { - getOffsetNanosecondsFor: dstTimeZone.getOffsetNanosecondsFor.bind(dstTimeZone), - getPossibleInstantsFor: dstTimeZone.getPossibleInstantsFor.bind(dstTimeZone), -}); -const calendar = TemporalHelpers.calendarObserver(actual, "calendar"); - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let relativeTo = { year: 2000, month: 4, day: 2, hour: 2, minute: 30, timeZone: dstTimeZoneObserver, calendar }; -instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); - -const expected = [ - // GetTemporalCalendarSlotValueWithISODefault - "has calendar.dateAdd", - "has calendar.dateFromFields", - "has calendar.dateUntil", - "has calendar.day", - "has calendar.dayOfWeek", - "has calendar.dayOfYear", - "has calendar.daysInMonth", - "has calendar.daysInWeek", - "has calendar.daysInYear", - "has calendar.fields", - "has calendar.id", - "has calendar.inLeapYear", - "has calendar.mergeFields", - "has calendar.month", - "has calendar.monthCode", - "has calendar.monthDayFromFields", - "has calendar.monthsInYear", - "has calendar.weekOfYear", - "has calendar.year", - "has calendar.yearMonthFromFields", - "has calendar.yearOfWeek", - // lookup - "get calendar.dateFromFields", - "get calendar.fields", - // CalendarFields - "call calendar.fields", - // InterpretTemporalDateTimeFields - "call calendar.dateFromFields", - // ToTemporalTimeZoneSlotValue - "has timeZone.getOffsetNanosecondsFor", - "has timeZone.getPossibleInstantsFor", - "has timeZone.id", - // lookup - "get timeZone.getOffsetNanosecondsFor", - "get timeZone.getPossibleInstantsFor", - // InterpretISODateTimeOffset - "call timeZone.getPossibleInstantsFor", -]; - -const expectedSpringForward = expected.concat([ - // DisambiguatePossibleInstants - "call timeZone.getOffsetNanosecondsFor", - "call timeZone.getOffsetNanosecondsFor", - "call timeZone.getPossibleInstantsFor", -]); -assert.compareArray( - actual.slice(0, expectedSpringForward.length), // ignore operations after ToRelativeTemporalObject - expectedSpringForward, - "order of operations converting property bag at skipped wall-clock time" -); -actual.splice(0); // clear - -relativeTo = { year: 2000, month: 10, day: 29, hour: 1, minute: 30, timeZone: dstTimeZoneObserver, calendar }; -instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); - -assert.compareArray( - actual.slice(0, expected.length), // ignore operations after ToRelativeTemporalObject - expected, - "order of operations converting property bag at repeated wall-clock time" -); -actual.splice(0); // clear diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-builtin-calendar-no-array-iteration.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-builtin-calendar-no-array-iteration.js deleted file mode 100644 index a7020b87a07..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-builtin-calendar-no-array-iteration.js +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (C) 2023 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: > - Calling the method with a relativeTo property bag with a builtin calendar - causes no observable array iteration when getting the calendar fields. -features: [Temporal] ----*/ - -const arrayPrototypeSymbolIteratorOriginal = Array.prototype[Symbol.iterator]; -Array.prototype[Symbol.iterator] = function arrayIterator() { - throw new Test262Error("Array should not be iterated"); -} - -const timeZone = "UTC"; -const instance = new Temporal.Duration(1, 0, 0, 1); -const relativeTo = { year: 2000, month: 5, day: 2, hour: 21, minute: 43, second: 5, timeZone, calendar: "iso8601" }; -instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); - -Array.prototype[Symbol.iterator] = arrayPrototypeSymbolIteratorOriginal; diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-datefromfields-called-with-null-prototype-fields.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-datefromfields-called-with-null-prototype-fields.js deleted file mode 100644 index f4f043136e1..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-datefromfields-called-with-null-prototype-fields.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2022 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: > - Calendar.dateFromFields method is called with a null-prototype fields object -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const calendar = TemporalHelpers.calendarCheckFieldsPrototypePollution(); -const instance = new Temporal.Duration(1, 0, 0, 1); -const relativeTo = { year: 2000, month: 5, day: 2, calendar }; -instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -assert.sameValue(calendar.dateFromFieldsCallCount, 1, "dateFromFields should be called on the property bag's calendar"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number.js deleted file mode 100644 index 8b674e55d9f..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-number.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2022 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: A number as calendar in relativeTo property bag is invalid -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -const numbers = [ - 1, - 19970327, - -19970327, - 1234567890, -]; - -for (const calendar of numbers) { - const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - TypeError, - () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), - `A number (${calendar}) is not a valid ISO string for relativeTo.calendar` - ); -} diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-string.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-string.js deleted file mode 100644 index 989b046d921..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-string.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2023 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: > - Builtin dateFromFields method is not observably called when the property bag - has a string-valued calendar property -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const dateFromFieldsOriginal = Object.getOwnPropertyDescriptor(Temporal.Calendar.prototype, "dateFromFields"); -Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", { - configurable: true, - enumerable: false, - get() { - TemporalHelpers.assertUnreachable("dateFromFields should not be looked up"); - }, -}); - -const instance = new Temporal.Duration(1, 0, 0, 1); -const relativeTo = { year: 2000, month: 5, day: 2, calendar: "iso8601" }; -instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); - -Object.defineProperty(Temporal.Calendar.prototype, "dateFromFields", dateFromFieldsOriginal); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-wrong-type.js deleted file mode 100644 index 120b8925c5a..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-calendar-wrong-type.js +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (C) 2022 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: > - Appropriate error thrown when relativeTo.calendar cannot be converted to a - calendar object or string -features: [BigInt, Symbol, Temporal] ----*/ - -const timeZone = new Temporal.TimeZone("UTC"); -const instance = new Temporal.Duration(1, 0, 0, 1); - -const primitiveTests = [ - [null, "null"], - [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], - [1n, "bigint"], -]; - -for (const [calendar, description] of primitiveTests) { - const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws( - typeof calendar === 'string' ? RangeError : TypeError, - () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ - [Symbol(), "symbol"], - [{}, "plain object that doesn't implement the protocol"], - [new Temporal.TimeZone("UTC"), "time zone instance"], - [Temporal.PlainDate, "Temporal.PlainDate, object"], - [Temporal.PlainDate.prototype, "Temporal.PlainDate.prototype, object"], - [Temporal.ZonedDateTime, "Temporal.ZonedDateTime, object"], - [Temporal.ZonedDateTime.prototype, "Temporal.ZonedDateTime.prototype, object"], -]; - -for (const [calendar, description] of typeErrorTests) { - const relativeTo = { year: 2019, monthCode: "M11", day: 1, calendar }; - assert.throws(TypeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), `${description} is not a valid property bag and does not convert to a string`); -} diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js deleted file mode 100644 index 25ec3a18bf8..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-getpossibleinstantsfor-called-with-iso8601-calendar.js +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright (C) 2023 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: > - Time zone's getPossibleInstantsFor is called with a PlainDateTime with the - built-in ISO 8601 calendar -features: [Temporal] -info: | - DisambiguatePossibleInstants: - 2. Let _n_ be _possibleInstants_'s length. - ... - 5. Assert: _n_ = 0. - ... - 19. If _disambiguation_ is *"earlier"*, then - ... - c. Let _earlierDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). - d. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _earlierDateTime_). - ... - 20. Assert: _disambiguation_ is *"compatible"* or *"later"*. - ... - 23. Let _laterDateTime_ be ! CreateTemporalDateTime(..., *"iso8601"*). - 24. Set _possibleInstants_ to ? GetPossibleInstantsFor(_timeZone_, _laterDateTime_). ----*/ - -class SkippedDateTime extends Temporal.TimeZone { - constructor() { - super("UTC"); - this.calls = 0; - } - - getPossibleInstantsFor(dateTime) { - // Calls occur in pairs. For the first one return no possible instants so - // that DisambiguatePossibleInstants will call it again - if (this.calls++ % 2 == 0) { - return []; - } - - assert.sameValue( - dateTime.getISOFields().calendar, - "iso8601", - "getPossibleInstantsFor called with dateTime with built-in ISO 8601 calendar" - ); - return super.getPossibleInstantsFor(dateTime); - } -} - -const nonBuiltinISOCalendar = new Temporal.Calendar("iso8601"); -const timeZone = new SkippedDateTime(); -const relativeTo = { year: 2000, month: 5, day: 2, timeZone, calendar: nonBuiltinISOCalendar }; - -const instance = new Temporal.Duration(1, 0, 0, 1); -instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); - -assert.sameValue(timeZone.calls, 6, "getPossibleInstantsFor should have been called 6 times"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-invalid-offset-string.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-invalid-offset-string.js deleted file mode 100644 index 9f16c9f60e3..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-invalid-offset-string.js +++ /dev/null @@ -1,29 +0,0 @@ -// Copyright (C) 2022 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: relativeTo property bag with offset property is rejected if offset is in the wrong format -features: [Temporal] ----*/ - -const timeZone = new Temporal.TimeZone("UTC"); -const instance = new Temporal.Duration(1, 0, 0, 1); - -const badOffsets = [ - "00:00", // missing sign - "+0", // too short - "-000:00", // too long - 0, // must be a string - null, // must be a string - true, // must be a string - 1000n, // must be a string -]; -badOffsets.forEach((offset) => { - const relativeTo = { year: 2021, month: 10, day: 28, offset, timeZone }; - assert.throws( - typeof(offset) === 'string' ? RangeError : TypeError, - () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), - { relativeTo }), `"${offset} is not a valid offset string` - ); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-no-time-units.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-no-time-units.js deleted file mode 100644 index 1e6f55be77a..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-no-time-units.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2021 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: Missing time units in relativeTo property bag default to 0 -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let relativeTo = { year: 2000, month: 1, day: 1 }; -const result = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "missing time units default to 0"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-out-of-range-backward-offset-shift.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-out-of-range-backward-offset-shift.js deleted file mode 100644 index 70ad89002e4..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-out-of-range-backward-offset-shift.js +++ /dev/null @@ -1,47 +0,0 @@ -// 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: > - UTC offset shift returned by getPossibleInstantsFor can be at most 24 hours. -features: [Temporal] -info: | - GetPossibleInstantsFor: - 5.b.i. Let _numResults_ be _list_'s length. - ii. If _numResults_ > 1, then - 1. Let _epochNs_ be a new empty List. - 2. For each value _instant_ in list, do - a. Append _instant_.[[EpochNanoseconds]] to the end of the List _epochNs_. - 3. Let _min_ be the least element of the List _epochNs_. - 4. Let _max_ be the greatest element of the List _epochNs_. - 5. If abs(ℝ(_max_ - _min_)) > nsPerDay, throw a *RangeError* exception. ----*/ - -class ShiftLonger24Hour extends Temporal.TimeZone { - id = 'TestTimeZone'; - - constructor() { - super('UTC'); - } - - getOffsetNanosecondsFor(instant) { - return 0; - } - - getPossibleInstantsFor(plainDateTime) { - const utc = new Temporal.TimeZone("UTC"); - const [utcInstant] = utc.getPossibleInstantsFor(plainDateTime); - return [ - utcInstant.subtract({ hours: 12, nanoseconds: 1 }), - utcInstant.add({ hours: 12 }), - utcInstant, // add a third value in case the implementation doesn't sort - ]; - } -} - -const timeZone = new ShiftLonger24Hour(); -const relativeTo = { year: 1970, month: 1, day: 1, hour: 12, timeZone }; - -const instance = new Temporal.Duration(1, 0, 0, 1); -assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), "RangeError should be thrown"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-out-of-range-forward-offset-shift.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-out-of-range-forward-offset-shift.js deleted file mode 100644 index 3fb7c91a9cd..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-out-of-range-forward-offset-shift.js +++ /dev/null @@ -1,42 +0,0 @@ -// 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: > - UTC offset shift returned by adjacent invocations of getOffsetNanosecondsFor - in DisambiguatePossibleInstants cannot be greater than 24 hours. -features: [Temporal] -info: | - DisambiguatePossibleInstants: - 18. If abs(_nanoseconds_) > nsPerDay, throw a *RangeError* exception. ----*/ - -class ShiftLonger24Hour extends Temporal.TimeZone { - id = 'TestTimeZone'; - _shiftEpochNs = 12n * 3600n * 1_000_000_000n; // 1970-01-01T12:00Z - - constructor() { - super('UTC'); - } - - getOffsetNanosecondsFor(instant) { - if (instant.epochNanoseconds < this._shiftEpochNs) return -12 * 3600e9; - return 12 * 3600e9 + 1; - } - - getPossibleInstantsFor(plainDateTime) { - const [utcInstant] = super.getPossibleInstantsFor(plainDateTime); - const { year, month, day } = plainDateTime; - - if (year < 1970) return [utcInstant.subtract({ hours: 12 })]; - if (year === 1970 && month === 1 && day === 1) return []; - return [utcInstant.add({ hours: 12, nanoseconds: 1 })]; - } -} - -const timeZone = new ShiftLonger24Hour(); -const relativeTo = { year: 1970, month: 1, day: 1, hour: 12, timeZone }; - -const instance = new Temporal.Duration(1, 0, 0, 1); -assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), "RangeError should be thrown"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-non-integer.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-non-integer.js deleted file mode 100644 index 1dc97f3ac1d..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-non-integer.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2021 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: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[3600_000_000_000.5, NaN, -Infinity, Infinity].forEach((wrongOffset) => { - const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(0, 3); - assert.throws(RangeError, () => duration.subtract(other, { relativeTo: { year: 2000, month: 5, day: 2, hour: 12, timeZone } })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-not-callable.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-not-callable.js deleted file mode 100644 index 19eac88965a..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-not-callable.js +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2021 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: TypeError thrown if timeZone.getOffsetNanosecondsFor is not callable -features: [BigInt, Symbol, Temporal, arrow-function] ----*/ - -[undefined, null, true, Math.PI, 'string', Symbol('sym'), 42n, {}].forEach((notCallable) => { - const timeZone = new Temporal.TimeZone("UTC"); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(0, 3); - timeZone.getOffsetNanosecondsFor = notCallable; - assert.throws( - TypeError, - () => duration.subtract(other, { relativeTo: { year: 2000, month: 5, day: 2, hour: 12, timeZone } }), - `Uncallable ${notCallable === null ? 'null' : typeof notCallable} getOffsetNanosecondsFor should throw TypeError` - ); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-out-of-range.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-out-of-range.js deleted file mode 100644 index d2e13a7193f..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-out-of-range.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2021 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: RangeError thrown if time zone reports an offset that is out of range -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[-86400_000_000_000, 86400_000_000_000].forEach((wrongOffset) => { - const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(0, 3); - assert.throws(RangeError, () => duration.subtract(other, { relativeTo: { year: 2000, month: 5, day: 2, hour: 12, timeZone } })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-wrong-type.js deleted file mode 100644 index 46558f50d44..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-getoffsetnanosecondsfor-wrong-type.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2021 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: TypeError thrown if time zone reports an offset that is not a Number -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[ - undefined, - null, - true, - "+01:00", - Symbol(), - 3600_000_000_000n, - {}, - { valueOf() { return 3600_000_000_000; } }, -].forEach((wrongOffset) => { - const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(0, 3); - assert.throws(TypeError, () => duration.subtract(other, { relativeTo: { year: 2000, month: 5, day: 2, hour: 12, timeZone } })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string-datetime.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string-datetime.js deleted file mode 100644 index 7a78717a797..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string-datetime.js +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright (C) 2021 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: Conversion of ISO date-time strings to Temporal.TimeZone instances -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1); - -let timeZone = "2021-08-19T17:30"; -assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), "bare date-time string is not a time zone"); - -[ - "2021-08-19T17:30-07:00:01", - "2021-08-19T17:30-07:00:00", - "2021-08-19T17:30-07:00:00.1", - "2021-08-19T17:30-07:00:00.0", - "2021-08-19T17:30-07:00:00.01", - "2021-08-19T17:30-07:00:00.00", - "2021-08-19T17:30-07:00:00.001", - "2021-08-19T17:30-07:00:00.000", - "2021-08-19T17:30-07:00:00.0001", - "2021-08-19T17:30-07:00:00.0000", - "2021-08-19T17:30-07:00:00.00001", - "2021-08-19T17:30-07:00:00.00000", - "2021-08-19T17:30-07:00:00.000001", - "2021-08-19T17:30-07:00:00.000000", - "2021-08-19T17:30-07:00:00.0000001", - "2021-08-19T17:30-07:00:00.0000000", - "2021-08-19T17:30-07:00:00.00000001", - "2021-08-19T17:30-07:00:00.00000000", - "2021-08-19T17:30-07:00:00.000000001", - "2021-08-19T17:30-07:00:00.000000000", -].forEach((timeZone) => { - assert.throws( - RangeError, - () => instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), - `ISO string ${timeZone} with a sub-minute offset is not a valid time zone` - ); -}); - -// The following are all valid strings so should not throw: - -[ - "2021-08-19T17:30Z", - "2021-08-19T1730Z", - "2021-08-19T17:30-07:00", - "2021-08-19T1730-07:00", - "2021-08-19T17:30-0700", - "2021-08-19T1730-0700", - "2021-08-19T17:30[UTC]", - "2021-08-19T1730[UTC]", - "2021-08-19T17:30Z[UTC]", - "2021-08-19T1730Z[UTC]", - "2021-08-19T17:30-07:00[UTC]", - "2021-08-19T1730-07:00[UTC]", - "2021-08-19T17:30-0700[UTC]", - "2021-08-19T1730-0700[UTC]", -].forEach((timeZone) => { - instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string-leap-second.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string-leap-second.js deleted file mode 100644 index 088075a80cc..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string-leap-second.js +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (C) 2022 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: Leap second is a valid ISO string for TimeZone -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1); -let timeZone = "2016-12-31T23:59:60+00:00[UTC]"; - -// A string with a leap second is a valid ISO string, so the following -// operation should not throw - -instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); - -timeZone = "2021-08-19T17:30:45.123456789+23:59[+23:59:60]"; -assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), "leap second in time zone name not valid"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string-year-zero.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string-year-zero.js deleted file mode 100644 index 7e7830a2e00..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string-year-zero.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2022 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: Negative zero, as an extended year, is rejected -features: [Temporal, arrow-function] ----*/ - -const invalidStrings = [ - "-000000-10-31T17:45Z", - "-000000-10-31T17:45+00:00[UTC]", -]; -const instance = new Temporal.Duration(1); -invalidStrings.forEach((timeZone) => { - assert.throws( - RangeError, - () => instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), - "reject minus zero as extended year" - ); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string.js deleted file mode 100644 index c05acabb357..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-string.js +++ /dev/null @@ -1,37 +0,0 @@ -// Copyright (C) 2022 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: Time zone IDs are valid input for a time zone -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const getPossibleInstantsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getPossibleInstantsFor"); -Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", { - configurable: true, - enumerable: false, - get() { - TemporalHelpers.assertUnreachable("getPossibleInstantsFor should not be looked up"); - }, -}); -const getOffsetNanosecondsForOriginal = Object.getOwnPropertyDescriptor(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor"); -Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", { - configurable: true, - enumerable: false, - get() { - TemporalHelpers.assertUnreachable("getOffsetNanosecondsFor should not be looked up"); - }, -}); - -const instance = new Temporal.Duration(1); - -// The following are all valid strings so should not throw: - -["UTC", "+01:00"].forEach((timeZone) => { - instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }); -}); - -Object.defineProperty(Temporal.TimeZone.prototype, "getPossibleInstantsFor", getPossibleInstantsForOriginal); -Object.defineProperty(Temporal.TimeZone.prototype, "getOffsetNanosecondsFor", getOffsetNanosecondsForOriginal); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-wrong-type.js deleted file mode 100644 index 53eb7876073..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-propertybag-timezone-wrong-type.js +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (C) 2022 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: > - Appropriate error thrown when argument cannot be converted to a valid string - or object for TimeZone -features: [BigInt, Symbol, Temporal] ----*/ - -const instance = new Temporal.Duration(1); - -const primitiveTests = [ - [null, "null"], - [true, "boolean"], - ["", "empty string"], - [1, "number that doesn't convert to a valid ISO string"], - [19761118, "number that would convert to a valid ISO string in other contexts"], - [1n, "bigint"], -]; - -for (const [timeZone, description] of primitiveTests) { - assert.throws( - typeof timeZone === 'string' ? RangeError : TypeError, - () => instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), - `${description} does not convert to a valid ISO string` - ); -} - -const typeErrorTests = [ - [Symbol(), "symbol"], - [{}, "object not implementing time zone protocol"], - [new Temporal.Calendar("iso8601"), "calendar instance"], -]; - -for (const [timeZone, description] of typeErrorTests) { - assert.throws(TypeError, () => instance.subtract(new Temporal.Duration(1), { relativeTo: { year: 2000, month: 5, day: 2, timeZone } }), `${description} is not a valid object and does not convert to a string`); -} diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-required.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-required.js deleted file mode 100644 index 893a9e11f52..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-required.js +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright (C) 2022 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: relativeTo is required if the largest unit is at least weeks. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const d = Temporal.Duration.from({ hours: 1 }); -const dy = Temporal.Duration.from({ years: 1, hours: 1 }); -const dm = Temporal.Duration.from({ months: 1, hours: 1 }); -const dw = Temporal.Duration.from({ weeks: 1, hours: 1 }); -assert.throws(RangeError, () => d.subtract(dy)); -assert.throws(RangeError, () => d.subtract(dm)); -assert.throws(RangeError, () => d.subtract(dw)); -assert.throws(RangeError, () => dy.subtract(d)); -assert.throws(RangeError, () => dm.subtract(d)); -assert.throws(RangeError, () => dw.subtract(d)); -const relativeTo = Temporal.PlainDate.from("2000-01-01"); -TemporalHelpers.assertDuration(d.subtract(dy, { relativeTo }), - -1, 0, 0, 0, 0, 0, 0, 0, 0, 0); -TemporalHelpers.assertDuration(d.subtract(dm, { relativeTo }), - 0, -1, 0, 0, 0, 0, 0, 0, 0, 0); -TemporalHelpers.assertDuration(d.subtract(dw, { relativeTo }), - 0, 0, -1, 0, 0, 0, 0, 0, 0, 0); -TemporalHelpers.assertDuration(dy.subtract(d, { relativeTo }), - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0); -TemporalHelpers.assertDuration(dm.subtract(d, { relativeTo }), - 0, 1, 0, 0, 0, 0, 0, 0, 0, 0); -TemporalHelpers.assertDuration(dw.subtract(d, { relativeTo }), - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-datetime.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-datetime.js deleted file mode 100644 index e31b31722ca..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-datetime.js +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (C) 2021 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: > - Conversion of ISO date-time strings as relativeTo option to - Temporal.ZonedDateTime or Temporal.PlainDateTime instances -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let relativeTo = "2019-11-01T00:00"; -const result1 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "bare date-time string is a plain relativeTo"); - -relativeTo = "2019-11-01T00:00-07:00"; -const result2 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result2, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + offset is a plain relativeTo"); - -relativeTo = "2019-11-01T00:00[-07:00]"; -const result3 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo"); - -relativeTo = "2019-11-01T00:00Z[-07:00]"; -const result4 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result4, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo"); - -relativeTo = "2019-11-01T00:00+00:00[UTC]"; -const result5 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result5, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo"); - -relativeTo = "2019-11-01T00:00Z"; -assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), "date-time + Z throws without an IANA annotation"); -relativeTo = "2019-11-01T00:00+04:15[UTC]"; -assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-invalid.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-invalid.js deleted file mode 100644 index 5bf459366c7..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-invalid.js +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright (C) 2021 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: RangeError thrown if relativeTo is a string with the wrong format -features: [Temporal] ----*/ - -['bad string', '15:30:45.123456', 'iso8601', 'UTC', 'P1YT1H'].forEach((relativeTo) => { - const duration = new Temporal.Duration(1, 0, 0, 41); - assert.throws(RangeError, () => duration.subtract(new Temporal.Duration(0, 0, 0, 10), { relativeTo })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-plaindatetime.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-plaindatetime.js deleted file mode 100644 index 4fe06e34ec5..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-plaindatetime.js +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright (C) 2021 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: The relativeTo option accepts a PlainDateTime-like ISO 8601 string -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -['2000-01-01', '2000-01-01T00:00', '2000-01-01T00:00[u-ca=iso8601]'].forEach((relativeTo) => { - const duration = new Temporal.Duration(1, 0, 0, 41); - const result = duration.subtract(new Temporal.Duration(0, 0, 0, 10), { relativeTo }); - TemporalHelpers.assertDuration(result, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-zoneddatetime-wrong-offset.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-zoneddatetime-wrong-offset.js deleted file mode 100644 index 148723fd2bd..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-zoneddatetime-wrong-offset.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2021 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 if a ZonedDateTime-like relativeTo string has the wrong UTC offset -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); -const relativeTo = "2000-01-01T00:00+05:30[UTC]"; -assert.throws( - RangeError, - () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), - "subtract should throw RangeError on a string with UTC offset mismatch" -); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-zoneddatetime.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-zoneddatetime.js deleted file mode 100644 index db33ebf528c..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-string-zoneddatetime.js +++ /dev/null @@ -1,20 +0,0 @@ -// Copyright (C) 2021 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: The relativeTo option accepts a ZonedDateTime-like ISO 8601 string -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[ - '2000-01-01[UTC]', - '2000-01-01T00:00[UTC]', - '2000-01-01T00:00+00:00[UTC]', - '2000-01-01T00:00+00:00[UTC][u-ca=iso8601]', -].forEach((relativeTo) => { - const duration = new Temporal.Duration(1, 0, 0, 41); - const result = duration.subtract(new Temporal.Duration(0, 0, 0, 10), { relativeTo }); - TemporalHelpers.assertDuration(result, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-sub-minute-offset.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-sub-minute-offset.js deleted file mode 100644 index a84801e02c7..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-sub-minute-offset.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2021 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: relativeTo string accepts trailing zeroes in sub-minute UTC offset -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let result; -let relativeTo; -const action = (relativeTo) => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); - -relativeTo = "1970-01-01T00:00-00:45:00[-00:45]"; -result = action(relativeTo); -TemporalHelpers.assertDateDuration(result, 1, 0, 0, 0, "ISO string offset accepted with zero seconds (string)"); - -relativeTo = { year: 1970, month: 1, day: 1, offset: "+00:45:00.000000000", timeZone: "+00:45" }; -result = action(relativeTo); -TemporalHelpers.assertDateDuration(result, 1, 0, 0, 0, "ISO string offset accepted with zero seconds (property bag)"); - -relativeTo = "1970-01-01T00:00+00:44:30.123456789[+00:45]"; -assert.throws(RangeError, () => action(relativeTo), "rounding is not accepted between ISO offset and time zone"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-wrong-type.js deleted file mode 100644 index 343fe7b182a..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-wrong-type.js +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (C) 2022 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: > - Appropriate error thrown when relativeTo cannot be converted to a valid - relativeTo string or property bag -features: [BigInt, Symbol, Temporal] ----*/ - -const timeZone = new Temporal.TimeZone('UTC'); -const instance = new Temporal.Duration(1, 0, 0, 1); - -const primitiveTests = [ - [undefined, 'undefined'], - [null, 'null'], - [true, 'boolean'], - ['', 'empty string'], - [1, "number that doesn't convert to a valid ISO string"], - [1n, 'bigint'] -]; - -for (const [relativeTo, description] of primitiveTests) { - assert.throws( - typeof relativeTo === 'string' || typeof relativeTo === 'undefined' ? RangeError : TypeError, - () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), - `${description} does not convert to a valid ISO string (first argument)` - ); -} - -const typeErrorTests = [ - [Symbol(), 'symbol'], - [{}, 'plain object'], - [Temporal.PlainDate, 'Temporal.PlainDate, object'], - [Temporal.PlainDate.prototype, 'Temporal.PlainDate.prototype, object'], - [Temporal.ZonedDateTime, 'Temporal.ZonedDateTime, object'], - [Temporal.ZonedDateTime.prototype, 'Temporal.ZonedDateTime.prototype, object'] -]; - -for (const [relativeTo, description] of typeErrorTests) { - assert.throws( - TypeError, - () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), - `${description} is not a valid property bag and does not convert to a string` - ); -} diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-year.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-year.js deleted file mode 100644 index 86a4090f932..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-year.js +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright (C) 2022 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: relativeTo with years. -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const oneYear = new Temporal.Duration(1); -const days365 = new Temporal.Duration(0, 0, 0, 365); -TemporalHelpers.assertDuration(oneYear.subtract(days365, { relativeTo: Temporal.PlainDate.from("2017-01-01") }), - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "non-leap year"); -TemporalHelpers.assertDuration(oneYear.subtract(days365, { relativeTo: Temporal.PlainDate.from("2016-01-01") }), - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, "leap year"); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-negative-epochnanoseconds.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-negative-epochnanoseconds.js deleted file mode 100644 index d607013e3e7..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-negative-epochnanoseconds.js +++ /dev/null @@ -1,24 +0,0 @@ -// Copyright (C) 2021 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: A pre-epoch value is handled correctly by the modulo operation in GetISOPartsFromEpoch -info: | - sec-temporal-getisopartsfromepoch step 1: - 1. Let _remainderNs_ be the mathematical value whose sign is the sign of _epochNanoseconds_ and whose magnitude is abs(_epochNanoseconds_) modulo 106. - sec-temporal-builtintimezonegetplaindatetimefor step 2: - 2. Let _result_ be ! GetISOPartsFromEpoch(_instant_.[[Nanoseconds]]). -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -const relativeTo = new Temporal.ZonedDateTime(-13849764_999_999_999n, "UTC"); -const duration = new Temporal.Duration(0, 0, 0, 1); - -// This code path shows up anywhere we convert an exact time, before the Unix -// epoch, with nonzero microseconds or nanoseconds, into a wall time; in this -// case via relativeTo. - -const result = duration.subtract(duration, { relativeTo }); -TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js deleted file mode 100644 index b7eda21c405..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-non-integer.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2021 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: RangeError thrown if time zone reports an offset that is not an integer number of nanoseconds -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[3600_000_000_000.5, NaN, -Infinity, Infinity].forEach((wrongOffset) => { - const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(0, 3); - const relativeTo = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone); - assert.throws(RangeError, () => duration.subtract(other, { relativeTo })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js deleted file mode 100644 index 7f066c36cca..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-not-callable.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2021 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: TypeError thrown if timeZone.getOffsetNanosecondsFor is not callable -features: [BigInt, Symbol, Temporal, arrow-function] ----*/ - -[undefined, null, true, Math.PI, 'string', Symbol('sym'), 42n, {}].forEach((notCallable) => { - const timeZone = new Temporal.TimeZone("UTC"); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(0, 3); - const relativeTo = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone); - timeZone.getOffsetNanosecondsFor = notCallable; - assert.throws( - TypeError, - () => duration.subtract(other, { relativeTo }), - `Uncallable ${notCallable === null ? 'null' : typeof notCallable} getOffsetNanosecondsFor should throw TypeError` - ); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js deleted file mode 100644 index 7a707aef3f3..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-out-of-range.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2021 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: RangeError thrown if time zone reports an offset that is out of range -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[-86400_000_000_000, 86400_000_000_000].forEach((wrongOffset) => { - const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(0, 3); - const relativeTo = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone); - assert.throws(RangeError, () => duration.subtract(other, { relativeTo })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js b/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js deleted file mode 100644 index 1e8b18f5097..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/relativeto-zoneddatetime-timezone-getoffsetnanosecondsfor-wrong-type.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2021 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: TypeError thrown if time zone reports an offset that is not a Number -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -[ - undefined, - null, - true, - "+01:00", - Symbol(), - 3600_000_000_000n, - {}, - { valueOf() { return 3600_000_000_000; } }, -].forEach((wrongOffset) => { - const timeZone = TemporalHelpers.specificOffsetTimeZone(wrongOffset); - const duration = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); - const other = new Temporal.Duration(0, 3); - const relativeTo = new Temporal.ZonedDateTime(1_000_000_000_987_654_321n, timeZone); - assert.throws(TypeError, () => duration.subtract(other, { relativeTo })); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/result-out-of-range-1.js b/test/built-ins/Temporal/Duration/prototype/subtract/result-out-of-range-1.js index 4e47a95caee..94183057605 100644 --- a/test/built-ins/Temporal/Duration/prototype/subtract/result-out-of-range-1.js +++ b/test/built-ins/Temporal/Duration/prototype/subtract/result-out-of-range-1.js @@ -8,9 +8,6 @@ description: > features: [Temporal] ---*/ -const plainDate = new Temporal.PlainDate(1970, 1, 1); -const zonedDateTime = new Temporal.ZonedDateTime(0n, "UTC", "iso8601"); - // Largest temporal unit is "second". const duration1 = Temporal.Duration.from({seconds: Number.MAX_SAFE_INTEGER}); const duration2 = Temporal.Duration.from({seconds: -Number.MAX_SAFE_INTEGER}); @@ -18,11 +15,3 @@ const duration2 = Temporal.Duration.from({seconds: -Number.MAX_SAFE_INTEGER}); assert.throws(RangeError, () => { duration1.subtract(duration2); }); - -assert.throws(RangeError, () => { - duration1.subtract(duration2, {relativeTo: plainDate}); -}); - -assert.throws(RangeError, () => { - duration1.subtract(duration2, {relativeTo: zonedDateTime}); -}); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/timezone-getpossibleinstantsfor-iterable.js b/test/built-ins/Temporal/Duration/prototype/subtract/timezone-getpossibleinstantsfor-iterable.js deleted file mode 100644 index 1ed510486c5..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/timezone-getpossibleinstantsfor-iterable.js +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (C) 2021 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: An iterable returned from timeZone.getPossibleInstantsFor is consumed after each call -info: | - sec-temporal.duration.prototype.subtract steps 5–6: - 5. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_). - 6. Let _result_ be ? AddDuration(_duration_.[[Years]], [...], _duration_.[[Nanoseconds]], −_other_.[[Years]], [...], −_other_.[[Nanoseconds]], _relativeTo_). - sec-temporal-torelativetemporalobject step 6.d: - d. Let _epochNanoseconds_ be ? InterpretISODateTimeOffset(_result_.[[Year]], [...], _result_.[[Nanosecond]], _offsetNs_, _timeZone_, *"compatible"*, *"reject"*). - sec-temporal-interpretisodatetimeoffset step 7: - 7. Let _possibleInstants_ be ? GetPossibleInstantsFor(_timeZone_, _dateTime_). - sec-temporal-addduration steps 7.d–e and 7.g.i: - d. Let _intermediateNs_ be ? AddZonedDateTime(_relativeTo_.[[Nanoseconds]], _timeZone_, _calendar_, _y1_, [...], _ns1_). - e. Let _endNs_ be ? AddZonedDateTime(_intermediateNs_, _timeZone_, _calendar_, _y2_, [...], _ns2_). - [...] - i. Let _result_ be ? DifferenceZonedDateTime(_relativeTo_.[[Nanoseconds]], _endNs_, _timeZone_, _calendar_, _largestUnit_). - sec-temporal-differencezoneddatetime step 8: - 8. Let _intermediateNs_ be ? AddZonedDateTime(_ns1_, _timeZone_, _calendar_, _dateDifference_.[[Years]], _dateDifference_.[[Months]], _dateDifference_.[[Weeks]], 0, 0, 0, 0, 0, 0, 0). - sec-temporal-addzoneddatetime step 8: - 8. Let _intermediateInstant_ be ? BuiltinTimeZoneGetInstantFor(_timeZone_, _intermediateDateTime_, *"compatible"*). - sec-temporal-builtintimezonegetinstantfor step 1: - 1. Let _possibleInstants_ be ? GetPossibleInstantsFor(_timeZone_, _dateTime_). - sec-temporal-getpossibleinstantsfor step 2: - 2. Let _list_ be ? IterableToList(_possibleInstants_). -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const expected = [ - "2000-01-01T09:00:00", // called once on the input relativeTo object - "2001-01-01T09:00:00", // called once on relativeTo plus the receiver - "1999-12-01T09:00:00", // called once on relativeTo plus the receiver minus the argument - "1999-12-01T09:00:00", // called once on relativeTo plus the years, months, and weeks from the difference of relativeTo minus endNs -]; - -TemporalHelpers.checkTimeZonePossibleInstantsIterable((timeZone) => { - const duration1 = new Temporal.Duration(1); - const duration2 = new Temporal.Duration(0, 13); - duration1.subtract(duration2, { relativeTo: { year: 2000, month: 1, day: 1, hour: 9, timeZone } }); -}, expected); diff --git a/test/built-ins/Temporal/Duration/prototype/subtract/year-zero.js b/test/built-ins/Temporal/Duration/prototype/subtract/year-zero.js deleted file mode 100644 index bee08e7a148..00000000000 --- a/test/built-ins/Temporal/Duration/prototype/subtract/year-zero.js +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright (C) 2022 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: Negative zero, as an extended year, is rejected -features: [Temporal, arrow-function] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let relativeTo = "-000000-11-04T00:00"; -assert.throws( - RangeError, - () => { instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); }, - "reject minus zero as extended year" -); diff --git a/test/intl402/Temporal/Duration/prototype/add/relativeto-infinity-throws-rangeerror.js b/test/intl402/Temporal/Duration/prototype/add/relativeto-infinity-throws-rangeerror.js deleted file mode 100644 index d2b0b866cef..00000000000 --- a/test/intl402/Temporal/Duration/prototype/add/relativeto-infinity-throws-rangeerror.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Throws if eraYear in the property bag is Infinity or -Infinity -esid: sec-temporal.duration.prototype.add -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); -const base = { era: "ad", month: 5, day: 2, hour: 15, calendar: "gregory" }; - -[Infinity, -Infinity].forEach((inf) => { - assert.throws(RangeError, () => instance.add(instance, { relativeTo: { ...base, eraYear: inf } }), `eraYear property cannot be ${inf} in relativeTo`); - - const calls = []; - const obj = TemporalHelpers.toPrimitiveObserver(calls, inf, "eraYear"); - assert.throws(RangeError, () => instance.add(instance, { relativeTo: { ...base, eraYear: obj } })); - assert.compareArray(calls, ["get eraYear.valueOf", "call eraYear.valueOf"], "it fails after fetching the primitive value"); -}); diff --git a/test/intl402/Temporal/Duration/prototype/add/relativeto-string-datetime.js b/test/intl402/Temporal/Duration/prototype/add/relativeto-string-datetime.js deleted file mode 100644 index 37eb146e7ba..00000000000 --- a/test/intl402/Temporal/Duration/prototype/add/relativeto-string-datetime.js +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: > - Conversion of ISO date-time strings as relativeTo option to - Temporal.ZonedDateTime or Temporal.PlainDateTime instances -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let relativeTo = "2019-11-01T00:00[America/Vancouver]"; -const result4 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result4, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo"); - -relativeTo = "2019-11-01T00:00Z[America/Vancouver]"; -const result5 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result5, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo"); - -relativeTo = "2019-11-01T00:00-07:00[America/Vancouver]"; -const result6 = instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); -TemporalHelpers.assertDuration(result6, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo"); - -relativeTo = "2019-11-01T00:00+04:15[America/Vancouver]"; -assert.throws(RangeError, () => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch"); diff --git a/test/intl402/Temporal/Duration/prototype/add/relativeto-sub-minute-offset.js b/test/intl402/Temporal/Duration/prototype/add/relativeto-sub-minute-offset.js deleted file mode 100644 index f34fb1e43c0..00000000000 --- a/test/intl402/Temporal/Duration/prototype/add/relativeto-sub-minute-offset.js +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.duration.prototype.add -description: relativeTo string accepts an inexact UTC offset rounded to hours and minutes -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); -let result; -let relativeTo; -const action = (relativeTo) => instance.add(new Temporal.Duration(0, 0, 0, 0, -24), { relativeTo }); - -relativeTo = "1970-01-01T00:00-00:45:00[-00:45]"; -result = action(relativeTo); -TemporalHelpers.assertDateDuration(result, 1, 0, 0, 0, "ISO string offset accepted with zero seconds (string)"); - -relativeTo = { year: 1970, month: 1, day: 1, offset: "+00:45:00.000000000", timeZone: "+00:45" }; -result = action(relativeTo); -TemporalHelpers.assertDateDuration(result, 1, 0, 0, 0, "ISO string offset accepted with zero seconds (property bag)"); - -relativeTo = "1970-01-01T00:00+00:44:30.123456789[+00:45]"; -assert.throws(RangeError, () => action(relativeTo), "rounding is not accepted between ISO offset and time zone"); diff --git a/test/intl402/Temporal/Duration/prototype/subtract/relativeto-infinity-throws-rangeerror.js b/test/intl402/Temporal/Duration/prototype/subtract/relativeto-infinity-throws-rangeerror.js deleted file mode 100644 index 75d223b85ed..00000000000 --- a/test/intl402/Temporal/Duration/prototype/subtract/relativeto-infinity-throws-rangeerror.js +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright (C) 2021 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -description: Throws if eraYear in the property bag is Infinity or -Infinity -esid: sec-temporal.duration.prototype.subtract -includes: [compareArray.js, temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 2, 3, 4, 5, 6, 7, 987, 654, 321); -const base = { era: "ad", month: 5, day: 2, hour: 15, calendar: "gregory" }; - -[Infinity, -Infinity].forEach((inf) => { - assert.throws(RangeError, () => instance.subtract(instance, { relativeTo: { ...base, eraYear: inf } }), `eraYear property cannot be ${inf} in relativeTo`); - - const calls = []; - const obj = TemporalHelpers.toPrimitiveObserver(calls, inf, "eraYear"); - assert.throws(RangeError, () => instance.subtract(instance, { relativeTo: { ...base, eraYear: obj } })); - assert.compareArray(calls, ["get eraYear.valueOf", "call eraYear.valueOf"], "it fails after fetching the primitive value"); -}); diff --git a/test/intl402/Temporal/Duration/prototype/subtract/relativeto-string-datetime.js b/test/intl402/Temporal/Duration/prototype/subtract/relativeto-string-datetime.js deleted file mode 100644 index 5c79dfd9ec6..00000000000 --- a/test/intl402/Temporal/Duration/prototype/subtract/relativeto-string-datetime.js +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (C) 2022 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: > - Conversion of ISO date-time strings as relativeTo option to - Temporal.ZonedDateTime or Temporal.PlainDateTime instances -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let relativeTo = "2019-11-01T00:00[America/Vancouver]"; -const result4 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result4, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, "date-time + IANA annotation is a zoned relativeTo"); - -relativeTo = "2019-11-01T00:00Z[America/Vancouver]"; -const result5 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result5, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, "date-time + Z + IANA annotation is a zoned relativeTo"); - -relativeTo = "2019-11-01T00:00-07:00[America/Vancouver]"; -const result6 = instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); -TemporalHelpers.assertDuration(result6, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, "date-time + offset + IANA annotation is a zoned relativeTo"); - -relativeTo = "2019-11-01T00:00+04:15[America/Vancouver]"; -assert.throws(RangeError, () => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }), "date-time + offset + IANA annotation throws if wall time and exact time mismatch"); diff --git a/test/intl402/Temporal/Duration/prototype/subtract/relativeto-sub-minute-offset.js b/test/intl402/Temporal/Duration/prototype/subtract/relativeto-sub-minute-offset.js deleted file mode 100644 index f8420e487b8..00000000000 --- a/test/intl402/Temporal/Duration/prototype/subtract/relativeto-sub-minute-offset.js +++ /dev/null @@ -1,26 +0,0 @@ -// Copyright (C) 2021 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: relativeTo string accepts an inexact UTC offset rounded to hours and minutes -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -const instance = new Temporal.Duration(1, 0, 0, 1); - -let result; -let relativeTo; -const action = (relativeTo) => instance.subtract(new Temporal.Duration(0, 0, 0, 0, 24), { relativeTo }); - -relativeTo = "1970-01-01T00:00-00:45:00[-00:45]"; -result = action(relativeTo); -TemporalHelpers.assertDateDuration(result, 1, 0, 0, 0, "ISO string offset accepted with zero seconds (string)"); - -relativeTo = { year: 1970, month: 1, day: 1, offset: "+00:45:00.000000000", timeZone: "+00:45" }; -result = action(relativeTo); -TemporalHelpers.assertDateDuration(result, 1, 0, 0, 0, "ISO string offset accepted with zero seconds (property bag)"); - -relativeTo = "1970-01-01T00:00+00:44:30.123456789[+00:45]"; -assert.throws(RangeError, () => action(relativeTo), "rounding is not accepted between ISO offset and time zone"); diff --git a/test/staging/Intl402/Temporal/old/duration-arithmetic-dst.js b/test/staging/Intl402/Temporal/old/duration-arithmetic-dst.js index 80fcdd4f2dc..c511a936a4d 100644 --- a/test/staging/Intl402/Temporal/old/duration-arithmetic-dst.js +++ b/test/staging/Intl402/Temporal/old/duration-arithmetic-dst.js @@ -20,18 +20,7 @@ var skippedHourDay = Temporal.ZonedDateTime.from("2019-03-10T00:00[America/Vanco var repeatedHourDay = Temporal.ZonedDateTime.from("2019-11-03T00:00[America/Vancouver]"); var inRepeatedHour = Temporal.ZonedDateTime.from("2019-11-03T01:00-07:00[America/Vancouver]"); -// subtract() - var oneDay = new Temporal.Duration(0, 0, 0, 1); -assert.sameValue(`${ Temporal.Duration.from({ - days: 127, - hours: 1 -}).subtract(oneDay, { relativeTo: inRepeatedHour }) }`, "P126DT1H"); -var hours24 = new Temporal.Duration(0, 0, 0, 0, 24); -assert.sameValue(`${ Temporal.Duration.from({ - days: 127, - hours: 1 -}).subtract(hours24, { relativeTo: inRepeatedHour }) }`, "P126D"); // total() var totalDays = Temporal.Duration.from({ @@ -54,19 +43,11 @@ assert.sameValue(Temporal.Duration.from({ // Without a TZDB, it's not possible to get a ZonedDateTime with DST from a // string. -assert.sameValue( - `${ oneDay.add(hours24, { relativeTo: "2019-11-02T00:00[America/Vancouver]" }) }`, - "P1DT24H" -); var hours25 = new Temporal.Duration(0, 0, 0, 0, 25); assert.sameValue(`${ hours25.round({ largestUnit: "days", relativeTo: "2019-11-03T00:00[America/Vancouver]" }) }`, "P1D"); -assert.sameValue( - `${ oneDay.subtract(hours24, { relativeTo: "2019-11-03T00:00[America/Vancouver]" }) }`, - "PT1H" -); assert.sameValue(oneDay.total({ unit: "hours", relativeTo: "2019-11-03T00:00[America/Vancouver]" diff --git a/test/staging/Temporal/Duration/old/add.js b/test/staging/Temporal/Duration/old/add.js deleted file mode 100644 index 52075623d61..00000000000 --- a/test/staging/Temporal/Duration/old/add.js +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (C) 2018 Bloomberg LP. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal-duration-objects -description: Temporal.Duration.prototype.add() works as expected -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -var oneDay = new Temporal.Duration(0, 0, 0, 1); -var hours24 = new Temporal.Duration(0, 0, 0, 0, 24); - -// relativeTo does not affect days if PlainDate -var relativeTo = Temporal.PlainDate.from("2017-01-01"); -assert.sameValue(`${ oneDay.add(hours24, { relativeTo }) }`, "P2D"); - -// relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change -var relativeTo = Temporal.ZonedDateTime.from("2017-01-01T00:00[+04:30]"); -assert.sameValue(`${ oneDay.add(hours24, { relativeTo }) }`, "P2D"); - -// relativeTo affects days if ZonedDateTime, and duration encompasses DST change -var timeZone = TemporalHelpers.springForwardFallBackTimeZone(); -var skippedHourDay = Temporal.PlainDateTime.from("2000-04-02").toZonedDateTime(timeZone); -var repeatedHourDay = Temporal.PlainDateTime.from("2000-10-29").toZonedDateTime(timeZone); -var inRepeatedHour = new Temporal.ZonedDateTime(972806400_000_000_000n, timeZone); -var hours12 = new Temporal.Duration(0, 0, 0, 0, 12); -var hours25 = new Temporal.Duration(0, 0, 0, 0, 25); - -// start inside repeated hour, end after -assert.sameValue(`${ hours25.add(oneDay, { relativeTo: inRepeatedHour }) }`, "P2D"); -assert.sameValue(`${ oneDay.add(hours25, { relativeTo: inRepeatedHour }) }`, "P2DT1H"); - -// start after repeated hour, end inside (negative) -var relativeTo = Temporal.PlainDateTime.from("2000-10-31T01:00").toZonedDateTime(timeZone); -assert.sameValue(`${ hours25.negated().add(oneDay.negated(), { relativeTo }) }`, "-P2DT1H"); -assert.sameValue(`${ oneDay.negated().add(hours25.negated(), { relativeTo }) }`, "-P2D"); - -// start inside repeated hour, end in skipped hour -assert.sameValue(`${ hours25.add(Temporal.Duration.from({ - days: 125, - hours: 1 -}), { relativeTo: inRepeatedHour }) }`, "P126DT1H"); -assert.sameValue(`${ oneDay.add(Temporal.Duration.from({ - days: 125, - hours: 1 -}), { relativeTo: inRepeatedHour }) }`, "P126DT1H"); - -// start in normal hour, end in skipped hour -var relativeTo = Temporal.PlainDateTime.from("2000-03-31T02:30").toZonedDateTime(timeZone); -assert.sameValue(`${ oneDay.add(hours25, { relativeTo }) }`, "P2DT1H"); -assert.sameValue(`${ hours25.add(oneDay, { relativeTo }) }`, "P2D"); - -// start before skipped hour, end >1 day after -assert.sameValue(`${ hours25.add(oneDay, { relativeTo: skippedHourDay }) }`, "P2DT2H"); -assert.sameValue(`${ oneDay.add(hours25, { relativeTo: skippedHourDay }) }`, "P2DT1H"); - -// start after skipped hour, end >1 day before (negative) -var relativeTo = Temporal.PlainDateTime.from("2000-04-03T00:00").toZonedDateTime(timeZone); -assert.sameValue(`${ hours25.negated().add(oneDay.negated(), { relativeTo }) }`, "-P2DT2H"); -assert.sameValue(`${ oneDay.negated().add(hours25.negated(), { relativeTo }) }`, "-P2DT1H"); - -// start before skipped hour, end <1 day after -assert.sameValue(`${ hours12.add(oneDay, { relativeTo: skippedHourDay }) }`, "P1DT13H"); -assert.sameValue(`${ oneDay.add(hours12, { relativeTo: skippedHourDay }) }`, "P1DT12H"); - -// start after skipped hour, end <1 day before (negative) -var relativeTo = Temporal.PlainDateTime.from("2000-04-02T12:00").toZonedDateTime(timeZone); -assert.sameValue(`${ hours12.negated().add(oneDay.negated(), { relativeTo }) }`, "-P1DT13H"); -assert.sameValue(`${ oneDay.negated().add(hours12.negated(), { relativeTo }) }`, "-P1DT12H"); - -// start before repeated hour, end >1 day after -assert.sameValue(`${ hours25.add(oneDay, { relativeTo: repeatedHourDay }) }`, "P2D"); -assert.sameValue(`${ oneDay.add(hours25, { relativeTo: repeatedHourDay }) }`, "P2DT1H"); - -// start after repeated hour, end >1 day before (negative) -var relativeTo = Temporal.PlainDateTime.from("2000-10-30T00:00").toZonedDateTime(timeZone); -assert.sameValue(`${ hours25.negated().add(oneDay.negated(), { relativeTo }) }`, "-P2D"); -assert.sameValue(`${ oneDay.negated().add(hours25.negated(), { relativeTo }) }`, "-P2DT1H"); - -// start before repeated hour, end <1 day after -assert.sameValue(`${ hours12.add(oneDay, { relativeTo: repeatedHourDay }) }`, "P1DT11H"); -assert.sameValue(`${ oneDay.add(hours12, { relativeTo: repeatedHourDay }) }`, "P1DT12H"); - -// start after repeated hour, end <1 day before (negative) -var relativeTo = Temporal.PlainDateTime.from("2000-10-29T12:00").toZonedDateTime(timeZone); -assert.sameValue(`${ hours12.negated().add(oneDay.negated(), { relativeTo }) }`, "-P1DT11H"); -assert.sameValue(`${ oneDay.negated().add(hours12.negated(), { relativeTo }) }`, "-P1DT12H"); - -// Samoa skipped 24 hours -var fakeSamoa = TemporalHelpers.crossDateLineTimeZone(); -var relativeTo = Temporal.PlainDateTime.from("2011-12-29T12:00").toZonedDateTime(fakeSamoa); -assert.sameValue(`${ hours25.add(oneDay, { relativeTo }) }`, "P3DT1H"); -assert.sameValue(`${ oneDay.add(hours25, { relativeTo }) }`, "P3DT1H"); - -// casts relativeTo to ZonedDateTime if possible -assert.sameValue(`${ oneDay.add(hours24, { - relativeTo: { - year: 2000, - month: 10, - day: 28, - timeZone - } -}) }`, "P1DT24H"); - -// casts relativeTo to PlainDate if possible -assert.sameValue(`${ oneDay.add(hours24, { relativeTo: "2019-11-02" }) }`, "P2D"); -assert.sameValue(`${ oneDay.add(hours24, { - relativeTo: { - year: 2019, - month: 11, - day: 2 - } -}) }`, "P2D"); - -// throws on wrong offset for ZonedDateTime relativeTo string -assert.throws(RangeError, () => oneDay.add(hours24, { relativeTo: "1971-01-01T00:00+02:00[-00:44:30]" })); - -// at least the required properties must be present in relativeTo -assert.throws(TypeError, () => oneDay.add(hours24, { - relativeTo: { - month: 11, - day: 3 - } -})); -assert.throws(TypeError, () => oneDay.add(hours24, { - relativeTo: { - year: 2019, - month: 11 - } -})); -assert.throws(TypeError, () => oneDay.add(hours24, { - relativeTo: { - year: 2019, - day: 3 - } -})); diff --git a/test/staging/Temporal/Duration/old/subtract.js b/test/staging/Temporal/Duration/old/subtract.js deleted file mode 100644 index 776038ca7fb..00000000000 --- a/test/staging/Temporal/Duration/old/subtract.js +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright (C) 2018 Bloomberg LP. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal-duration-objects -description: Temporal.Duration.prototype.subtract() works as expected -includes: [temporalHelpers.js] -features: [Temporal] ----*/ - -var oneDay = new Temporal.Duration(0, 0, 0, 1); -var hours24 = new Temporal.Duration(0, 0, 0, 0, 24); - -// relativeTo does not affect days if PlainDate -var relativeTo = Temporal.PlainDate.from("2017-01-01"); -assert.sameValue(`${ oneDay.subtract(hours24, { relativeTo }) }`, "PT0S"); - -// relativeTo does not affect days if ZonedDateTime, and duration encompasses no DST change -var relativeTo = Temporal.ZonedDateTime.from("2017-01-01T00:00[+04:30]"); -assert.sameValue(`${ oneDay.subtract(hours24, { relativeTo }) }`, "PT0S"); - -// relativeTo affects days if ZonedDateTime, and duration encompasses DST change -var timeZone = TemporalHelpers.springForwardFallBackTimeZone(); -var skippedHourDay = Temporal.PlainDateTime.from("2000-04-02").toZonedDateTime(timeZone); -var repeatedHourDay = Temporal.PlainDateTime.from("2000-10-29").toZonedDateTime(timeZone); -var inRepeatedHour = new Temporal.ZonedDateTime(972806400_000_000_000n, timeZone); -var twoDays = new Temporal.Duration(0, 0, 0, 2); -var threeDays = new Temporal.Duration(0, 0, 0, 3); - -// start inside repeated hour, end after -assert.sameValue(`${ hours24.subtract(oneDay, { relativeTo: inRepeatedHour }) }`, "-PT1H"); -assert.sameValue(`${ oneDay.subtract(hours24, { relativeTo: inRepeatedHour }) }`, "PT1H"); - -// start in normal hour, end in skipped hour -var relativeTo = Temporal.PlainDateTime.from("2000-04-01T02:30").toZonedDateTime(timeZone); -assert.sameValue(`${ hours24.subtract(oneDay, { relativeTo }) }`, "PT1H"); -assert.sameValue(`${ oneDay.subtract(hours24, { relativeTo }) }`, "PT0S"); - -// start before skipped hour, end >1 day after -assert.sameValue(`${ threeDays.subtract(hours24, { relativeTo: skippedHourDay }) }`, "P2D"); -assert.sameValue(`${ hours24.subtract(threeDays, { relativeTo: skippedHourDay }) }`, "-P1DT23H"); - -// start before skipped hour, end <1 day after -assert.sameValue(`${ twoDays.subtract(hours24, { relativeTo: skippedHourDay }) }`, "P1D"); -assert.sameValue(`${ hours24.subtract(twoDays, { relativeTo: skippedHourDay }) }`, "-PT23H"); - -// start before repeated hour, end >1 day after -assert.sameValue(`${ threeDays.subtract(hours24, { relativeTo: repeatedHourDay }) }`, "P2D"); -assert.sameValue(`${ hours24.subtract(threeDays, { relativeTo: repeatedHourDay }) }`, "-P2DT1H"); - -// start before repeated hour, end <1 day after -assert.sameValue(`${ twoDays.subtract(hours24, { relativeTo: repeatedHourDay }) }`, "P1D"); -assert.sameValue(`${ hours24.subtract(twoDays, { relativeTo: repeatedHourDay }) }`, "-P1DT1H"); - -// Samoa skipped 24 hours -var fakeSamoa = TemporalHelpers.crossDateLineTimeZone(); -var relativeTo = Temporal.PlainDateTime.from("2011-12-29T12:00").toZonedDateTime(fakeSamoa); -assert.sameValue(`${ twoDays.subtract(Temporal.Duration.from({ hours: 48 }), { relativeTo }) }`, "-P1D"); -assert.sameValue(`${ Temporal.Duration.from({ hours: 48 }).subtract(twoDays, { relativeTo }) }`, "P2D"); - -// casts relativeTo to ZonedDateTime if possible -assert.sameValue(`${ oneDay.subtract(hours24, { - relativeTo: { - year: 2000, - month: 10, - day: 29, - timeZone - } -}) }`, "PT1H"); - -// casts relativeTo to PlainDate if possible -assert.sameValue(`${ oneDay.subtract(hours24, { relativeTo: "2019-11-02" }) }`, "PT0S"); -assert.sameValue(`${ oneDay.subtract(hours24, { - relativeTo: { - year: 2019, - month: 11, - day: 2 - } -}) }`, "PT0S"); - -// throws on wrong offset for ZonedDateTime relativeTo string -assert.throws(RangeError, () => oneDay.subtract(hours24, { relativeTo: "1971-01-01T00:00+02:00[-00:44:30]" })); - -// at least the required properties must be present in relativeTo -assert.throws(TypeError, () => oneDay.subtract(hours24, { - relativeTo: { - month: 11, - day: 3 - } -})); -assert.throws(TypeError, () => oneDay.subtract(hours24, { - relativeTo: { - year: 2019, - month: 11 - } -})); -assert.throws(TypeError, () => oneDay.subtract(hours24, { - relativeTo: { - year: 2019, - day: 3 - } -}));