diff --git a/test/staging/Temporal/Instant/old/compare.js b/test/built-ins/Temporal/Instant/compare/cross-epoch.js similarity index 55% rename from test/staging/Temporal/Instant/old/compare.js rename to test/built-ins/Temporal/Instant/compare/cross-epoch.js index 2534bf6245..47522d2c59 100644 --- a/test/staging/Temporal/Instant/old/compare.js +++ b/test/built-ins/Temporal/Instant/compare/cross-epoch.js @@ -2,20 +2,20 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal-instant-objects -description: Temporal.Instant.compare works +esid: sec-temporal.instant.compare +description: Temporal.Instant.compare works cross-epoch. features: [Temporal] ---*/ -var i1 = Temporal.Instant.from("1963-02-13T09:36:29.123456789Z"); -var i2 = Temporal.Instant.from("1976-11-18T15:23:30.123456789Z"); -var i3 = Temporal.Instant.from("1981-12-15T14:34:31.987654321Z"); +const i1 = Temporal.Instant.from("1963-02-13T09:36:29.123456789Z"); +const i2 = Temporal.Instant.from("1976-11-18T15:23:30.123456789Z"); +const i3 = Temporal.Instant.from("1981-12-15T14:34:31.987654321Z"); // pre epoch equal -assert.sameValue(Temporal.Instant.compare(i1, Temporal.Instant.from(i1)), 0) +assert.sameValue(Temporal.Instant.compare(i1, i1), 0) // epoch equal -assert.sameValue(Temporal.Instant.compare(i2, Temporal.Instant.from(i2)), 0) +assert.sameValue(Temporal.Instant.compare(i2, i2), 0) // cross epoch smaller/larger assert.sameValue(Temporal.Instant.compare(i1, i2), -1) diff --git a/test/built-ins/Temporal/Instant/fromEpochMilliseconds/limits.js b/test/built-ins/Temporal/Instant/fromEpochMilliseconds/limits.js new file mode 100644 index 0000000000..40d3b129bf --- /dev/null +++ b/test/built-ins/Temporal/Instant/fromEpochMilliseconds/limits.js @@ -0,0 +1,20 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.fromepochmilliseconds +description: Min/max range. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + + +// constructing from ms +var limit = 8640000000000000; +assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(-limit - 1)); +assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(limit + 1)); +TemporalHelpers.assertInstantsEqual(Temporal.Instant.fromEpochMilliseconds(-limit), + Temporal.Instant.from("-271821-04-20T00:00:00Z")); +TemporalHelpers.assertInstantsEqual(Temporal.Instant.fromEpochMilliseconds(limit), + Temporal.Instant.from("+275760-09-13T00:00:00Z")); + diff --git a/test/built-ins/Temporal/Instant/limits.js b/test/built-ins/Temporal/Instant/limits.js new file mode 100644 index 0000000000..8d9b0cb217 --- /dev/null +++ b/test/built-ins/Temporal/Instant/limits.js @@ -0,0 +1,19 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant +description: Min/max range. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + + +// constructing from ns +var limit = 8640000000000000000000n; +assert.throws(RangeError, () => new Temporal.Instant(-limit - 1n)); +assert.throws(RangeError, () => new Temporal.Instant(limit + 1n)); +TemporalHelpers.assertInstantsEqual(new Temporal.Instant(-limit), + Temporal.Instant.from("-271821-04-20T00:00:00Z")); +TemporalHelpers.assertInstantsEqual(new Temporal.Instant(limit), + Temporal.Instant.from("+275760-09-13T00:00:00Z")); diff --git a/test/built-ins/Temporal/Instant/prototype/add/cross-epoch.js b/test/built-ins/Temporal/Instant/prototype/add/cross-epoch.js new file mode 100644 index 0000000000..3d17400390 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/add/cross-epoch.js @@ -0,0 +1,35 @@ +// Copyright (C) 2018 Bloomberg LP. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal-instant.prototype.add +description: Cross-epoch arithmetic. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const inst = Temporal.Instant.from("1969-12-25T12:23:45.678901234Z"); + +// cross epoch in ms +const one = inst.subtract({ + hours: 240, + nanoseconds: 800 +}); +const two = inst.add({ + hours: 240, + nanoseconds: 800 +}); +const three = two.subtract({ + hours: 480, + nanoseconds: 1600 +}); +const four = one.add({ + hours: 480, + nanoseconds: 1600 +}); +TemporalHelpers.assertInstantsEqual(one, Temporal.Instant.from("1969-12-15T12:23:45.678900434Z"), + `(${ inst }).subtract({ hours: 240, nanoseconds: 800 }) = ${ one }`); +TemporalHelpers.assertInstantsEqual(two, Temporal.Instant.from("1970-01-04T12:23:45.678902034Z"), + `(${ inst }).add({ hours: 240, nanoseconds: 800 }) = ${ two }`); +TemporalHelpers.assertInstantsEqual(three, one, `(${ two }).subtract({ hours: 480, nanoseconds: 1600 }) = ${ one }`); +TemporalHelpers.assertInstantsEqual(four, two, `(${ one }).add({ hours: 480, nanoseconds: 1600 }) = ${ two }`); diff --git a/test/staging/Temporal/Instant/old/equals.js b/test/built-ins/Temporal/Instant/prototype/equals/cross-epoch.js similarity index 52% rename from test/staging/Temporal/Instant/old/equals.js rename to test/built-ins/Temporal/Instant/prototype/equals/cross-epoch.js index 0bdbe1b848..49332af510 100644 --- a/test/staging/Temporal/Instant/old/equals.js +++ b/test/built-ins/Temporal/Instant/prototype/equals/cross-epoch.js @@ -2,14 +2,14 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal-instant-objects -description: Temporal.Instant.equals works +esid: sec-temporal.instant.prototype.equals +description: Temporal.Instant.equals works cross-epoch features: [Temporal] ---*/ -var i1 = Temporal.Instant.from("1963-02-13T09:36:29.123456789Z"); -var i2 = Temporal.Instant.from("1976-11-18T15:23:30.123456789Z"); -var i3 = Temporal.Instant.from("1981-12-15T14:34:31.987654321Z"); +const i1 = Temporal.Instant.from("1963-02-13T09:36:29.123456789Z"); +const i2 = Temporal.Instant.from("1976-11-18T15:23:30.123456789Z"); +const i3 = Temporal.Instant.from("1981-12-15T14:34:31.987654321Z"); // pre epoch equal assert(i1.equals(i1)) diff --git a/test/built-ins/Temporal/Instant/prototype/round/accepts-plural-units.js b/test/built-ins/Temporal/Instant/prototype/round/accepts-plural-units.js new file mode 100644 index 0000000000..24cafd35ee --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/accepts-plural-units.js @@ -0,0 +1,23 @@ +// 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.instant.prototype.round +description: round() accepts plural units. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const inst = new Temporal.Instant(1_000_000_000_123_456_789n); + +[ + "hour", + "minute", + "second", + "millisecond", + "microsecond", + "nanosecond" +].forEach(smallestUnit => { + TemporalHelpers.assertInstantsEqual(inst.round({ smallestUnit }), + inst.round({ smallestUnit: `${ smallestUnit }s` })); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/round/accepts-string-parameter-for-smallestunit.js b/test/built-ins/Temporal/Instant/prototype/round/accepts-string-parameter-for-smallestunit.js new file mode 100644 index 0000000000..d8a8c4c6f9 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/accepts-string-parameter-for-smallestunit.js @@ -0,0 +1,23 @@ +// 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.instant.prototype.round +description: round() accepts string parameter as shortcut for {smallestUnit}. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const inst = new Temporal.Instant(1_000_000_000_123_456_789n); + +[ + "hour", + "minute", + "second", + "millisecond", + "microsecond", + "nanosecond" +].forEach(smallestUnit => { + TemporalHelpers.assertInstantsEqual(inst.round(smallestUnit), + inst.round({ smallestUnit })); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/round/allow-increments-that-divide-evenly-into-solar-days.js b/test/built-ins/Temporal/Instant/prototype/round/allow-increments-that-divide-evenly-into-solar-days.js new file mode 100644 index 0000000000..fa73bbc88c --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/allow-increments-that-divide-evenly-into-solar-days.js @@ -0,0 +1,15 @@ +// 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.instant.prototype.round +description: round() allows increments that divide evenly into solar days. +features: [Temporal] +---*/ + +const inst = Temporal.Instant.from("1976-11-18T14:23:30.123456789Z"); + +assert(inst.round({ + smallestUnit: "second", + roundingIncrement: 864 +}) instanceof Temporal.Instant); diff --git a/test/built-ins/Temporal/Instant/prototype/round/round-to-days.js b/test/built-ins/Temporal/Instant/prototype/round/round-to-days.js new file mode 100644 index 0000000000..9c2be93f01 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/round-to-days.js @@ -0,0 +1,29 @@ +// 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.instant.prototype.round +description: Rounds to days by specifying increments of 86400 seconds in various units +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const inst = Temporal.Instant.from("1976-11-18T14:23:30.123456789Z"); +const expected = Temporal.Instant.from("1976-11-19T00:00:00Z"); + +TemporalHelpers.assertInstantsEqual(inst.round({ + smallestUnit: "hour", + roundingIncrement: 24 +}), expected); +TemporalHelpers.assertInstantsEqual(inst.round({ + smallestUnit: "minute", + roundingIncrement: 1440 +}), expected); +TemporalHelpers.assertInstantsEqual(inst.round({ + smallestUnit: "second", + roundingIncrement: 86400 +}), expected); +TemporalHelpers.assertInstantsEqual(inst.round({ + smallestUnit: "millisecond", + roundingIncrement: 86400000 +}), expected); diff --git a/test/built-ins/Temporal/Instant/prototype/round/rounding-increments.js b/test/built-ins/Temporal/Instant/prototype/round/rounding-increments.js new file mode 100644 index 0000000000..0314b05737 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/rounding-increments.js @@ -0,0 +1,47 @@ +// 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.instant.prototype.round +description: round() throws without required smallestUnit parameter. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const inst = Temporal.Instant.from("1976-11-18T14:23:30.123456789Z"); + +// rounds to an increment of hours +TemporalHelpers.assertInstantsEqual(inst.round({ + smallestUnit: "hour", + roundingIncrement: 4 +}), Temporal.Instant.from("1976-11-18T16:00:00Z")); + +// rounds to an increment of minutes +TemporalHelpers.assertInstantsEqual(inst.round({ + smallestUnit: "minute", + roundingIncrement: 15 +}), Temporal.Instant.from("1976-11-18T14:30:00Z")); + +// rounds to an increment of seconds +TemporalHelpers.assertInstantsEqual(inst.round({ + smallestUnit: "second", + roundingIncrement: 30 +}), Temporal.Instant.from("1976-11-18T14:23:30Z")); + +// rounds to an increment of milliseconds +TemporalHelpers.assertInstantsEqual(inst.round({ + smallestUnit: "millisecond", + roundingIncrement: 10 +}), Temporal.Instant.from("1976-11-18T14:23:30.12Z")); + +// rounds to an increment of microseconds +TemporalHelpers.assertInstantsEqual(inst.round({ + smallestUnit: "microsecond", + roundingIncrement: 10 +}), Temporal.Instant.from("1976-11-18T14:23:30.12346Z")); + +// rounds to an increment of nanoseconds +TemporalHelpers.assertInstantsEqual(inst.round({ + smallestUnit: "nanosecond", + roundingIncrement: 10 +}), Temporal.Instant.from("1976-11-18T14:23:30.12345679Z")); diff --git a/test/built-ins/Temporal/Instant/prototype/round/throws-on-increments-that-do-not-divide-evenly.js b/test/built-ins/Temporal/Instant/prototype/round/throws-on-increments-that-do-not-divide-evenly.js new file mode 100644 index 0000000000..785a084547 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/throws-on-increments-that-do-not-divide-evenly.js @@ -0,0 +1,35 @@ +// 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.instant.prototype.round +description: round() throws on increments that do not divide evenly into solar days. +features: [Temporal] +---*/ + +const inst = new Temporal.Instant(0n); + +assert.throws(RangeError, () => inst.round({ + smallestUnit: "hour", + roundingIncrement: 7 +})); +assert.throws(RangeError, () => inst.round({ + smallestUnit: "minute", + roundingIncrement: 29 +})); +assert.throws(RangeError, () => inst.round({ + smallestUnit: "second", + roundingIncrement: 29 +})); +assert.throws(RangeError, () => inst.round({ + smallestUnit: "millisecond", + roundingIncrement: 29 +})); +assert.throws(RangeError, () => inst.round({ + smallestUnit: "microsecond", + roundingIncrement: 29 +})); +assert.throws(RangeError, () => inst.round({ + smallestUnit: "nanosecond", + roundingIncrement: 29 +})); diff --git a/test/built-ins/Temporal/Instant/prototype/round/throws-without-smallest-unit.js b/test/built-ins/Temporal/Instant/prototype/round/throws-without-smallest-unit.js new file mode 100644 index 0000000000..bec2eb2973 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/throws-without-smallest-unit.js @@ -0,0 +1,16 @@ +// 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.instant.prototype.round +description: round() throws without required smallestUnit parameter. +features: [Temporal] +---*/ + +const inst = new Temporal.Instant(0n); + +assert.throws(RangeError, () => inst.round({})); +assert.throws(RangeError, () => inst.round({ + roundingIncrement: 1, + roundingMode: "ceil" +})); diff --git a/test/built-ins/Temporal/Instant/prototype/since/add-subtract.js b/test/built-ins/Temporal/Instant/prototype/since/add-subtract.js new file mode 100644 index 0000000000..53c74c8638 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/add-subtract.js @@ -0,0 +1,18 @@ +// 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.instant.prototype.since +description: since() works. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.Instant.from("1976-11-18T15:23:30.123456789Z"); +const later = Temporal.Instant.from("2019-10-29T10:46:38.271986102Z"); +const diff = later.since(earlier); + +TemporalHelpers.assertDurationsEqual(earlier.since(later), diff.negated()); +TemporalHelpers.assertDurationsEqual(earlier.until(later), diff); +TemporalHelpers.assertInstantsEqual(earlier.add(diff), later); +TemporalHelpers.assertInstantsEqual(later.subtract(diff), earlier); diff --git a/test/built-ins/Temporal/Instant/prototype/since/invalid-increments.js b/test/built-ins/Temporal/Instant/prototype/since/invalid-increments.js new file mode 100644 index 0000000000..93d0379d90 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/invalid-increments.js @@ -0,0 +1,77 @@ + +// 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.instant.prototype.since +description: Test invalid increments. +features: [Temporal] +---*/ + +const earlier = new Temporal.Instant(0n); +const later = new Temporal.Instant(1_000_000_000_000_000_000n); +const largestUnit = "hours"; + +// throws on increments that do not divide evenly into the next highest +assert.throws(RangeError, () => later.since(earlier, { + largestUnit, + smallestUnit: "hours", + roundingIncrement: 11 +})); +assert.throws(RangeError, () => later.since(earlier, { + largestUnit, + smallestUnit: "minutes", + roundingIncrement: 29 +})); +assert.throws(RangeError, () => later.since(earlier, { + largestUnit, + smallestUnit: "seconds", + roundingIncrement: 29 +})); +assert.throws(RangeError, () => later.since(earlier, { + largestUnit, + smallestUnit: "milliseconds", + roundingIncrement: 29 +})); +assert.throws(RangeError, () => later.since(earlier, { + largestUnit, + smallestUnit: "microseconds", + roundingIncrement: 29 +})); +assert.throws(RangeError, () => later.since(earlier, { + largestUnit, + smallestUnit: "nanoseconds", + roundingIncrement: 29 +})); + +// throws on increments that are equal to the next highest +assert.throws(RangeError, () => later.since(earlier, { + largestUnit, + smallestUnit: "hours", + roundingIncrement: 24 +})); +assert.throws(RangeError, () => later.since(earlier, { + largestUnit, + smallestUnit: "minutes", + roundingIncrement: 60 +})); +assert.throws(RangeError, () => later.since(earlier, { + largestUnit, + smallestUnit: "seconds", + roundingIncrement: 60 +})); +assert.throws(RangeError, () => later.since(earlier, { + largestUnit, + smallestUnit: "milliseconds", + roundingIncrement: 1000 +})); +assert.throws(RangeError, () => later.since(earlier, { + largestUnit, + smallestUnit: "microseconds", + roundingIncrement: 1000 +})); +assert.throws(RangeError, () => later.since(earlier, { + largestUnit, + smallestUnit: "nanoseconds", + roundingIncrement: 1000 +})); diff --git a/test/built-ins/Temporal/Instant/prototype/since/largest-unit-default.js b/test/built-ins/Temporal/Instant/prototype/since/largest-unit-default.js new file mode 100644 index 0000000000..88649032c2 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/largest-unit-default.js @@ -0,0 +1,21 @@ +// 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.instant.prototype.since +description: Assumes a different default for largestUnit if smallestUnit is larger than seconds. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.Instant.from("1976-11-18T15:23:30.123456789Z"); +const later = Temporal.Instant.from("2019-10-29T10:46:38.271986102Z"); + +TemporalHelpers.assertDuration(later.since(earlier, { + smallestUnit: "hours", + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 376435, 0, 0, 0, 0, 0); +TemporalHelpers.assertDuration(later.since(earlier, { + smallestUnit: "minutes", + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 0, 22586123, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/Instant/prototype/since/minutes-and-hours.js b/test/built-ins/Temporal/Instant/prototype/since/minutes-and-hours.js new file mode 100644 index 0000000000..f2f655ad12 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/minutes-and-hours.js @@ -0,0 +1,18 @@ +// 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.instant.prototype.since +description: since() can return minutes and hours. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const feb20 = Temporal.Instant.from("2020-02-01T00:00Z"); +const feb21 = Temporal.Instant.from("2021-02-01T00:00Z"); + +// can return minutes and hours +TemporalHelpers.assertDuration(feb21.since(feb20, { largestUnit: "hours" }), + 0, 0, 0, 0, 8784, 0, 0, 0, 0, 0); +TemporalHelpers.assertDuration(feb21.since(feb20, { largestUnit: "minutes" }), + 0, 0, 0, 0, 0, 527040, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/Instant/prototype/since/options-may-be-function.js b/test/built-ins/Temporal/Instant/prototype/since/options-may-be-function.js new file mode 100644 index 0000000000..e629aa1d5b --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/options-may-be-function.js @@ -0,0 +1,15 @@ +// 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.instant.prototype.since +description: Options may be a function object. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const feb20 = Temporal.Instant.from("2020-02-01T00:00Z"); +const feb21 = Temporal.Instant.from("2021-02-01T00:00Z"); + +TemporalHelpers.assertDuration(feb21.since(feb20, () => {}), + 0, 0, 0, 0, 0, 0, 31622400, 0, 0, 0); diff --git a/test/built-ins/Temporal/Instant/prototype/since/rounding-increments.js b/test/built-ins/Temporal/Instant/prototype/since/rounding-increments.js new file mode 100644 index 0000000000..02285483e6 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/rounding-increments.js @@ -0,0 +1,62 @@ +// 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.instant.prototype.since +description: Test different rounding increments. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.Instant.from("1976-11-18T15:23:30.123456789Z"); +const later = Temporal.Instant.from("2019-10-29T10:46:38.271986102Z"); +const largestUnit = "hours"; + +// rounds to an increment of hours +TemporalHelpers.assertDuration(later.since(earlier, { + largestUnit, + smallestUnit: "hours", + roundingIncrement: 3, + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 376434, 0, 0, 0, 0, 0); + +// rounds to an increment of minutes +TemporalHelpers.assertDuration(later.since(earlier, { + largestUnit, + smallestUnit: "minutes", + roundingIncrement: 30, + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 376435, 30, 0, 0, 0, 0); + +// rounds to an increment of seconds +TemporalHelpers.assertDuration(later.since(earlier, { + largestUnit, + smallestUnit: "seconds", + roundingIncrement: 15, + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 376435, 23, 15, 0, 0, 0); + +// rounds to an increment of milliseconds +TemporalHelpers.assertDuration(later.since(earlier, { + largestUnit, + smallestUnit: "milliseconds", + roundingIncrement: 10, + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 376435, 23, 8, 150, 0, 0); + +// rounds to an increment of microseconds +TemporalHelpers.assertDuration(later.since(earlier, { + largestUnit, + smallestUnit: "microseconds", + roundingIncrement: 10, + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 376435, 23, 8, 148, 530, 0); + +// rounds to an increment of nanoseconds +TemporalHelpers.assertDuration(later.since(earlier, { + largestUnit, + smallestUnit: "nanoseconds", + roundingIncrement: 10, + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 376435, 23, 8, 148, 529, 310); + diff --git a/test/built-ins/Temporal/Instant/prototype/since/subseconds.js b/test/built-ins/Temporal/Instant/prototype/since/subseconds.js new file mode 100644 index 0000000000..f6348059b9 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/subseconds.js @@ -0,0 +1,30 @@ +// 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.instant.prototype.since +description: since() can return subseconds. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const feb20 = Temporal.Instant.from("2020-02-01T00:00Z"); + +const latersub = feb20.add({ + hours: 24, + milliseconds: 250, + microseconds: 250, + nanoseconds: 250 +}); + +const msDiff = latersub.since(feb20, { largestUnit: "milliseconds" }); +TemporalHelpers.assertDuration(msDiff, + 0, 0, 0, 0, 0, 0, 0, 86400250, 250, 250); + +const µsDiff = latersub.since(feb20, { largestUnit: "microseconds" }); +TemporalHelpers.assertDuration(µsDiff, + 0, 0, 0, 0, 0, 0, 0, 0, 86400250250, 250); + +const nsDiff = latersub.since(feb20, { largestUnit: "nanoseconds" }); +TemporalHelpers.assertDuration(nsDiff, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 86400250250250); diff --git a/test/built-ins/Temporal/Instant/prototype/since/valid-increments.js b/test/built-ins/Temporal/Instant/prototype/since/valid-increments.js new file mode 100644 index 0000000000..c4729f2524 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/valid-increments.js @@ -0,0 +1,89 @@ +// 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.instant.prototype.since +description: Test valid increments. +features: [Temporal] +---*/ + +const earlier = Temporal.Instant.from("1976-11-18T15:23:30.123456789Z"); +const later = Temporal.Instant.from("2019-10-29T10:46:38.271986102Z"); +const largestUnit = "hours"; + +[ + 1, + 2, + 3, + 4, + 6, + 8, + 12 +].forEach(roundingIncrement => { + const options = { + largestUnit, + smallestUnit: "hours", + roundingIncrement + }; + assert(later.since(earlier, options) instanceof Temporal.Duration); +}); + +// valid increments divide into 60 +[ + "minutes", + "seconds" +].forEach(smallestUnit => { + [ + 1, + 2, + 3, + 4, + 5, + 6, + 10, + 12, + 15, + 20, + 30 + ].forEach(roundingIncrement => { + const options = { + largestUnit, + smallestUnit, + roundingIncrement + }; + assert(later.since(earlier, options) instanceof Temporal.Duration); + }); +}); + +// valid increments divide into 1000 +[ + "milliseconds", + "microseconds", + "nanoseconds" +].forEach(smallestUnit => { + [ + 1, + 2, + 4, + 5, + 8, + 10, + 20, + 25, + 40, + 50, + 100, + 125, + 200, + 250, + 500 + ].forEach(roundingIncrement => { + const options = { + largestUnit, + smallestUnit, + roundingIncrement + }; + assert(later.since(earlier, options) instanceof Temporal.Duration); + }); +}); + diff --git a/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-missing.js b/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-missing.js new file mode 100644 index 0000000000..f03b8c0b5b --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/timezone-missing.js @@ -0,0 +1,12 @@ +// 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.instant.prototype.tozoneddatetimeiso +description: toZonedDateTimeISO() throws without parameter. +features: [Temporal] +---*/ + +const inst = Temporal.Instant.from("1976-11-18T14:23:30.123456789Z"); + +assert.throws(TypeError, () => inst.toZonedDateTimeISO()); diff --git a/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/to-zoned-date-time-iso.js b/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/to-zoned-date-time-iso.js new file mode 100644 index 0000000000..8e0c6beaaf --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toZonedDateTimeISO/to-zoned-date-time-iso.js @@ -0,0 +1,20 @@ +// 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.instant.prototype.tozoneddatetimeiso +description: Test time zone parameters. +features: [Temporal] +---*/ + +const inst = new Temporal.Instant(1_000_000_000_000_000_000n); + +// time zone parameter UTC +const zdt = inst.toZonedDateTimeISO("UTC"); +assert.sameValue(inst.epochNanoseconds, zdt.epochNanoseconds); +assert.sameValue(zdt.timeZoneId, "UTC"); + +// time zone parameter non-UTC +const zdtNonUTC = inst.toZonedDateTimeISO("-05:00"); +assert.sameValue(inst.epochNanoseconds, zdtNonUTC.epochNanoseconds); +assert.sameValue(zdtNonUTC.timeZoneId, "-05:00"); diff --git a/test/built-ins/Temporal/Instant/prototype/until/add-subtract.js b/test/built-ins/Temporal/Instant/prototype/until/add-subtract.js new file mode 100644 index 0000000000..8e4e5fd936 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/add-subtract.js @@ -0,0 +1,19 @@ +// 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.instant.prototype.until +description: until() works. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.Instant.from("1969-07-24T16:50:35.123456789Z"); +const later = Temporal.Instant.from("2019-10-29T10:46:38.271986102Z"); +const diff = earlier.until(later); + +TemporalHelpers.assertDurationsEqual(later.until(earlier), diff.negated()); +TemporalHelpers.assertDurationsEqual(later.since(earlier), diff); +TemporalHelpers.assertInstantsEqual(earlier.add(diff), later); +TemporalHelpers.assertInstantsEqual(later.subtract(diff), earlier); + diff --git a/test/built-ins/Temporal/Instant/prototype/until/invalid-increments.js b/test/built-ins/Temporal/Instant/prototype/until/invalid-increments.js new file mode 100644 index 0000000000..1d776a7c2e --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/invalid-increments.js @@ -0,0 +1,76 @@ +// 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.instant.prototype.until +description: Test various rounding increments. +features: [Temporal] +---*/ + +const earlier = Temporal.Instant.from("1969-07-24T16:50:35.123456789Z"); +const later = Temporal.Instant.from("2019-10-29T10:46:38.271986102Z"); +const largestUnit = "hours"; + +// throws on increments that do not divide evenly into the next highest +assert.throws(RangeError, () => earlier.until(later, { + largestUnit, + smallestUnit: "hours", + roundingIncrement: 11 +})); +assert.throws(RangeError, () => earlier.until(later, { + largestUnit, + smallestUnit: "minutes", + roundingIncrement: 29 +})); +assert.throws(RangeError, () => earlier.until(later, { + largestUnit, + smallestUnit: "seconds", + roundingIncrement: 29 +})); +assert.throws(RangeError, () => earlier.until(later, { + largestUnit, + smallestUnit: "milliseconds", + roundingIncrement: 29 +})); +assert.throws(RangeError, () => earlier.until(later, { + largestUnit, + smallestUnit: "microseconds", + roundingIncrement: 29 +})); +assert.throws(RangeError, () => earlier.until(later, { + largestUnit, + smallestUnit: "nanoseconds", + roundingIncrement: 29 +})); + +// throws on increments that are equal to the next highest +assert.throws(RangeError, () => earlier.until(later, { + largestUnit, + smallestUnit: "hours", + roundingIncrement: 24 +})); +assert.throws(RangeError, () => earlier.until(later, { + largestUnit, + smallestUnit: "minutes", + roundingIncrement: 60 +})); +assert.throws(RangeError, () => earlier.until(later, { + largestUnit, + smallestUnit: "seconds", + roundingIncrement: 60 +})); +assert.throws(RangeError, () => earlier.until(later, { + largestUnit, + smallestUnit: "milliseconds", + roundingIncrement: 1000 +})); +assert.throws(RangeError, () => earlier.until(later, { + largestUnit, + smallestUnit: "microseconds", + roundingIncrement: 1000 +})); +assert.throws(RangeError, () => earlier.until(later, { + largestUnit, + smallestUnit: "nanoseconds", + roundingIncrement: 1000 +})); diff --git a/test/built-ins/Temporal/Instant/prototype/until/largestunit-default.js b/test/built-ins/Temporal/Instant/prototype/until/largestunit-default.js new file mode 100644 index 0000000000..245bf95ec9 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/largestunit-default.js @@ -0,0 +1,21 @@ +// 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.instant.prototype.until +description: Assumes a different default for largestUnit if smallestUnit is larger than seconds. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.Instant.from("1969-07-24T16:50:35.123456789Z"); +const later = Temporal.Instant.from("2019-10-29T10:46:38.271986102Z"); + +TemporalHelpers.assertDuration(earlier.until(later, { + smallestUnit: "hours", + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 440610, 0, 0, 0, 0, 0); +TemporalHelpers.assertDuration(earlier.until(later, { + smallestUnit: "minutes", + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 0, 26436596, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/Instant/prototype/until/minutes-and-hours.js b/test/built-ins/Temporal/Instant/prototype/until/minutes-and-hours.js new file mode 100644 index 0000000000..97652ec85c --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/minutes-and-hours.js @@ -0,0 +1,17 @@ +// 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.instant.prototype.until +description: Can return minutes and hours. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const feb20 = Temporal.Instant.from("2020-02-01T00:00Z"); +const feb21 = Temporal.Instant.from("2021-02-01T00:00Z"); + +TemporalHelpers.assertDuration(feb20.until(feb21, { largestUnit: "hours" }), + 0, 0, 0, 0, 8784, 0, 0, 0, 0, 0); +TemporalHelpers.assertDuration(feb20.until(feb21, { largestUnit: "minutes" }), + 0, 0, 0, 0, 0, 527040, 0, 0, 0, 0); diff --git a/test/built-ins/Temporal/Instant/prototype/until/options-may-be-function.js b/test/built-ins/Temporal/Instant/prototype/until/options-may-be-function.js new file mode 100644 index 0000000000..7b104a2ff0 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/options-may-be-function.js @@ -0,0 +1,15 @@ +// 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.instant.prototype.until +description: Options may be a function object. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const feb20 = Temporal.Instant.from("2020-02-01T00:00Z"); +const feb21 = Temporal.Instant.from("2021-02-01T00:00Z"); + +TemporalHelpers.assertDuration(feb20.until(feb21, () => {}), + 0, 0, 0, 0, 0, 0, 31622400, 0, 0, 0); diff --git a/test/built-ins/Temporal/Instant/prototype/until/rounding-increments.js b/test/built-ins/Temporal/Instant/prototype/until/rounding-increments.js new file mode 100644 index 0000000000..57d50d9263 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/rounding-increments.js @@ -0,0 +1,62 @@ +// 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.instant.prototype.until +description: Test various rounding increments. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.Instant.from("1969-07-24T16:50:35.123456789Z"); +const later = Temporal.Instant.from("2019-10-29T10:46:38.271986102Z"); +const largestUnit = "hours"; + +// rounds to an increment of hours +TemporalHelpers.assertDuration(earlier.until(later, { + largestUnit, + smallestUnit: "hours", + roundingIncrement: 4, + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 440608, 0, 0, 0, 0, 0); + +// rounds to an increment of minutes +TemporalHelpers.assertDuration(earlier.until(later, { + largestUnit, + smallestUnit: "minutes", + roundingIncrement: 30, + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 440610, 0, 0, 0, 0, 0); + +// rounds to an increment of seconds +TemporalHelpers.assertDuration(earlier.until(later, { + largestUnit, + smallestUnit: "seconds", + roundingIncrement: 15, + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 440609, 56, 0, 0, 0, 0); + +// rounds to an increment of milliseconds +TemporalHelpers.assertDuration(earlier.until(later, { + largestUnit, + smallestUnit: "milliseconds", + roundingIncrement: 10, + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 440609, 56, 3, 150, 0, 0); + +// rounds to an increment of microseconds +TemporalHelpers.assertDuration(earlier.until(later, { + largestUnit, + smallestUnit: "microseconds", + roundingIncrement: 10, + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 440609, 56, 3, 148, 530, 0); + +// rounds to an increment of nanoseconds +TemporalHelpers.assertDuration(earlier.until(later, { + largestUnit, + smallestUnit: "nanoseconds", + roundingIncrement: 10, + roundingMode: "halfExpand" +}), 0, 0, 0, 0, 440609, 56, 3, 148, 529, 310); + diff --git a/test/built-ins/Temporal/Instant/prototype/until/subseconds.js b/test/built-ins/Temporal/Instant/prototype/until/subseconds.js new file mode 100644 index 0000000000..928727b482 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/subseconds.js @@ -0,0 +1,31 @@ +// 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.instant.prototype.until +description: Can return subseconds. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const feb20 = Temporal.Instant.from("2020-02-01T00:00Z"); +const feb21 = Temporal.Instant.from("2021-02-01T00:00Z"); + +const latersub = feb20.add({ + hours: 24, + milliseconds: 250, + microseconds: 250, + nanoseconds: 250 +}); +const msDiff = feb20.until(latersub, { largestUnit: "milliseconds" }); +TemporalHelpers.assertDuration(msDiff, + 0, 0, 0, 0, 0, 0, 0, 86400250, 250, 250); + +const µsDiff = feb20.until(latersub, { largestUnit: "microseconds" }); +TemporalHelpers.assertDuration(µsDiff, + 0, 0, 0, 0, 0, 0, 0, 0, 86400250250, 250); + +const nsDiff = feb20.until(latersub, { largestUnit: "nanoseconds" }); +TemporalHelpers.assertDuration(nsDiff, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 86400250250250); + diff --git a/test/built-ins/Temporal/Instant/prototype/until/valid-increments.js b/test/built-ins/Temporal/Instant/prototype/until/valid-increments.js new file mode 100644 index 0000000000..c6901705b8 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/valid-increments.js @@ -0,0 +1,89 @@ +// 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.instant.prototype.until +description: Test various rounding increments. +features: [Temporal] +---*/ + +const earlier = Temporal.Instant.from("1969-07-24T16:50:35.123456789Z"); +const later = Temporal.Instant.from("2019-10-29T10:46:38.271986102Z"); +const largestUnit = "hours"; + +// valid hour increments divide into 24 +[ + 1, + 2, + 3, + 4, + 6, + 8, + 12 +].forEach(roundingIncrement => { + const options = { + largestUnit, + smallestUnit: "hours", + roundingIncrement + }; + assert(earlier.until(later, options) instanceof Temporal.Duration); +}); + +// valid increments divide into 60 +[ + "minutes", + "seconds" +].forEach(smallestUnit => { + [ + 1, + 2, + 3, + 4, + 5, + 6, + 10, + 12, + 15, + 20, + 30 + ].forEach(roundingIncrement => { + const options = { + largestUnit, + smallestUnit, + roundingIncrement + }; + assert(earlier.until(later, options) instanceof Temporal.Duration); + }); +}); + +// valid increments divide into 1000 +[ + "milliseconds", + "microseconds", + "nanoseconds" +].forEach(smallestUnit => { + [ + 1, + 2, + 4, + 5, + 8, + 10, + 20, + 25, + 40, + 50, + 100, + 125, + 200, + 250, + 500 + ].forEach(roundingIncrement => { + const options = { + largestUnit, + smallestUnit, + roundingIncrement + }; + assert(earlier.until(later, options) instanceof Temporal.Duration); + }); +}); diff --git a/test/staging/Temporal/Instant/old/add.js b/test/staging/Temporal/Instant/old/add.js deleted file mode 100644 index 0141f4af6c..0000000000 --- a/test/staging/Temporal/Instant/old/add.js +++ /dev/null @@ -1,32 +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-instant-objects -description: Temporal.Instant.add works -features: [Temporal] ----*/ - -var inst = Temporal.Instant.from("1969-12-25T12:23:45.678901234Z"); - -// cross epoch in ms -var one = inst.subtract({ - hours: 240, - nanoseconds: 800 -}); -var two = inst.add({ - hours: 240, - nanoseconds: 800 -}); -var three = two.subtract({ - hours: 480, - nanoseconds: 1600 -}); -var four = one.add({ - hours: 480, - nanoseconds: 1600 -}); -assert.sameValue(`${ one }`, "1969-12-15T12:23:45.678900434Z", `(${ inst }).subtract({ hours: 240, nanoseconds: 800 }) = ${ one }`); -assert.sameValue(`${ two }`, "1970-01-04T12:23:45.678902034Z", `(${ inst }).add({ hours: 240, nanoseconds: 800 }) = ${ two }`); -assert(three.equals(one), `(${ two }).subtract({ hours: 480, nanoseconds: 1600 }) = ${ one }`); -assert(four.equals(two), `(${ one }).add({ hours: 480, nanoseconds: 1600 }) = ${ two }`); diff --git a/test/staging/Temporal/Instant/old/limits.js b/test/staging/Temporal/Instant/old/limits.js deleted file mode 100644 index d7818426a0..0000000000 --- a/test/staging/Temporal/Instant/old/limits.js +++ /dev/null @@ -1,23 +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-instant-objects -description: Min/max range -features: [Temporal] ----*/ - - -// constructing from ns -var limit = 8640000000000000000000n; -assert.throws(RangeError, () => new Temporal.Instant(-limit - 1n)); -assert.throws(RangeError, () => new Temporal.Instant(limit + 1n)); -assert.sameValue(`${ new Temporal.Instant(-limit) }`, "-271821-04-20T00:00:00Z"); -assert.sameValue(`${ new Temporal.Instant(limit) }`, "+275760-09-13T00:00:00Z"); - -// constructing from ms -var limit = 8640000000000000; -assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(-limit - 1)); -assert.throws(RangeError, () => Temporal.Instant.fromEpochMilliseconds(limit + 1)); -assert.sameValue(`${ Temporal.Instant.fromEpochMilliseconds(-limit) }`, "-271821-04-20T00:00:00Z"); -assert.sameValue(`${ Temporal.Instant.fromEpochMilliseconds(limit) }`, "+275760-09-13T00:00:00Z"); diff --git a/test/staging/Temporal/Instant/old/round.js b/test/staging/Temporal/Instant/old/round.js deleted file mode 100644 index 01b88205dc..0000000000 --- a/test/staging/Temporal/Instant/old/round.js +++ /dev/null @@ -1,128 +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-instant-objects -description: Temporal.Instant.round works -features: [Temporal] ----*/ - -var inst = Temporal.Instant.from("1976-11-18T14:23:30.123456789Z"); - -// throws without required smallestUnit parameter -assert.throws(RangeError, () => inst.round({})); -assert.throws(RangeError, () => inst.round({ - roundingIncrement: 1, - roundingMode: "ceil" -})); - -// rounds to an increment of hours -assert.sameValue(`${ inst.round({ - smallestUnit: "hour", - roundingIncrement: 4 -}) }`, "1976-11-18T16:00:00Z"); - -// rounds to an increment of minutes -assert.sameValue(`${ inst.round({ - smallestUnit: "minute", - roundingIncrement: 15 -}) }`, "1976-11-18T14:30:00Z"); - -// rounds to an increment of seconds -assert.sameValue(`${ inst.round({ - smallestUnit: "second", - roundingIncrement: 30 -}) }`, "1976-11-18T14:23:30Z"); - -// rounds to an increment of milliseconds -assert.sameValue(`${ inst.round({ - smallestUnit: "millisecond", - roundingIncrement: 10 -}) }`, "1976-11-18T14:23:30.12Z"); - -// rounds to an increment of microseconds -assert.sameValue(`${ inst.round({ - smallestUnit: "microsecond", - roundingIncrement: 10 -}) }`, "1976-11-18T14:23:30.12346Z"); - -// rounds to an increment of nanoseconds -assert.sameValue(`${ inst.round({ - smallestUnit: "nanosecond", - roundingIncrement: 10 -}) }`, "1976-11-18T14:23:30.12345679Z"); - -// rounds to days by specifying increment of 86400 seconds in various units -var expected = "1976-11-19T00:00:00Z"; -assert.sameValue(`${ inst.round({ - smallestUnit: "hour", - roundingIncrement: 24 -}) }`, expected); -assert.sameValue(`${ inst.round({ - smallestUnit: "minute", - roundingIncrement: 1440 -}) }`, expected); -assert.sameValue(`${ inst.round({ - smallestUnit: "second", - roundingIncrement: 86400 -}) }`, expected); -assert.sameValue(`${ inst.round({ - smallestUnit: "millisecond", - roundingIncrement: 86400000 -}) }`, expected); - -// allows increments that divide evenly into solar days -assert(inst.round({ - smallestUnit: "second", - roundingIncrement: 864 -}) instanceof Temporal.Instant); - -// throws on increments that do not divide evenly into solar days -assert.throws(RangeError, () => inst.round({ - smallestUnit: "hour", - roundingIncrement: 7 -})); -assert.throws(RangeError, () => inst.round({ - smallestUnit: "minute", - roundingIncrement: 29 -})); -assert.throws(RangeError, () => inst.round({ - smallestUnit: "second", - roundingIncrement: 29 -})); -assert.throws(RangeError, () => inst.round({ - smallestUnit: "millisecond", - roundingIncrement: 29 -})); -assert.throws(RangeError, () => inst.round({ - smallestUnit: "microsecond", - roundingIncrement: 29 -})); -assert.throws(RangeError, () => inst.round({ - smallestUnit: "nanosecond", - roundingIncrement: 29 -})); - -// accepts plural units -[ - "hour", - "minute", - "second", - "millisecond", - "microsecond", - "nanosecond" -].forEach(smallestUnit => { - assert(inst.round({ smallestUnit }).equals(inst.round({ smallestUnit: `${ smallestUnit }s` }))); -}); - -// accepts string parameter as shortcut for {smallestUnit} -[ - "hour", - "minute", - "second", - "millisecond", - "microsecond", - "nanosecond" -].forEach(smallestUnit => { - assert(inst.round(smallestUnit).equals(inst.round({ smallestUnit }))); -}); diff --git a/test/staging/Temporal/Instant/old/since.js b/test/staging/Temporal/Instant/old/since.js deleted file mode 100644 index fa9773de9a..0000000000 --- a/test/staging/Temporal/Instant/old/since.js +++ /dev/null @@ -1,246 +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-instant-objects -description: Temporal.Instant.since() works -features: [Temporal] ----*/ - -var earlier = Temporal.Instant.from("1976-11-18T15:23:30.123456789Z"); -var later = Temporal.Instant.from("2019-10-29T10:46:38.271986102Z"); -var diff = later.since(earlier); -assert.sameValue(`${ earlier.since(later) }`, `${ diff.negated() }`) -assert.sameValue(`${ earlier.until(later) }`, `${ diff }`) -assert(earlier.add(diff).equals(later)) -assert(later.subtract(diff).equals(earlier)) -var feb20 = Temporal.Instant.from("2020-02-01T00:00Z"); -var feb21 = Temporal.Instant.from("2021-02-01T00:00Z"); - -// can return minutes and hours -assert.sameValue(`${ feb21.since(feb20, { largestUnit: "hours" }) }`, "PT8784H"); -assert.sameValue(`${ feb21.since(feb20, { largestUnit: "minutes" }) }`, "PT527040M"); - -// can return subseconds -var latersub = feb20.add({ - hours: 24, - milliseconds: 250, - microseconds: 250, - nanoseconds: 250 -}); -var msDiff = latersub.since(feb20, { largestUnit: "milliseconds" }); -assert.sameValue(msDiff.seconds, 0); -assert.sameValue(msDiff.milliseconds, 86400250); -assert.sameValue(msDiff.microseconds, 250); -assert.sameValue(msDiff.nanoseconds, 250); -var µsDiff = latersub.since(feb20, { largestUnit: "microseconds" }); -assert.sameValue(µsDiff.milliseconds, 0); -assert.sameValue(µsDiff.microseconds, 86400250250); -assert.sameValue(µsDiff.nanoseconds, 250); -var nsDiff = latersub.since(feb20, { largestUnit: "nanoseconds" }); -assert.sameValue(nsDiff.microseconds, 0); -assert.sameValue(nsDiff.nanoseconds, 86400250250250); - -// options may be a function object -assert.sameValue(`${ feb21.since(feb20, () => { -}) }`, "PT31622400S"); - -// assumes a different default for largestUnit if smallestUnit is larger than seconds -assert.sameValue(`${ later.since(earlier, { - smallestUnit: "hours", - roundingMode: "halfExpand" -}) }`, "PT376435H"); -assert.sameValue(`${ later.since(earlier, { - smallestUnit: "minutes", - roundingMode: "halfExpand" -}) }`, "PT22586123M"); -var largestUnit = "hours"; - -// rounds to an increment of hours -assert.sameValue(`${ later.since(earlier, { - largestUnit, - smallestUnit: "hours", - roundingIncrement: 3, - roundingMode: "halfExpand" -}) }`, "PT376434H"); - -// rounds to an increment of minutes -assert.sameValue(`${ later.since(earlier, { - largestUnit, - smallestUnit: "minutes", - roundingIncrement: 30, - roundingMode: "halfExpand" -}) }`, "PT376435H30M"); - -// rounds to an increment of seconds -assert.sameValue(`${ later.since(earlier, { - largestUnit, - smallestUnit: "seconds", - roundingIncrement: 15, - roundingMode: "halfExpand" -}) }`, "PT376435H23M15S"); - -// rounds to an increment of milliseconds -assert.sameValue(`${ later.since(earlier, { - largestUnit, - smallestUnit: "milliseconds", - roundingIncrement: 10, - roundingMode: "halfExpand" -}) }`, "PT376435H23M8.15S"); - -// rounds to an increment of microseconds -assert.sameValue(`${ later.since(earlier, { - largestUnit, - smallestUnit: "microseconds", - roundingIncrement: 10, - roundingMode: "halfExpand" -}) }`, "PT376435H23M8.14853S"); - -// rounds to an increment of nanoseconds -assert.sameValue(`${ later.since(earlier, { - largestUnit, - smallestUnit: "nanoseconds", - roundingIncrement: 10, - roundingMode: "halfExpand" -}) }`, "PT376435H23M8.14852931S"); - -// valid hour increments divide into 24 -[ - 1, - 2, - 3, - 4, - 6, - 8, - 12 -].forEach(roundingIncrement => { - var options = { - largestUnit, - smallestUnit: "hours", - roundingIncrement - }; - assert(later.since(earlier, options) instanceof Temporal.Duration); -}); - -// valid increments divide into 60 -[ - "minutes", - "seconds" -].forEach(smallestUnit => { - [ - 1, - 2, - 3, - 4, - 5, - 6, - 10, - 12, - 15, - 20, - 30 - ].forEach(roundingIncrement => { - var options = { - largestUnit, - smallestUnit, - roundingIncrement - }; - assert(later.since(earlier, options) instanceof Temporal.Duration); - }); -}); - -// valid increments divide into 1000 -[ - "milliseconds", - "microseconds", - "nanoseconds" -].forEach(smallestUnit => { - [ - 1, - 2, - 4, - 5, - 8, - 10, - 20, - 25, - 40, - 50, - 100, - 125, - 200, - 250, - 500 - ].forEach(roundingIncrement => { - var options = { - largestUnit, - smallestUnit, - roundingIncrement - }; - assert(later.since(earlier, options) instanceof Temporal.Duration); - }); -}); - -// throws on increments that do not divide evenly into the next highest -assert.throws(RangeError, () => later.since(earlier, { - largestUnit, - smallestUnit: "hours", - roundingIncrement: 11 -})); -assert.throws(RangeError, () => later.since(earlier, { - largestUnit, - smallestUnit: "minutes", - roundingIncrement: 29 -})); -assert.throws(RangeError, () => later.since(earlier, { - largestUnit, - smallestUnit: "seconds", - roundingIncrement: 29 -})); -assert.throws(RangeError, () => later.since(earlier, { - largestUnit, - smallestUnit: "milliseconds", - roundingIncrement: 29 -})); -assert.throws(RangeError, () => later.since(earlier, { - largestUnit, - smallestUnit: "microseconds", - roundingIncrement: 29 -})); -assert.throws(RangeError, () => later.since(earlier, { - largestUnit, - smallestUnit: "nanoseconds", - roundingIncrement: 29 -})); - -// throws on increments that are equal to the next highest -assert.throws(RangeError, () => later.since(earlier, { - largestUnit, - smallestUnit: "hours", - roundingIncrement: 24 -})); -assert.throws(RangeError, () => later.since(earlier, { - largestUnit, - smallestUnit: "minutes", - roundingIncrement: 60 -})); -assert.throws(RangeError, () => later.since(earlier, { - largestUnit, - smallestUnit: "seconds", - roundingIncrement: 60 -})); -assert.throws(RangeError, () => later.since(earlier, { - largestUnit, - smallestUnit: "milliseconds", - roundingIncrement: 1000 -})); -assert.throws(RangeError, () => later.since(earlier, { - largestUnit, - smallestUnit: "microseconds", - roundingIncrement: 1000 -})); -assert.throws(RangeError, () => later.since(earlier, { - largestUnit, - smallestUnit: "nanoseconds", - roundingIncrement: 1000 -})); diff --git a/test/staging/Temporal/Instant/old/toZonedDateTimeISO.js b/test/staging/Temporal/Instant/old/toZonedDateTimeISO.js deleted file mode 100644 index 6f50c10771..0000000000 --- a/test/staging/Temporal/Instant/old/toZonedDateTimeISO.js +++ /dev/null @@ -1,23 +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-instant-objects -description: Temporal.Instant.toZonedDateTimeISO() works -features: [Temporal] ----*/ - -var inst = Temporal.Instant.from("1976-11-18T14:23:30.123456789Z"); - -// throws without parameter -assert.throws(TypeError, () => inst.toZonedDateTimeISO()); - -// time zone parameter UTC -var zdt = inst.toZonedDateTimeISO("UTC"); -assert.sameValue(inst.epochNanoseconds, zdt.epochNanoseconds); -assert.sameValue(`${ zdt }`, "1976-11-18T14:23:30.123456789+00:00[UTC]"); - -// time zone parameter non-UTC -var zdt = inst.toZonedDateTimeISO("-05:00"); -assert.sameValue(inst.epochNanoseconds, zdt.epochNanoseconds); -assert.sameValue(`${ zdt }`, "1976-11-18T09:23:30.123456789-05:00[-05:00]"); diff --git a/test/staging/Temporal/Instant/old/until.js b/test/staging/Temporal/Instant/old/until.js deleted file mode 100644 index 3c4c33ad31..0000000000 --- a/test/staging/Temporal/Instant/old/until.js +++ /dev/null @@ -1,246 +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-instant-objects -description: Temporal.Instant.until() works -features: [Temporal] ----*/ - -var earlier = Temporal.Instant.from("1969-07-24T16:50:35.123456789Z"); -var later = Temporal.Instant.from("2019-10-29T10:46:38.271986102Z"); -var diff = earlier.until(later); -assert.sameValue(`${ later.until(earlier) }`, `${ diff.negated() }`) -assert.sameValue(`${ later.since(earlier) }`, `${ diff }`) -assert(earlier.add(diff).equals(later)) -assert(later.subtract(diff).equals(earlier)) -var feb20 = Temporal.Instant.from("2020-02-01T00:00Z"); -var feb21 = Temporal.Instant.from("2021-02-01T00:00Z"); - -// can return minutes and hours -assert.sameValue(`${ feb20.until(feb21, { largestUnit: "hours" }) }`, "PT8784H"); -assert.sameValue(`${ feb20.until(feb21, { largestUnit: "minutes" }) }`, "PT527040M"); - -// can return subseconds -var latersub = feb20.add({ - hours: 24, - milliseconds: 250, - microseconds: 250, - nanoseconds: 250 -}); -var msDiff = feb20.until(latersub, { largestUnit: "milliseconds" }); -assert.sameValue(msDiff.seconds, 0); -assert.sameValue(msDiff.milliseconds, 86400250); -assert.sameValue(msDiff.microseconds, 250); -assert.sameValue(msDiff.nanoseconds, 250); -var µsDiff = feb20.until(latersub, { largestUnit: "microseconds" }); -assert.sameValue(µsDiff.milliseconds, 0); -assert.sameValue(µsDiff.microseconds, 86400250250); -assert.sameValue(µsDiff.nanoseconds, 250); -var nsDiff = feb20.until(latersub, { largestUnit: "nanoseconds" }); -assert.sameValue(nsDiff.microseconds, 0); -assert.sameValue(nsDiff.nanoseconds, 86400250250250); - -// options may be a function object -assert.sameValue(`${ feb20.until(feb21, () => { -}) }`, "PT31622400S"); - -// assumes a different default for largestUnit if smallestUnit is larger than seconds -assert.sameValue(`${ earlier.until(later, { - smallestUnit: "hours", - roundingMode: "halfExpand" -}) }`, "PT440610H"); -assert.sameValue(`${ earlier.until(later, { - smallestUnit: "minutes", - roundingMode: "halfExpand" -}) }`, "PT26436596M"); -var largestUnit = "hours"; - -// rounds to an increment of hours -assert.sameValue(`${ earlier.until(later, { - largestUnit, - smallestUnit: "hours", - roundingIncrement: 4, - roundingMode: "halfExpand" -}) }`, "PT440608H"); - -// rounds to an increment of minutes -assert.sameValue(`${ earlier.until(later, { - largestUnit, - smallestUnit: "minutes", - roundingIncrement: 30, - roundingMode: "halfExpand" -}) }`, "PT440610H"); - -// rounds to an increment of seconds -assert.sameValue(`${ earlier.until(later, { - largestUnit, - smallestUnit: "seconds", - roundingIncrement: 15, - roundingMode: "halfExpand" -}) }`, "PT440609H56M"); - -// rounds to an increment of milliseconds -assert.sameValue(`${ earlier.until(later, { - largestUnit, - smallestUnit: "milliseconds", - roundingIncrement: 10, - roundingMode: "halfExpand" -}) }`, "PT440609H56M3.15S"); - -// rounds to an increment of microseconds -assert.sameValue(`${ earlier.until(later, { - largestUnit, - smallestUnit: "microseconds", - roundingIncrement: 10, - roundingMode: "halfExpand" -}) }`, "PT440609H56M3.14853S"); - -// rounds to an increment of nanoseconds -assert.sameValue(`${ earlier.until(later, { - largestUnit, - smallestUnit: "nanoseconds", - roundingIncrement: 10, - roundingMode: "halfExpand" -}) }`, "PT440609H56M3.14852931S"); - -// valid hour increments divide into 24 -[ - 1, - 2, - 3, - 4, - 6, - 8, - 12 -].forEach(roundingIncrement => { - var options = { - largestUnit, - smallestUnit: "hours", - roundingIncrement - }; - assert(earlier.until(later, options) instanceof Temporal.Duration); -}); - -// valid increments divide into 60 -[ - "minutes", - "seconds" -].forEach(smallestUnit => { - [ - 1, - 2, - 3, - 4, - 5, - 6, - 10, - 12, - 15, - 20, - 30 - ].forEach(roundingIncrement => { - var options = { - largestUnit, - smallestUnit, - roundingIncrement - }; - assert(earlier.until(later, options) instanceof Temporal.Duration); - }); -}); - -// valid increments divide into 1000 -[ - "milliseconds", - "microseconds", - "nanoseconds" -].forEach(smallestUnit => { - [ - 1, - 2, - 4, - 5, - 8, - 10, - 20, - 25, - 40, - 50, - 100, - 125, - 200, - 250, - 500 - ].forEach(roundingIncrement => { - var options = { - largestUnit, - smallestUnit, - roundingIncrement - }; - assert(earlier.until(later, options) instanceof Temporal.Duration); - }); -}); - -// throws on increments that do not divide evenly into the next highest -assert.throws(RangeError, () => earlier.until(later, { - largestUnit, - smallestUnit: "hours", - roundingIncrement: 11 -})); -assert.throws(RangeError, () => earlier.until(later, { - largestUnit, - smallestUnit: "minutes", - roundingIncrement: 29 -})); -assert.throws(RangeError, () => earlier.until(later, { - largestUnit, - smallestUnit: "seconds", - roundingIncrement: 29 -})); -assert.throws(RangeError, () => earlier.until(later, { - largestUnit, - smallestUnit: "milliseconds", - roundingIncrement: 29 -})); -assert.throws(RangeError, () => earlier.until(later, { - largestUnit, - smallestUnit: "microseconds", - roundingIncrement: 29 -})); -assert.throws(RangeError, () => earlier.until(later, { - largestUnit, - smallestUnit: "nanoseconds", - roundingIncrement: 29 -})); - -// throws on increments that are equal to the next highest -assert.throws(RangeError, () => earlier.until(later, { - largestUnit, - smallestUnit: "hours", - roundingIncrement: 24 -})); -assert.throws(RangeError, () => earlier.until(later, { - largestUnit, - smallestUnit: "minutes", - roundingIncrement: 60 -})); -assert.throws(RangeError, () => earlier.until(later, { - largestUnit, - smallestUnit: "seconds", - roundingIncrement: 60 -})); -assert.throws(RangeError, () => earlier.until(later, { - largestUnit, - smallestUnit: "milliseconds", - roundingIncrement: 1000 -})); -assert.throws(RangeError, () => earlier.until(later, { - largestUnit, - smallestUnit: "microseconds", - roundingIncrement: 1000 -})); -assert.throws(RangeError, () => earlier.until(later, { - largestUnit, - smallestUnit: "nanoseconds", - roundingIncrement: 1000 -}));