diff --git a/test/staging/Temporal/Instant/old/add.js b/test/staging/Temporal/Instant/old/add.js new file mode 100644 index 0000000000..0141f4af6c --- /dev/null +++ b/test/staging/Temporal/Instant/old/add.js @@ -0,0 +1,32 @@ +// 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/compare.js b/test/staging/Temporal/Instant/old/compare.js new file mode 100644 index 0000000000..2534bf6245 --- /dev/null +++ b/test/staging/Temporal/Instant/old/compare.js @@ -0,0 +1,30 @@ +// 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.compare works +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"); + +// pre epoch equal +assert.sameValue(Temporal.Instant.compare(i1, Temporal.Instant.from(i1)), 0) + +// epoch equal +assert.sameValue(Temporal.Instant.compare(i2, Temporal.Instant.from(i2)), 0) + +// cross epoch smaller/larger +assert.sameValue(Temporal.Instant.compare(i1, i2), -1) + +// cross epoch larger/smaller +assert.sameValue(Temporal.Instant.compare(i2, i1), 1) + +// epoch smaller/larger +assert.sameValue(Temporal.Instant.compare(i2, i3), -1) + +// epoch larger/smaller +assert.sameValue(Temporal.Instant.compare(i3, i2), 1) diff --git a/test/staging/Temporal/Instant/old/equals.js b/test/staging/Temporal/Instant/old/equals.js new file mode 100644 index 0000000000..0bdbe1b848 --- /dev/null +++ b/test/staging/Temporal/Instant/old/equals.js @@ -0,0 +1,24 @@ +// 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.equals works +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"); + +// pre epoch equal +assert(i1.equals(i1)) + +// epoch equal +assert(i2.equals(i2)) + +// cross epoch unequal +assert(!i1.equals(i2)) + +// epoch unequal +assert(!i2.equals(i3)) diff --git a/test/staging/Temporal/Instant/old/limits.js b/test/staging/Temporal/Instant/old/limits.js new file mode 100644 index 0000000000..408bbce1ca --- /dev/null +++ b/test/staging/Temporal/Instant/old/limits.js @@ -0,0 +1,30 @@ +// 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"); + +// converting from DateTime +var min = Temporal.PlainDateTime.from("-271821-04-19T00:00:00.000000001"); +var max = Temporal.PlainDateTime.from("+275760-09-13T23:59:59.999999999"); +var utc = Temporal.TimeZone.from("UTC"); +assert.throws(RangeError, () => utc.getInstantFor(min)); +assert.throws(RangeError, () => utc.getInstantFor(max)); diff --git a/test/staging/Temporal/Instant/old/round.js b/test/staging/Temporal/Instant/old/round.js new file mode 100644 index 0000000000..43882c7344 --- /dev/null +++ b/test/staging/Temporal/Instant/old/round.js @@ -0,0 +1,272 @@ +// 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" +})); + +// halfExpand +var incrementOneNearest = [ + [ + "hour", + "1976-11-18T14:00:00Z" + ], + [ + "minute", + "1976-11-18T14:24:00Z" + ], + [ + "second", + "1976-11-18T14:23:30Z" + ], + [ + "millisecond", + "1976-11-18T14:23:30.123Z" + ], + [ + "microsecond", + "1976-11-18T14:23:30.123457Z" + ], + [ + "nanosecond", + "1976-11-18T14:23:30.123456789Z" + ] +]; +incrementOneNearest.forEach(([smallestUnit, expected]) => { + assert.sameValue(`${ inst.round({ + smallestUnit, + roundingMode: "halfExpand" + }) }`, expected); +}); + +// ceil +var incrementOneCeil = [ + [ + "hour", + "1976-11-18T15:00:00Z" + ], + [ + "minute", + "1976-11-18T14:24:00Z" + ], + [ + "second", + "1976-11-18T14:23:31Z" + ], + [ + "millisecond", + "1976-11-18T14:23:30.124Z" + ], + [ + "microsecond", + "1976-11-18T14:23:30.123457Z" + ], + [ + "nanosecond", + "1976-11-18T14:23:30.123456789Z" + ] +]; +incrementOneCeil.forEach(([smallestUnit, expected]) => { + assert.sameValue(`${ inst.round({ + smallestUnit, + roundingMode: "ceil" + }) }`, expected); +}); + +// floor +var incrementOneFloor = [ + [ + "hour", + "1976-11-18T14:00:00Z" + ], + [ + "minute", + "1976-11-18T14:23:00Z" + ], + [ + "second", + "1976-11-18T14:23:30Z" + ], + [ + "millisecond", + "1976-11-18T14:23:30.123Z" + ], + [ + "microsecond", + "1976-11-18T14:23:30.123456Z" + ], + [ + "nanosecond", + "1976-11-18T14:23:30.123456789Z" + ] +]; +incrementOneFloor.forEach(([smallestUnit, expected]) => { + assert.sameValue(`${ inst.round({ + smallestUnit, + roundingMode: "floor" + }) }`, expected); +}); + +// trunc +var incrementOneFloor = [ + [ + "hour", + "1976-11-18T14:00:00Z" + ], + [ + "minute", + "1976-11-18T14:23:00Z" + ], + [ + "second", + "1976-11-18T14:23:30Z" + ], + [ + "millisecond", + "1976-11-18T14:23:30.123Z" + ], + [ + "microsecond", + "1976-11-18T14:23:30.123456Z" + ], + [ + "nanosecond", + "1976-11-18T14:23:30.123456789Z" + ] +]; +incrementOneFloor.forEach(([smallestUnit, expected]) => { + assert.sameValue(`${ inst.round({ + smallestUnit, + roundingMode: "trunc" + }) }`, expected); +}); + +// 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); +assert.sameValue(`${ inst.round({ + smallestUnit: "microsecond", + roundingIncrement: 86400000000 +}) }`, expected); +assert.sameValue(`${ inst.round({ + smallestUnit: "nanosecond", + roundingIncrement: 86400000000000 +}) }`, 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 new file mode 100644 index 0000000000..39314d43d2 --- /dev/null +++ b/test/staging/Temporal/Instant/old/since.js @@ -0,0 +1,422 @@ +// 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"; + +// halfExpand +var roundingMode = "halfExpand"; +var incrementOneNearest = [ + [ + "hours", + "PT376435H" + ], + [ + "minutes", + "PT376435H23M" + ], + [ + "seconds", + "PT376435H23M8S" + ], + [ + "milliseconds", + "PT376435H23M8.149S" + ], + [ + "microseconds", + "PT376435H23M8.148529S" + ], + [ + "nanoseconds", + "PT376435H23M8.148529313S" + ] +]; +incrementOneNearest.forEach(([smallestUnit, expected]) => { + assert.sameValue(`${ later.since(earlier, { + largestUnit, + smallestUnit, + roundingMode + }) }`, expected); + assert.sameValue(`${ earlier.since(later, { + largestUnit, + smallestUnit, + roundingMode + }) }`, `-${ expected }`); +}); + +// ceil +var roundingMode = "ceil"; +var incrementOneCeil = [ + [ + "hours", + "PT376436H", + "-PT376435H" + ], + [ + "minutes", + "PT376435H24M", + "-PT376435H23M" + ], + [ + "seconds", + "PT376435H23M9S", + "-PT376435H23M8S" + ], + [ + "milliseconds", + "PT376435H23M8.149S", + "-PT376435H23M8.148S" + ], + [ + "microseconds", + "PT376435H23M8.14853S", + "-PT376435H23M8.148529S" + ], + [ + "nanoseconds", + "PT376435H23M8.148529313S", + "-PT376435H23M8.148529313S" + ] +]; +incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + assert.sameValue(`${ later.since(earlier, { + largestUnit, + smallestUnit, + roundingMode + }) }`, expectedPositive); + assert.sameValue(`${ earlier.since(later, { + largestUnit, + smallestUnit, + roundingMode + }) }`, expectedNegative); +}); + +// floor +var roundingMode = "floor"; +var incrementOneFloor = [ + [ + "hours", + "PT376435H", + "-PT376436H" + ], + [ + "minutes", + "PT376435H23M", + "-PT376435H24M" + ], + [ + "seconds", + "PT376435H23M8S", + "-PT376435H23M9S" + ], + [ + "milliseconds", + "PT376435H23M8.148S", + "-PT376435H23M8.149S" + ], + [ + "microseconds", + "PT376435H23M8.148529S", + "-PT376435H23M8.14853S" + ], + [ + "nanoseconds", + "PT376435H23M8.148529313S", + "-PT376435H23M8.148529313S" + ] +]; +incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + assert.sameValue(`${ later.since(earlier, { + largestUnit, + smallestUnit, + roundingMode + }) }`, expectedPositive); + assert.sameValue(`${ earlier.since(later, { + largestUnit, + smallestUnit, + roundingMode + }) }`, expectedNegative); +}); + +// trunc +var roundingMode = "trunc"; +var incrementOneTrunc = [ + [ + "hours", + "PT376435H" + ], + [ + "minutes", + "PT376435H23M" + ], + [ + "seconds", + "PT376435H23M8S" + ], + [ + "milliseconds", + "PT376435H23M8.148S" + ], + [ + "microseconds", + "PT376435H23M8.148529S" + ], + [ + "nanoseconds", + "PT376435H23M8.148529313S" + ] +]; +incrementOneTrunc.forEach(([smallestUnit, expected]) => { + assert.sameValue(`${ later.since(earlier, { + largestUnit, + smallestUnit, + roundingMode + }) }`, expected); + assert.sameValue(`${ earlier.since(later, { + largestUnit, + smallestUnit, + roundingMode + }) }`, `-${ expected }`); +}); + +// 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/toZonedDateTime.js b/test/staging/Temporal/Instant/old/toZonedDateTime.js new file mode 100644 index 0000000000..a538f1d4ff --- /dev/null +++ b/test/staging/Temporal/Instant/old/toZonedDateTime.js @@ -0,0 +1,34 @@ +// 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.toZonedDateTime() works +features: [Temporal] +---*/ + +var inst = Temporal.Instant.from("1976-11-18T14:23:30.123456789Z"); + +// throws without parameter +assert.throws(TypeError, () => inst.toZonedDateTime()); + +// throws with a string parameter +assert.throws(TypeError, () => inst.toZonedDateTime("Asia/Singapore")); + +// time zone parameter UTC +var timeZone = Temporal.TimeZone.from("UTC"); +var zdt = inst.toZonedDateTime({ + timeZone, + calendar: "gregory" +}); +assert.sameValue(inst.epochNanoseconds, zdt.epochNanoseconds); +assert.sameValue(`${ zdt }`, "1976-11-18T14:23:30.123456789+00:00[UTC][u-ca=gregory]"); + +// time zone parameter non-UTC +var timeZone = Temporal.TimeZone.from("America/New_York"); +var zdt = inst.toZonedDateTime({ + timeZone, + calendar: "gregory" +}); +assert.sameValue(inst.epochNanoseconds, zdt.epochNanoseconds); +assert.sameValue(`${ zdt }`, "1976-11-18T09:23:30.123456789-05:00[America/New_York][u-ca=gregory]"); diff --git a/test/staging/Temporal/Instant/old/toZonedDateTimeISO.js b/test/staging/Temporal/Instant/old/toZonedDateTimeISO.js new file mode 100644 index 0000000000..61de7de3c4 --- /dev/null +++ b/test/staging/Temporal/Instant/old/toZonedDateTimeISO.js @@ -0,0 +1,25 @@ +// 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(RangeError, () => inst.toZonedDateTimeISO()); + +// time zone parameter UTC +var tz = Temporal.TimeZone.from("UTC"); +var zdt = inst.toZonedDateTimeISO(tz); +assert.sameValue(inst.epochNanoseconds, zdt.epochNanoseconds); +assert.sameValue(`${ zdt }`, "1976-11-18T14:23:30.123456789+00:00[UTC]"); + +// time zone parameter non-UTC +var tz = Temporal.TimeZone.from("America/New_York"); +var zdt = inst.toZonedDateTimeISO(tz); +assert.sameValue(inst.epochNanoseconds, zdt.epochNanoseconds); +assert.sameValue(`${ zdt }`, "1976-11-18T09:23:30.123456789-05:00[America/New_York]"); diff --git a/test/staging/Temporal/Instant/old/until.js b/test/staging/Temporal/Instant/old/until.js new file mode 100644 index 0000000000..04ee8804b9 --- /dev/null +++ b/test/staging/Temporal/Instant/old/until.js @@ -0,0 +1,422 @@ +// 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"; + +// halfExpand +var roundingMode = "halfExpand"; +var incrementOneNearest = [ + [ + "hours", + "PT440610H" + ], + [ + "minutes", + "PT440609H56M" + ], + [ + "seconds", + "PT440609H56M3S" + ], + [ + "milliseconds", + "PT440609H56M3.149S" + ], + [ + "microseconds", + "PT440609H56M3.148529S" + ], + [ + "nanoseconds", + "PT440609H56M3.148529313S" + ] +]; +incrementOneNearest.forEach(([smallestUnit, expected]) => { + assert.sameValue(`${ earlier.until(later, { + largestUnit, + smallestUnit, + roundingMode + }) }`, expected); + assert.sameValue(`${ later.until(earlier, { + largestUnit, + smallestUnit, + roundingMode + }) }`, `-${ expected }`); +}); + +// ceil +var roundingMode = "ceil"; +var incrementOneCeil = [ + [ + "hours", + "PT440610H", + "-PT440609H" + ], + [ + "minutes", + "PT440609H57M", + "-PT440609H56M" + ], + [ + "seconds", + "PT440609H56M4S", + "-PT440609H56M3S" + ], + [ + "milliseconds", + "PT440609H56M3.149S", + "-PT440609H56M3.148S" + ], + [ + "microseconds", + "PT440609H56M3.14853S", + "-PT440609H56M3.148529S" + ], + [ + "nanoseconds", + "PT440609H56M3.148529313S", + "-PT440609H56M3.148529313S" + ] +]; +incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + assert.sameValue(`${ earlier.until(later, { + largestUnit, + smallestUnit, + roundingMode + }) }`, expectedPositive); + assert.sameValue(`${ later.until(earlier, { + largestUnit, + smallestUnit, + roundingMode + }) }`, expectedNegative); +}); + +// floor +var roundingMode = "floor"; +var incrementOneFloor = [ + [ + "hours", + "PT440609H", + "-PT440610H" + ], + [ + "minutes", + "PT440609H56M", + "-PT440609H57M" + ], + [ + "seconds", + "PT440609H56M3S", + "-PT440609H56M4S" + ], + [ + "milliseconds", + "PT440609H56M3.148S", + "-PT440609H56M3.149S" + ], + [ + "microseconds", + "PT440609H56M3.148529S", + "-PT440609H56M3.14853S" + ], + [ + "nanoseconds", + "PT440609H56M3.148529313S", + "-PT440609H56M3.148529313S" + ] +]; +incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + assert.sameValue(`${ earlier.until(later, { + largestUnit, + smallestUnit, + roundingMode + }) }`, expectedPositive); + assert.sameValue(`${ later.until(earlier, { + largestUnit, + smallestUnit, + roundingMode + }) }`, expectedNegative); +}); + +// trunc +var roundingMode = "trunc"; +var incrementOneTrunc = [ + [ + "hours", + "PT440609H" + ], + [ + "minutes", + "PT440609H56M" + ], + [ + "seconds", + "PT440609H56M3S" + ], + [ + "milliseconds", + "PT440609H56M3.148S" + ], + [ + "microseconds", + "PT440609H56M3.148529S" + ], + [ + "nanoseconds", + "PT440609H56M3.148529313S" + ] +]; +incrementOneTrunc.forEach(([smallestUnit, expected]) => { + assert.sameValue(`${ earlier.until(later, { + largestUnit, + smallestUnit, + roundingMode + }) }`, expected); + assert.sameValue(`${ later.until(earlier, { + largestUnit, + smallestUnit, + roundingMode + }) }`, `-${ expected }`); +}); + +// 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 +}));