diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-expand.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-expand.js new file mode 100644 index 0000000000..cba03c21e1 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-expand.js @@ -0,0 +1,42 @@ +// 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.round +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987); +const relativeTo = new Temporal.PlainDate(2020, 1, 1); + +const expected = [ + ["years", [6], [-6]], + ["months", [5, 8], [-5, -8]], + ["weeks", [5, 6, 9], [-5, -6, -9]], + ["days", [5, 6, 7, 10], [-5, -6, -7, -10]], + ["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]], + ["minutes", [5, 6, 7, 9, 16, 31], [-5, -6, -7, -9, -16, -31]], + ["seconds", [5, 6, 7, 9, 16, 30, 21], [-5, -6, -7, -9, -16, -30, -21]], + ["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]], + ["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]], + ["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + instance.round({ smallestUnit, relativeTo, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + instance.negated().round({ smallestUnit, relativeTo, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfCeil.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfCeil.js new file mode 100644 index 0000000000..23d3ec7659 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfCeil.js @@ -0,0 +1,42 @@ +// 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.round +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987); +const relativeTo = new Temporal.PlainDate(2020, 1, 1); + +const expected = [ + ["years", [6], [-6]], + ["months", [5, 8], [-5, -8]], + ["weeks", [5, 6, 8], [-5, -6, -8]], + ["days", [5, 6, 7, 10], [-5, -6, -7, -10]], + ["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]], + ["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]], + ["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]], + ["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]], + ["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]], + ["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + instance.round({ smallestUnit, relativeTo, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + instance.negated().round({ smallestUnit, relativeTo, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfEven.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfEven.js new file mode 100644 index 0000000000..18530749a3 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfEven.js @@ -0,0 +1,42 @@ +// 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.round +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987); +const relativeTo = new Temporal.PlainDate(2020, 1, 1); + +const expected = [ + ["years", [6], [-6]], + ["months", [5, 8], [-5, -8]], + ["weeks", [5, 6, 8], [-5, -6, -8]], + ["days", [5, 6, 7, 10], [-5, -6, -7, -10]], + ["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]], + ["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]], + ["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]], + ["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]], + ["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]], + ["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + instance.round({ smallestUnit, relativeTo, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + instance.negated().round({ smallestUnit, relativeTo, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfFloor.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfFloor.js new file mode 100644 index 0000000000..1c198d6d91 --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfFloor.js @@ -0,0 +1,42 @@ +// 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.round +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987); +const relativeTo = new Temporal.PlainDate(2020, 1, 1); + +const expected = [ + ["years", [6], [-6]], + ["months", [5, 8], [-5, -8]], + ["weeks", [5, 6, 8], [-5, -6, -8]], + ["days", [5, 6, 7, 10], [-5, -6, -7, -10]], + ["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]], + ["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]], + ["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]], + ["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]], + ["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]], + ["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + instance.round({ smallestUnit, relativeTo, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + instance.negated().round({ smallestUnit, relativeTo, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfTrunc.js b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..006d1b133f --- /dev/null +++ b/test/built-ins/Temporal/Duration/prototype/round/roundingmode-halfTrunc.js @@ -0,0 +1,42 @@ +// 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.round +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.Duration(5, 6, 7, 8, 40, 30, 20, 123, 500, 987); +const relativeTo = new Temporal.PlainDate(2020, 1, 1); + +const expected = [ + ["years", [6], [-6]], + ["months", [5, 8], [-5, -8]], + ["weeks", [5, 6, 8], [-5, -6, -8]], + ["days", [5, 6, 7, 10], [-5, -6, -7, -10]], + ["hours", [5, 6, 7, 9, 17], [-5, -6, -7, -9, -17]], + ["minutes", [5, 6, 7, 9, 16, 30], [-5, -6, -7, -9, -16, -30]], + ["seconds", [5, 6, 7, 9, 16, 30, 20], [-5, -6, -7, -9, -16, -30, -20]], + ["milliseconds", [5, 6, 7, 9, 16, 30, 20, 124], [-5, -6, -7, -9, -16, -30, -20, -124]], + ["microseconds", [5, 6, 7, 9, 16, 30, 20, 123, 501], [-5, -6, -7, -9, -16, -30, -20, -123, -501]], + ["nanoseconds", [5, 6, 7, 9, 16, 30, 20, 123, 500, 987], [-5, -6, -7, -9, -16, -30, -20, -123, -500, -987]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + instance.round({ smallestUnit, relativeTo, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + instance.negated().round({ smallestUnit, relativeTo, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/round/roundingmode-expand.js b/test/built-ins/Temporal/Instant/prototype/round/roundingmode-expand.js new file mode 100644 index 0000000000..97bc621dda --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/roundingmode-expand.js @@ -0,0 +1,29 @@ +// 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.round +description: Tests calculations with roundingMode "expand". +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */); + +const expected = [ + ["hour", 217177200_000_000_000n /* 1976-11-18T15:00:00Z */], + ["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */], + ["second", 217175011_000_000_000n /* 1976-11-18T14:23:31Z */], + ["millisecond", 217175010_124_000_000n /* 1976-11-18T14:23:30.124Z */], + ["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */], + ["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expected]) => { + assert.sameValue( + instance.round({ smallestUnit, roundingMode }).epochNanoseconds, + expected, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfCeil.js b/test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfCeil.js new file mode 100644 index 0000000000..af6e5dd3f3 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfCeil.js @@ -0,0 +1,29 @@ +// 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.round +description: Tests calculations with roundingMode "halfCeil". +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */); + +const expected = [ + ["hour", 217173600_000_000_000n /* 1976-11-18T14:00:00Z */], + ["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */], + ["second", 217175010_000_000_000n /* 1976-11-18T14:23:30Z */], + ["millisecond", 217175010_123_000_000n /* 1976-11-18T14:23:30.123Z */], + ["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */], + ["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expected]) => { + assert.sameValue( + instance.round({ smallestUnit, roundingMode }).epochNanoseconds, + expected, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfEven.js b/test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfEven.js new file mode 100644 index 0000000000..9a50ba0eed --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfEven.js @@ -0,0 +1,29 @@ +// 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.round +description: Tests calculations with roundingMode "halfEven". +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */); + +const expected = [ + ["hour", 217173600_000_000_000n /* 1976-11-18T14:00:00Z */], + ["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */], + ["second", 217175010_000_000_000n /* 1976-11-18T14:23:30Z */], + ["millisecond", 217175010_123_000_000n /* 1976-11-18T14:23:30.123Z */], + ["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */], + ["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expected]) => { + assert.sameValue( + instance.round({ smallestUnit, roundingMode }).epochNanoseconds, + expected, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfFloor.js b/test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfFloor.js new file mode 100644 index 0000000000..56ae1d0d7d --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfFloor.js @@ -0,0 +1,29 @@ +// 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.round +description: Tests calculations with roundingMode "halfFloor". +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */); + +const expected = [ + ["hour", 217173600_000_000_000n /* 1976-11-18T14:00:00Z */], + ["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */], + ["second", 217175010_000_000_000n /* 1976-11-18T14:23:30Z */], + ["millisecond", 217175010_123_000_000n /* 1976-11-18T14:23:30.123Z */], + ["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */], + ["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expected]) => { + assert.sameValue( + instance.round({ smallestUnit, roundingMode }).epochNanoseconds, + expected, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfTrunc.js b/test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..be654781a6 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/round/roundingmode-halfTrunc.js @@ -0,0 +1,29 @@ +// 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.round +description: Tests calculations with roundingMode "halfTrunc". +features: [Temporal] +---*/ + +const instance = new Temporal.Instant(217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */); + +const expected = [ + ["hour", 217173600_000_000_000n /* 1976-11-18T14:00:00Z */], + ["minute", 217175040_000_000_000n /* 1976-11-18T14:24:00Z */], + ["second", 217175010_000_000_000n /* 1976-11-18T14:23:30Z */], + ["millisecond", 217175010_123_000_000n /* 1976-11-18T14:23:30.123Z */], + ["microsecond", 217175010_123_457_000n /* 1976-11-18T14:23:30.123457Z */], + ["nanosecond", 217175010_123_456_789n /* 1976-11-18T14:23:30.123456789Z */], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expected]) => { + assert.sameValue( + instance.round({ smallestUnit, roundingMode }).epochNanoseconds, + expected, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/since/roundingmode-expand.js b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-expand.js new file mode 100644 index 0000000000..95d7154ba8 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-expand.js @@ -0,0 +1,39 @@ +// 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: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.Instant(217178610_123_456_789n); +const later = new Temporal.Instant(1572345998_271_986_102n); + +const expected = [ + ["hours", [0, 0, 0, 0, 376436], [0, 0, 0, 0, -376436]], + ["minutes", [0, 0, 0, 0, 376435, 24], [0, 0, 0, 0, -376435, -24]], + ["seconds", [0, 0, 0, 0, 376435, 23, 9], [0, 0, 0, 0, -376435, -23, -9]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -149]], + ["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 530], [0, 0, 0, 0, -376435, -23, -8, -148, -530]], + ["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]], +]; + +const roundingMode = "expand"; +const largestUnit = "hours"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { largestUnit, smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { largestUnit, smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfCeil.js b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfCeil.js new file mode 100644 index 0000000000..4741f24a7c --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfCeil.js @@ -0,0 +1,39 @@ +// 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: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.Instant(217178610_123_456_789n); +const later = new Temporal.Instant(1572345998_271_986_102n); + +const expected = [ + ["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376435]], + ["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -23]], + ["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -8]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -149]], + ["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -529]], + ["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]], +]; + +const roundingMode = "halfCeil"; +const largestUnit = "hours"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { largestUnit, smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { largestUnit, smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfEven.js b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfEven.js new file mode 100644 index 0000000000..c1b105ef72 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfEven.js @@ -0,0 +1,39 @@ +// 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: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.Instant(217178610_123_456_789n); +const later = new Temporal.Instant(1572345998_271_986_102n); + +const expected = [ + ["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376435]], + ["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -23]], + ["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -8]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -149]], + ["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -529]], + ["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]], +]; + +const roundingMode = "halfEven"; +const largestUnit = "hours"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { largestUnit, smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { largestUnit, smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfFloor.js b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfFloor.js new file mode 100644 index 0000000000..3a9fa6cfd2 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfFloor.js @@ -0,0 +1,39 @@ +// 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: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.Instant(217178610_123_456_789n); +const later = new Temporal.Instant(1572345998_271_986_102n); + +const expected = [ + ["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376435]], + ["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -23]], + ["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -8]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -149]], + ["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -529]], + ["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]], +]; + +const roundingMode = "halfFloor"; +const largestUnit = "hours"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { largestUnit, smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { largestUnit, smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfTrunc.js b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..2a8722894d --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfTrunc.js @@ -0,0 +1,39 @@ +// 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: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.Instant(217178610_123_456_789n); +const later = new Temporal.Instant(1572345998_271_986_102n); + +const expected = [ + ["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376435]], + ["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -23]], + ["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -8]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -149]], + ["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -529]], + ["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]], +]; + +const roundingMode = "halfTrunc"; +const largestUnit = "hours"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { largestUnit, smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { largestUnit, smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-expand.js b/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-expand.js new file mode 100644 index 0000000000..5866f2ac5d --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-expand.js @@ -0,0 +1,37 @@ +// 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.tostring +description: expand value for roundingMode option +features: [Temporal] +---*/ + +const instant = new Temporal.Instant(1_000_000_000_123_987_500n); + +const result1 = instant.toString({ smallestUnit: "microsecond", roundingMode: "expand" }); +assert.sameValue(result1, "2001-09-09T01:46:40.123988Z", + "roundingMode is expand (with 6 digits from smallestUnit)"); + +const result2 = instant.toString({ fractionalSecondDigits: 6, roundingMode: "expand" }); +assert.sameValue(result2, "2001-09-09T01:46:40.123988Z", + "roundingMode is expand (with 6 digits from fractionalSecondDigits)"); + +const result3 = instant.toString({ smallestUnit: "millisecond", roundingMode: "expand" }); +assert.sameValue(result3, "2001-09-09T01:46:40.124Z", + "roundingMode is expand (with 3 digits from smallestUnit)"); + +const result4 = instant.toString({ fractionalSecondDigits: 3, roundingMode: "expand" }); +assert.sameValue(result4, "2001-09-09T01:46:40.124Z", + "roundingMode is expand (with 3 digits from fractionalSecondDigits)"); + +const result5 = instant.toString({ smallestUnit: "second", roundingMode: "expand" }); +assert.sameValue(result5, "2001-09-09T01:46:41Z", + "roundingMode is expand (with 0 digits from smallestUnit)"); + +const result6 = instant.toString({ fractionalSecondDigits: 0, roundingMode: "expand" }); +assert.sameValue(result6, "2001-09-09T01:46:41Z", + "roundingMode is expand (with 0 digits from fractionalSecondDigits)"); + +const result7 = instant.toString({ smallestUnit: "minute", roundingMode: "expand" }); +assert.sameValue(result7, "2001-09-09T01:47Z", "roundingMode is expand (round to minute)"); diff --git a/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfCeil.js b/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfCeil.js new file mode 100644 index 0000000000..0e82bc95bb --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfCeil.js @@ -0,0 +1,37 @@ +// 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.tostring +description: halfCeil value for roundingMode option +features: [Temporal] +---*/ + +const instant = new Temporal.Instant(1_000_000_000_123_987_500n); + +const result1 = instant.toString({ smallestUnit: "microsecond", roundingMode: "halfCeil" }); +assert.sameValue(result1, "2001-09-09T01:46:40.123988Z", + "roundingMode is halfCeil (with 6 digits from smallestUnit)"); + +const result2 = instant.toString({ fractionalSecondDigits: 6, roundingMode: "halfCeil" }); +assert.sameValue(result2, "2001-09-09T01:46:40.123988Z", + "roundingMode is halfCeil (with 6 digits from fractionalSecondDigits)"); + +const result3 = instant.toString({ smallestUnit: "millisecond", roundingMode: "halfCeil" }); +assert.sameValue(result3, "2001-09-09T01:46:40.124Z", + "roundingMode is halfCeil (with 3 digits from smallestUnit)"); + +const result4 = instant.toString({ fractionalSecondDigits: 3, roundingMode: "halfCeil" }); +assert.sameValue(result4, "2001-09-09T01:46:40.124Z", + "roundingMode is halfCeil (with 3 digits from fractionalSecondDigits)"); + +const result5 = instant.toString({ smallestUnit: "second", roundingMode: "halfCeil" }); +assert.sameValue(result5, "2001-09-09T01:46:40Z", + "roundingMode is halfCeil (with 0 digits from smallestUnit)"); + +const result6 = instant.toString({ fractionalSecondDigits: 0, roundingMode: "halfCeil" }); +assert.sameValue(result6, "2001-09-09T01:46:40Z", + "roundingMode is halfCeil (with 0 digits from fractionalSecondDigits)"); + +const result7 = instant.toString({ smallestUnit: "minute", roundingMode: "halfCeil" }); +assert.sameValue(result7, "2001-09-09T01:47Z", "roundingMode is halfCeil (round to minute)"); diff --git a/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfEven.js b/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfEven.js new file mode 100644 index 0000000000..2638ffb87b --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfEven.js @@ -0,0 +1,37 @@ +// 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.tostring +description: halfEven value for roundingMode option +features: [Temporal] +---*/ + +const instant = new Temporal.Instant(1_000_000_000_123_987_500n); + +const result1 = instant.toString({ smallestUnit: "microsecond", roundingMode: "halfEven" }); +assert.sameValue(result1, "2001-09-09T01:46:40.123988Z", + "roundingMode is halfEven (with 6 digits from smallestUnit)"); + +const result2 = instant.toString({ fractionalSecondDigits: 6, roundingMode: "halfEven" }); +assert.sameValue(result2, "2001-09-09T01:46:40.123988Z", + "roundingMode is halfEven (with 6 digits from fractionalSecondDigits)"); + +const result3 = instant.toString({ smallestUnit: "millisecond", roundingMode: "halfEven" }); +assert.sameValue(result3, "2001-09-09T01:46:40.124Z", + "roundingMode is halfEven (with 3 digits from smallestUnit)"); + +const result4 = instant.toString({ fractionalSecondDigits: 3, roundingMode: "halfEven" }); +assert.sameValue(result4, "2001-09-09T01:46:40.124Z", + "roundingMode is halfEven (with 3 digits from fractionalSecondDigits)"); + +const result5 = instant.toString({ smallestUnit: "second", roundingMode: "halfEven" }); +assert.sameValue(result5, "2001-09-09T01:46:40Z", + "roundingMode is halfEven (with 0 digits from smallestUnit)"); + +const result6 = instant.toString({ fractionalSecondDigits: 0, roundingMode: "halfEven" }); +assert.sameValue(result6, "2001-09-09T01:46:40Z", + "roundingMode is halfEven (with 0 digits from fractionalSecondDigits)"); + +const result7 = instant.toString({ smallestUnit: "minute", roundingMode: "halfEven" }); +assert.sameValue(result7, "2001-09-09T01:47Z", "roundingMode is halfEven (round to minute)"); diff --git a/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfFloor.js b/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfFloor.js new file mode 100644 index 0000000000..abb8283376 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfFloor.js @@ -0,0 +1,37 @@ +// 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.tostring +description: halfFloor value for roundingMode option +features: [Temporal] +---*/ + +const instant = new Temporal.Instant(1_000_000_000_123_987_500n); + +const result1 = instant.toString({ smallestUnit: "microsecond", roundingMode: "halfFloor" }); +assert.sameValue(result1, "2001-09-09T01:46:40.123987Z", + "roundingMode is halfFloor (with 6 digits from smallestUnit)"); + +const result2 = instant.toString({ fractionalSecondDigits: 6, roundingMode: "halfFloor" }); +assert.sameValue(result2, "2001-09-09T01:46:40.123987Z", + "roundingMode is halfFloor (with 6 digits from fractionalSecondDigits)"); + +const result3 = instant.toString({ smallestUnit: "millisecond", roundingMode: "halfFloor" }); +assert.sameValue(result3, "2001-09-09T01:46:40.124Z", + "roundingMode is halfFloor (with 3 digits from smallestUnit)"); + +const result4 = instant.toString({ fractionalSecondDigits: 3, roundingMode: "halfFloor" }); +assert.sameValue(result4, "2001-09-09T01:46:40.124Z", + "roundingMode is halfFloor (with 3 digits from fractionalSecondDigits)"); + +const result5 = instant.toString({ smallestUnit: "second", roundingMode: "halfFloor" }); +assert.sameValue(result5, "2001-09-09T01:46:40Z", + "roundingMode is halfFloor (with 0 digits from smallestUnit)"); + +const result6 = instant.toString({ fractionalSecondDigits: 0, roundingMode: "halfFloor" }); +assert.sameValue(result6, "2001-09-09T01:46:40Z", + "roundingMode is halfFloor (with 0 digits from fractionalSecondDigits)"); + +const result7 = instant.toString({ smallestUnit: "minute", roundingMode: "halfFloor" }); +assert.sameValue(result7, "2001-09-09T01:47Z", "roundingMode is halfFloor (round to minute)"); diff --git a/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfTrunc.js b/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..f4b2461b5a --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toString/roundingmode-halfTrunc.js @@ -0,0 +1,37 @@ +// 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.tostring +description: halfTrunc value for roundingMode option +features: [Temporal] +---*/ + +const instant = new Temporal.Instant(1_000_000_000_123_987_500n); + +const result1 = instant.toString({ smallestUnit: "microsecond", roundingMode: "halfTrunc" }); +assert.sameValue(result1, "2001-09-09T01:46:40.123987Z", + "roundingMode is halfTrunc (with 6 digits from smallestUnit)"); + +const result2 = instant.toString({ fractionalSecondDigits: 6, roundingMode: "halfTrunc" }); +assert.sameValue(result2, "2001-09-09T01:46:40.123987Z", + "roundingMode is halfTrunc (with 6 digits from fractionalSecondDigits)"); + +const result3 = instant.toString({ smallestUnit: "millisecond", roundingMode: "halfTrunc" }); +assert.sameValue(result3, "2001-09-09T01:46:40.124Z", + "roundingMode is halfTrunc (with 3 digits from smallestUnit)"); + +const result4 = instant.toString({ fractionalSecondDigits: 3, roundingMode: "halfTrunc" }); +assert.sameValue(result4, "2001-09-09T01:46:40.124Z", + "roundingMode is halfTrunc (with 3 digits from fractionalSecondDigits)"); + +const result5 = instant.toString({ smallestUnit: "second", roundingMode: "halfTrunc" }); +assert.sameValue(result5, "2001-09-09T01:46:40Z", + "roundingMode is halfTrunc (with 0 digits from smallestUnit)"); + +const result6 = instant.toString({ fractionalSecondDigits: 0, roundingMode: "halfTrunc" }); +assert.sameValue(result6, "2001-09-09T01:46:40Z", + "roundingMode is halfTrunc (with 0 digits from fractionalSecondDigits)"); + +const result7 = instant.toString({ smallestUnit: "minute", roundingMode: "halfTrunc" }); +assert.sameValue(result7, "2001-09-09T01:47Z", "roundingMode is halfTrunc (round to minute)"); diff --git a/test/built-ins/Temporal/Instant/prototype/until/roundingmode-expand.js b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-expand.js new file mode 100644 index 0000000000..47717659db --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-expand.js @@ -0,0 +1,39 @@ +// 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.until +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.Instant(217178610_123_456_789n); +const later = new Temporal.Instant(1572345998_271_986_102n); + +const expected = [ + ["hours", [0, 0, 0, 0, 376436], [0, 0, 0, 0, -376436]], + ["minutes", [0, 0, 0, 0, 376435, 24], [0, 0, 0, 0, -376435, -24]], + ["seconds", [0, 0, 0, 0, 376435, 23, 9], [0, 0, 0, 0, -376435, -23, -9]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -149]], + ["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 530], [0, 0, 0, 0, -376435, -23, -8, -148, -530]], + ["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]], +]; + +const roundingMode = "expand"; +const largestUnit = "hours"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { largestUnit, smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { largestUnit, smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfCeil.js b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfCeil.js new file mode 100644 index 0000000000..03fda5d343 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfCeil.js @@ -0,0 +1,39 @@ +// 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.until +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.Instant(217178610_123_456_789n); +const later = new Temporal.Instant(1572345998_271_986_102n); + +const expected = [ + ["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376435]], + ["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -23]], + ["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -8]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -149]], + ["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -529]], + ["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]], +]; + +const roundingMode = "halfCeil"; +const largestUnit = "hours"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { largestUnit, smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { largestUnit, smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfEven.js b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfEven.js new file mode 100644 index 0000000000..6e05872c1a --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfEven.js @@ -0,0 +1,39 @@ +// 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.until +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.Instant(217178610_123_456_789n); +const later = new Temporal.Instant(1572345998_271_986_102n); + +const expected = [ + ["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376435]], + ["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -23]], + ["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -8]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -149]], + ["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -529]], + ["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]], +]; + +const roundingMode = "halfEven"; +const largestUnit = "hours"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { largestUnit, smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { largestUnit, smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfFloor.js b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfFloor.js new file mode 100644 index 0000000000..fa6bfc8bb4 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfFloor.js @@ -0,0 +1,39 @@ +// 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.until +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.Instant(217178610_123_456_789n); +const later = new Temporal.Instant(1572345998_271_986_102n); + +const expected = [ + ["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376435]], + ["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -23]], + ["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -8]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -149]], + ["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -529]], + ["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]], +]; + +const roundingMode = "halfFloor"; +const largestUnit = "hours"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { largestUnit, smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { largestUnit, smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfTrunc.js b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..14c078cd68 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfTrunc.js @@ -0,0 +1,39 @@ +// 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.until +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.Instant(217178610_123_456_789n); +const later = new Temporal.Instant(1572345998_271_986_102n); + +const expected = [ + ["hours", [0, 0, 0, 0, 376435], [0, 0, 0, 0, -376435]], + ["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -23]], + ["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -8]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -149]], + ["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529], [0, 0, 0, 0, -376435, -23, -8, -148, -529]], + ["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]], +]; + +const roundingMode = "halfTrunc"; +const largestUnit = "hours"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { largestUnit, smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { largestUnit, smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-expand.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-expand.js new file mode 100644 index 0000000000..d46e18a1cd --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-expand.js @@ -0,0 +1,36 @@ +// 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.plaindate.prototype.since +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfCeil.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfCeil.js new file mode 100644 index 0000000000..8601af318d --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfCeil.js @@ -0,0 +1,36 @@ +// 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.plaindate.prototype.since +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfEven.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfEven.js new file mode 100644 index 0000000000..aac877632b --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfEven.js @@ -0,0 +1,36 @@ +// 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.plaindate.prototype.since +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfFloor.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfFloor.js new file mode 100644 index 0000000000..85147077f4 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfFloor.js @@ -0,0 +1,36 @@ +// 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.plaindate.prototype.since +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfTrunc.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..a8cf1250af --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfTrunc.js @@ -0,0 +1,36 @@ +// 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.plaindate.prototype.since +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-expand.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-expand.js new file mode 100644 index 0000000000..f41b88a8d3 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-expand.js @@ -0,0 +1,36 @@ +// 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.plaindate.prototype.until +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfCeil.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfCeil.js new file mode 100644 index 0000000000..8eb16b0943 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfCeil.js @@ -0,0 +1,36 @@ +// 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.plaindate.prototype.until +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfEven.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfEven.js new file mode 100644 index 0000000000..681edf13bd --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfEven.js @@ -0,0 +1,36 @@ +// 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.plaindate.prototype.until +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfFloor.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfFloor.js new file mode 100644 index 0000000000..5847aa4e08 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfFloor.js @@ -0,0 +1,36 @@ +// 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.plaindate.prototype.until +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfTrunc.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..917a5be714 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfTrunc.js @@ -0,0 +1,36 @@ +// 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.plaindate.prototype.until +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-expand.js b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-expand.js new file mode 100644 index 0000000000..7c610eb5fc --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-expand.js @@ -0,0 +1,32 @@ +// 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.plaindatetime.prototype.round +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789); + +const expected = [ + ["day", [1976, 11, 'M11', 19]], + ["hour", [1976, 11, 'M11', 18, 15]], + ["minute", [1976, 11, 'M11', 18, 14, 24]], + ["second", [1976, 11, 'M11', 18, 14, 23, 31]], + ["millisecond", [1976, 11, 'M11', 18, 14, 23, 30, 124]], + ["microsecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 457]], + ["nanosecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 456, 789]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expected]) => { + const [y, mon, mc, d, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; + TemporalHelpers.assertPlainDateTime( + instance.round({ smallestUnit, roundingMode }), + y, mon, mc, d, h, min, s, ms, µs, ns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfCeil.js b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfCeil.js new file mode 100644 index 0000000000..508861b1cd --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfCeil.js @@ -0,0 +1,32 @@ +// 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.plaindatetime.prototype.round +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789); + +const expected = [ + ["day", [1976, 11, 'M11', 19]], + ["hour", [1976, 11, 'M11', 18, 14]], + ["minute", [1976, 11, 'M11', 18, 14, 24]], + ["second", [1976, 11, 'M11', 18, 14, 23, 30]], + ["millisecond", [1976, 11, 'M11', 18, 14, 23, 30, 123]], + ["microsecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 457]], + ["nanosecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 456, 789]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expected]) => { + const [y, mon, mc, d, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; + TemporalHelpers.assertPlainDateTime( + instance.round({ smallestUnit, roundingMode }), + y, mon, mc, d, h, min, s, ms, µs, ns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfEven.js b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfEven.js new file mode 100644 index 0000000000..c53320aa62 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfEven.js @@ -0,0 +1,32 @@ +// 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.plaindatetime.prototype.round +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789); + +const expected = [ + ["day", [1976, 11, 'M11', 19]], + ["hour", [1976, 11, 'M11', 18, 14]], + ["minute", [1976, 11, 'M11', 18, 14, 24]], + ["second", [1976, 11, 'M11', 18, 14, 23, 30]], + ["millisecond", [1976, 11, 'M11', 18, 14, 23, 30, 123]], + ["microsecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 457]], + ["nanosecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 456, 789]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expected]) => { + const [y, mon, mc, d, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; + TemporalHelpers.assertPlainDateTime( + instance.round({ smallestUnit, roundingMode }), + y, mon, mc, d, h, min, s, ms, µs, ns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfFloor.js b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfFloor.js new file mode 100644 index 0000000000..37b6a8e551 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfFloor.js @@ -0,0 +1,32 @@ +// 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.plaindatetime.prototype.round +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789); + +const expected = [ + ["day", [1976, 11, 'M11', 19]], + ["hour", [1976, 11, 'M11', 18, 14]], + ["minute", [1976, 11, 'M11', 18, 14, 24]], + ["second", [1976, 11, 'M11', 18, 14, 23, 30]], + ["millisecond", [1976, 11, 'M11', 18, 14, 23, 30, 123]], + ["microsecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 457]], + ["nanosecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 456, 789]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expected]) => { + const [y, mon, mc, d, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; + TemporalHelpers.assertPlainDateTime( + instance.round({ smallestUnit, roundingMode }), + y, mon, mc, d, h, min, s, ms, µs, ns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfTrunc.js b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..017477954d --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/round/roundingmode-halfTrunc.js @@ -0,0 +1,32 @@ +// 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.plaindatetime.prototype.round +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainDateTime(1976, 11, 18, 14, 23, 30, 123, 456, 789); + +const expected = [ + ["day", [1976, 11, 'M11', 19]], + ["hour", [1976, 11, 'M11', 18, 14]], + ["minute", [1976, 11, 'M11', 18, 14, 24]], + ["second", [1976, 11, 'M11', 18, 14, 23, 30]], + ["millisecond", [1976, 11, 'M11', 18, 14, 23, 30, 123]], + ["microsecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 457]], + ["nanosecond", [1976, 11, 'M11', 18, 14, 23, 30, 123, 456, 789]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expected]) => { + const [y, mon, mc, d, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; + TemporalHelpers.assertPlainDateTime( + instance.round({ smallestUnit, roundingMode }), + y, mon, mc, d, h, min, s, ms, µs, ns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-expand.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-expand.js new file mode 100644 index 0000000000..0ec933a5ed --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-expand.js @@ -0,0 +1,42 @@ +// 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.plaindatetime.prototype.since +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 140], [0, 0, -140]], + ["days", [0, 0, 0, 974], [0, 0, 0, -974]], + ["hours", [0, 0, 0, 973, 5], [0, 0, 0, -973, -5]], + ["minutes", [0, 0, 0, 973, 4, 18], [0, 0, 0, -973, -4, -18]], + ["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 865], [0, 0, 0, -973, -4, -17, -4, -865]], + ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfCeil.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfCeil.js new file mode 100644 index 0000000000..2954fa8501 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfCeil.js @@ -0,0 +1,42 @@ +// 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.plaindatetime.prototype.since +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 973, 4], [0, 0, 0, -973, -4]], + ["minutes", [0, 0, 0, 973, 4, 17], [0, 0, 0, -973, -4, -17]], + ["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfEven.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfEven.js new file mode 100644 index 0000000000..908cd9e8c0 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfEven.js @@ -0,0 +1,42 @@ +// 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.plaindatetime.prototype.since +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 973, 4], [0, 0, 0, -973, -4]], + ["minutes", [0, 0, 0, 973, 4, 17], [0, 0, 0, -973, -4, -17]], + ["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfFloor.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfFloor.js new file mode 100644 index 0000000000..d71b07c533 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfFloor.js @@ -0,0 +1,42 @@ +// 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.plaindatetime.prototype.since +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 973, 4], [0, 0, 0, -973, -4]], + ["minutes", [0, 0, 0, 973, 4, 17], [0, 0, 0, -973, -4, -17]], + ["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfTrunc.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..ad467c3722 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfTrunc.js @@ -0,0 +1,42 @@ +// 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.plaindatetime.prototype.since +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 973, 4], [0, 0, 0, -973, -4]], + ["minutes", [0, 0, 0, 973, 4, 17], [0, 0, 0, -973, -4, -17]], + ["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-expand.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-expand.js new file mode 100644 index 0000000000..e3b80e6884 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-expand.js @@ -0,0 +1,37 @@ +// 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.plaindatetime.prototype.tostring +description: expand value for roundingMode option +features: [Temporal] +---*/ + +const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 987, 500); + +const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "expand" }); +assert.sameValue(result1, "2000-05-02T12:34:56.123988", + "roundingMode is expand (with 6 digits from smallestUnit)"); + +const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "expand" }); +assert.sameValue(result2, "2000-05-02T12:34:56.123988", + "roundingMode is expand (with 6 digits from fractionalSecondDigits)"); + +const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "expand" }); +assert.sameValue(result3, "2000-05-02T12:34:56.124", + "roundingMode is expand (with 3 digits from smallestUnit)"); + +const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "expand" }); +assert.sameValue(result4, "2000-05-02T12:34:56.124", + "roundingMode is expand (with 3 digits from fractionalSecondDigits)"); + +const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "expand" }); +assert.sameValue(result5, "2000-05-02T12:34:57", + "roundingMode is expand (with 0 digits from smallestUnit)"); + +const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "expand" }); +assert.sameValue(result6, "2000-05-02T12:34:57", + "roundingMode is expand (with 0 digits from fractionalSecondDigits)"); + +const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "expand" }); +assert.sameValue(result7, "2000-05-02T12:35", "roundingMode is expand (round to minute)"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfCeil.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfCeil.js new file mode 100644 index 0000000000..dd4005d820 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfCeil.js @@ -0,0 +1,37 @@ +// 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.plaindatetime.prototype.tostring +description: halfCeil value for roundingMode option +features: [Temporal] +---*/ + +const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 987, 500); + +const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfCeil" }); +assert.sameValue(result1, "2000-05-02T12:34:56.123988", + "roundingMode is halfCeil (with 6 digits from smallestUnit)"); + +const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfCeil" }); +assert.sameValue(result2, "2000-05-02T12:34:56.123988", + "roundingMode is halfCeil (with 6 digits from fractionalSecondDigits)"); + +const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfCeil" }); +assert.sameValue(result3, "2000-05-02T12:34:56.124", + "roundingMode is halfCeil (with 3 digits from smallestUnit)"); + +const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfCeil" }); +assert.sameValue(result4, "2000-05-02T12:34:56.124", + "roundingMode is halfCeil (with 3 digits from fractionalSecondDigits)"); + +const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfCeil" }); +assert.sameValue(result5, "2000-05-02T12:34:56", + "roundingMode is halfCeil (with 0 digits from smallestUnit)"); + +const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfCeil" }); +assert.sameValue(result6, "2000-05-02T12:34:56", + "roundingMode is halfCeil (with 0 digits from fractionalSecondDigits)"); + +const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfCeil" }); +assert.sameValue(result7, "2000-05-02T12:35", "roundingMode is halfCeil (round to minute)"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfEven.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfEven.js new file mode 100644 index 0000000000..be4751193b --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfEven.js @@ -0,0 +1,37 @@ +// 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.plaindatetime.prototype.tostring +description: halfEven value for roundingMode option +features: [Temporal] +---*/ + +const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 987, 500); + +const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfEven" }); +assert.sameValue(result1, "2000-05-02T12:34:56.123988", + "roundingMode is halfEven (with 6 digits from smallestUnit)"); + +const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfEven" }); +assert.sameValue(result2, "2000-05-02T12:34:56.123988", + "roundingMode is halfEven (with 6 digits from fractionalSecondDigits)"); + +const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfEven" }); +assert.sameValue(result3, "2000-05-02T12:34:56.124", + "roundingMode is halfEven (with 3 digits from smallestUnit)"); + +const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfEven" }); +assert.sameValue(result4, "2000-05-02T12:34:56.124", + "roundingMode is halfEven (with 3 digits from fractionalSecondDigits)"); + +const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfEven" }); +assert.sameValue(result5, "2000-05-02T12:34:56", + "roundingMode is halfEven (with 0 digits from smallestUnit)"); + +const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfEven" }); +assert.sameValue(result6, "2000-05-02T12:34:56", + "roundingMode is halfEven (with 0 digits from fractionalSecondDigits)"); + +const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfEven" }); +assert.sameValue(result7, "2000-05-02T12:35", "roundingMode is halfEven (round to minute)"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfFloor.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfFloor.js new file mode 100644 index 0000000000..bffaaccab8 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfFloor.js @@ -0,0 +1,37 @@ +// 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.plaindatetime.prototype.tostring +description: halfFloor value for roundingMode option +features: [Temporal] +---*/ + +const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 987, 500); + +const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfFloor" }); +assert.sameValue(result1, "2000-05-02T12:34:56.123987", + "roundingMode is halfFloor (with 6 digits from smallestUnit)"); + +const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfFloor" }); +assert.sameValue(result2, "2000-05-02T12:34:56.123987", + "roundingMode is halfFloor (with 6 digits from fractionalSecondDigits)"); + +const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfFloor" }); +assert.sameValue(result3, "2000-05-02T12:34:56.124", + "roundingMode is halfFloor (with 3 digits from smallestUnit)"); + +const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfFloor" }); +assert.sameValue(result4, "2000-05-02T12:34:56.124", + "roundingMode is halfFloor (with 3 digits from fractionalSecondDigits)"); + +const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfFloor" }); +assert.sameValue(result5, "2000-05-02T12:34:56", + "roundingMode is halfFloor (with 0 digits from smallestUnit)"); + +const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfFloor" }); +assert.sameValue(result6, "2000-05-02T12:34:56", + "roundingMode is halfFloor (with 0 digits from fractionalSecondDigits)"); + +const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfFloor" }); +assert.sameValue(result7, "2000-05-02T12:35", "roundingMode is halfFloor (round to minute)"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfTrunc.js b/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..09dca74504 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toString/roundingmode-halfTrunc.js @@ -0,0 +1,37 @@ +// 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.plaindatetime.prototype.tostring +description: halfTrunc value for roundingMode option +features: [Temporal] +---*/ + +const datetime = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 123, 987, 500); + +const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfTrunc" }); +assert.sameValue(result1, "2000-05-02T12:34:56.123987", + "roundingMode is halfTrunc (with 6 digits from smallestUnit)"); + +const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfTrunc" }); +assert.sameValue(result2, "2000-05-02T12:34:56.123987", + "roundingMode is halfTrunc (with 6 digits from fractionalSecondDigits)"); + +const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfTrunc" }); +assert.sameValue(result3, "2000-05-02T12:34:56.124", + "roundingMode is halfTrunc (with 3 digits from smallestUnit)"); + +const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfTrunc" }); +assert.sameValue(result4, "2000-05-02T12:34:56.124", + "roundingMode is halfTrunc (with 3 digits from fractionalSecondDigits)"); + +const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfTrunc" }); +assert.sameValue(result5, "2000-05-02T12:34:56", + "roundingMode is halfTrunc (with 0 digits from smallestUnit)"); + +const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfTrunc" }); +assert.sameValue(result6, "2000-05-02T12:34:56", + "roundingMode is halfTrunc (with 0 digits from fractionalSecondDigits)"); + +const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfTrunc" }); +assert.sameValue(result7, "2000-05-02T12:35", "roundingMode is halfTrunc (round to minute)"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-expand.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-expand.js new file mode 100644 index 0000000000..45975458f7 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-expand.js @@ -0,0 +1,42 @@ +// 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.plaindatetime.prototype.until +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 140], [0, 0, -140]], + ["days", [0, 0, 0, 974], [0, 0, 0, -974]], + ["hours", [0, 0, 0, 973, 5], [0, 0, 0, -973, -5]], + ["minutes", [0, 0, 0, 973, 4, 18], [0, 0, 0, -973, -4, -18]], + ["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 865], [0, 0, 0, -973, -4, -17, -4, -865]], + ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfCeil.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfCeil.js new file mode 100644 index 0000000000..d1223f2581 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfCeil.js @@ -0,0 +1,42 @@ +// 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.plaindatetime.prototype.until +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 973, 4], [0, 0, 0, -973, -4]], + ["minutes", [0, 0, 0, 973, 4, 17], [0, 0, 0, -973, -4, -17]], + ["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfEven.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfEven.js new file mode 100644 index 0000000000..3397387ca8 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfEven.js @@ -0,0 +1,42 @@ +// 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.plaindatetime.prototype.until +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 973, 4], [0, 0, 0, -973, -4]], + ["minutes", [0, 0, 0, 973, 4, 17], [0, 0, 0, -973, -4, -17]], + ["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfFloor.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfFloor.js new file mode 100644 index 0000000000..ac2350dc8e --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfFloor.js @@ -0,0 +1,42 @@ +// 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.plaindatetime.prototype.until +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 973, 4], [0, 0, 0, -973, -4]], + ["minutes", [0, 0, 0, 973, 4, 17], [0, 0, 0, -973, -4, -17]], + ["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfTrunc.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..f2c874de82 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfTrunc.js @@ -0,0 +1,42 @@ +// 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.plaindatetime.prototype.until +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainDateTime(2019, 1, 8, 8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainDateTime(2021, 9, 7, 12, 39, 40, 987, 654, 321); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 973, 4], [0, 0, 0, -973, -4]], + ["minutes", [0, 0, 0, 973, 4, 17], [0, 0, 0, -973, -4, -17]], + ["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198], [0, 0, 0, -973, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-expand.js b/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-expand.js new file mode 100644 index 0000000000..cd4e336298 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-expand.js @@ -0,0 +1,31 @@ +// 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.plaintime.prototype.round +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(13, 46, 23, 123, 456, 789); + +const expected = [ + ["hour", [14]], + ["minute", [13, 47]], + ["second", [13, 46, 24]], + ["millisecond", [13, 46, 23, 124]], + ["microsecond", [13, 46, 23, 123, 457]], + ["nanosecond", [13, 46, 23, 123, 456, 789]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expected]) => { + const [h, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; + TemporalHelpers.assertPlainTime( + instance.round({ smallestUnit, roundingMode }), + h, min, s, ms, µs, ns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfCeil.js b/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfCeil.js new file mode 100644 index 0000000000..6215a1f967 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfCeil.js @@ -0,0 +1,31 @@ +// 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.plaintime.prototype.round +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(13, 46, 23, 123, 456, 789); + +const expected = [ + ["hour", [14]], + ["minute", [13, 46]], + ["second", [13, 46, 23]], + ["millisecond", [13, 46, 23, 123]], + ["microsecond", [13, 46, 23, 123, 457]], + ["nanosecond", [13, 46, 23, 123, 456, 789]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expected]) => { + const [h, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; + TemporalHelpers.assertPlainTime( + instance.round({ smallestUnit, roundingMode }), + h, min, s, ms, µs, ns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfEven.js b/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfEven.js new file mode 100644 index 0000000000..647375b9bf --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfEven.js @@ -0,0 +1,31 @@ +// 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.plaintime.prototype.round +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(13, 46, 23, 123, 456, 789); + +const expected = [ + ["hour", [14]], + ["minute", [13, 46]], + ["second", [13, 46, 23]], + ["millisecond", [13, 46, 23, 123]], + ["microsecond", [13, 46, 23, 123, 457]], + ["nanosecond", [13, 46, 23, 123, 456, 789]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expected]) => { + const [h, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; + TemporalHelpers.assertPlainTime( + instance.round({ smallestUnit, roundingMode }), + h, min, s, ms, µs, ns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfFloor.js b/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfFloor.js new file mode 100644 index 0000000000..6d4164ea51 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfFloor.js @@ -0,0 +1,31 @@ +// 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.plaintime.prototype.round +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(13, 46, 23, 123, 456, 789); + +const expected = [ + ["hour", [14]], + ["minute", [13, 46]], + ["second", [13, 46, 23]], + ["millisecond", [13, 46, 23, 123]], + ["microsecond", [13, 46, 23, 123, 457]], + ["nanosecond", [13, 46, 23, 123, 456, 789]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expected]) => { + const [h, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; + TemporalHelpers.assertPlainTime( + instance.round({ smallestUnit, roundingMode }), + h, min, s, ms, µs, ns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfTrunc.js b/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..836e7b2a22 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/round/roundingmode-halfTrunc.js @@ -0,0 +1,31 @@ +// 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.plaintime.prototype.round +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const instance = new Temporal.PlainTime(13, 46, 23, 123, 456, 789); + +const expected = [ + ["hour", [14]], + ["minute", [13, 46]], + ["second", [13, 46, 23]], + ["millisecond", [13, 46, 23, 123]], + ["microsecond", [13, 46, 23, 123, 457]], + ["nanosecond", [13, 46, 23, 123, 456, 789]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expected]) => { + const [h, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; + TemporalHelpers.assertPlainTime( + instance.round({ smallestUnit, roundingMode }), + h, min, s, ms, µs, ns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-expand.js b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-expand.js new file mode 100644 index 0000000000..7b912d7564 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-expand.js @@ -0,0 +1,38 @@ +// 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.plaintime.prototype.since +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); + +const expected = [ + ["hours", [0, 0, 0, 0, 5], [0, 0, 0, 0, -5]], + ["minutes", [0, 0, 0, 0, 4, 18], [0, 0, 0, 0, -4, -18]], + ["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 865], [0, 0, 0, 0, -4, -17, -4, -865]], + ["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfCeil.js b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfCeil.js new file mode 100644 index 0000000000..cc1f77229f --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfCeil.js @@ -0,0 +1,38 @@ +// 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.plaintime.prototype.since +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); + +const expected = [ + ["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -4]], + ["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -17]], + ["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfEven.js b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfEven.js new file mode 100644 index 0000000000..edd387cb45 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfEven.js @@ -0,0 +1,38 @@ +// 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.plaintime.prototype.since +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); + +const expected = [ + ["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -4]], + ["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -17]], + ["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfFloor.js b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfFloor.js new file mode 100644 index 0000000000..d55360cbbc --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfFloor.js @@ -0,0 +1,38 @@ +// 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.plaintime.prototype.since +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); + +const expected = [ + ["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -4]], + ["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -17]], + ["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfTrunc.js b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..40fdddd916 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfTrunc.js @@ -0,0 +1,38 @@ +// 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.plaintime.prototype.since +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); + +const expected = [ + ["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -4]], + ["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -17]], + ["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-expand.js b/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-expand.js new file mode 100644 index 0000000000..88ceee0ed4 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-expand.js @@ -0,0 +1,37 @@ +// 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.plaintime.prototype.tostring +description: expand value for roundingMode option +features: [Temporal] +---*/ + +const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500); + +const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "expand" }); +assert.sameValue(result1, "12:34:56.123988", + "roundingMode is expand (with 6 digits from smallestUnit)"); + +const result2 = time.toString({ fractionalSecondDigits: 6, roundingMode: "expand" }); +assert.sameValue(result2, "12:34:56.123988", + "roundingMode is expand (with 6 digits from fractionalSecondDigits)"); + +const result3 = time.toString({ smallestUnit: "millisecond", roundingMode: "expand" }); +assert.sameValue(result3, "12:34:56.124", + "roundingMode is expand (with 3 digits from smallestUnit)"); + +const result4 = time.toString({ fractionalSecondDigits: 3, roundingMode: "expand" }); +assert.sameValue(result4, "12:34:56.124", + "roundingMode is expand (with 3 digits from fractionalSecondDigits)"); + +const result5 = time.toString({ smallestUnit: "second", roundingMode: "expand" }); +assert.sameValue(result5, "12:34:57", + "roundingMode is expand (with 0 digits from smallestUnit)"); + +const result6 = time.toString({ fractionalSecondDigits: 0, roundingMode: "expand" }); +assert.sameValue(result6, "12:34:57", + "roundingMode is expand (with 0 digits from fractionalSecondDigits)"); + +const result7 = time.toString({ smallestUnit: "minute", roundingMode: "expand" }); +assert.sameValue(result7, "12:35", "roundingMode is expand (round to minute)"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfCeil.js b/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfCeil.js new file mode 100644 index 0000000000..c82b99ccdc --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfCeil.js @@ -0,0 +1,37 @@ +// 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.plaintime.prototype.tostring +description: halfCeil value for roundingMode option +features: [Temporal] +---*/ + +const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500); + +const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "halfCeil" }); +assert.sameValue(result1, "12:34:56.123988", + "roundingMode is halfCeil (with 6 digits from smallestUnit)"); + +const result2 = time.toString({ fractionalSecondDigits: 6, roundingMode: "halfCeil" }); +assert.sameValue(result2, "12:34:56.123988", + "roundingMode is halfCeil (with 6 digits from fractionalSecondDigits)"); + +const result3 = time.toString({ smallestUnit: "millisecond", roundingMode: "halfCeil" }); +assert.sameValue(result3, "12:34:56.124", + "roundingMode is halfCeil (with 3 digits from smallestUnit)"); + +const result4 = time.toString({ fractionalSecondDigits: 3, roundingMode: "halfCeil" }); +assert.sameValue(result4, "12:34:56.124", + "roundingMode is halfCeil (with 3 digits from fractionalSecondDigits)"); + +const result5 = time.toString({ smallestUnit: "second", roundingMode: "halfCeil" }); +assert.sameValue(result5, "12:34:56", + "roundingMode is halfCeil (with 0 digits from smallestUnit)"); + +const result6 = time.toString({ fractionalSecondDigits: 0, roundingMode: "halfCeil" }); +assert.sameValue(result6, "12:34:56", + "roundingMode is halfCeil (with 0 digits from fractionalSecondDigits)"); + +const result7 = time.toString({ smallestUnit: "minute", roundingMode: "halfCeil" }); +assert.sameValue(result7, "12:35", "roundingMode is halfCeil (round to minute)"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfEven.js b/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfEven.js new file mode 100644 index 0000000000..19fc6049cb --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfEven.js @@ -0,0 +1,37 @@ +// 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.plaintime.prototype.tostring +description: halfEven value for roundingMode option +features: [Temporal] +---*/ + +const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500); + +const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "halfEven" }); +assert.sameValue(result1, "12:34:56.123988", + "roundingMode is halfEven (with 6 digits from smallestUnit)"); + +const result2 = time.toString({ fractionalSecondDigits: 6, roundingMode: "halfEven" }); +assert.sameValue(result2, "12:34:56.123988", + "roundingMode is halfEven (with 6 digits from fractionalSecondDigits)"); + +const result3 = time.toString({ smallestUnit: "millisecond", roundingMode: "halfEven" }); +assert.sameValue(result3, "12:34:56.124", + "roundingMode is halfEven (with 3 digits from smallestUnit)"); + +const result4 = time.toString({ fractionalSecondDigits: 3, roundingMode: "halfEven" }); +assert.sameValue(result4, "12:34:56.124", + "roundingMode is halfEven (with 3 digits from fractionalSecondDigits)"); + +const result5 = time.toString({ smallestUnit: "second", roundingMode: "halfEven" }); +assert.sameValue(result5, "12:34:56", + "roundingMode is halfEven (with 0 digits from smallestUnit)"); + +const result6 = time.toString({ fractionalSecondDigits: 0, roundingMode: "halfEven" }); +assert.sameValue(result6, "12:34:56", + "roundingMode is halfEven (with 0 digits from fractionalSecondDigits)"); + +const result7 = time.toString({ smallestUnit: "minute", roundingMode: "halfEven" }); +assert.sameValue(result7, "12:35", "roundingMode is halfEven (round to minute)"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfFloor.js b/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfFloor.js new file mode 100644 index 0000000000..d063ae649a --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfFloor.js @@ -0,0 +1,37 @@ +// 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.plaintime.prototype.tostring +description: halfFloor value for roundingMode option +features: [Temporal] +---*/ + +const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500); + +const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "halfFloor" }); +assert.sameValue(result1, "12:34:56.123987", + "roundingMode is halfFloor (with 6 digits from smallestUnit)"); + +const result2 = time.toString({ fractionalSecondDigits: 6, roundingMode: "halfFloor" }); +assert.sameValue(result2, "12:34:56.123987", + "roundingMode is halfFloor (with 6 digits from fractionalSecondDigits)"); + +const result3 = time.toString({ smallestUnit: "millisecond", roundingMode: "halfFloor" }); +assert.sameValue(result3, "12:34:56.124", + "roundingMode is halfFloor (with 3 digits from smallestUnit)"); + +const result4 = time.toString({ fractionalSecondDigits: 3, roundingMode: "halfFloor" }); +assert.sameValue(result4, "12:34:56.124", + "roundingMode is halfFloor (with 3 digits from fractionalSecondDigits)"); + +const result5 = time.toString({ smallestUnit: "second", roundingMode: "halfFloor" }); +assert.sameValue(result5, "12:34:56", + "roundingMode is halfFloor (with 0 digits from smallestUnit)"); + +const result6 = time.toString({ fractionalSecondDigits: 0, roundingMode: "halfFloor" }); +assert.sameValue(result6, "12:34:56", + "roundingMode is halfFloor (with 0 digits from fractionalSecondDigits)"); + +const result7 = time.toString({ smallestUnit: "minute", roundingMode: "halfFloor" }); +assert.sameValue(result7, "12:35", "roundingMode is halfFloor (round to minute)"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfTrunc.js b/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..e663669992 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toString/roundingmode-halfTrunc.js @@ -0,0 +1,37 @@ +// 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.plaintime.prototype.tostring +description: halfTrunc value for roundingMode option +features: [Temporal] +---*/ + +const time = new Temporal.PlainTime(12, 34, 56, 123, 987, 500); + +const result1 = time.toString({ smallestUnit: "microsecond", roundingMode: "halfTrunc" }); +assert.sameValue(result1, "12:34:56.123987", + "roundingMode is halfTrunc (with 6 digits from smallestUnit)"); + +const result2 = time.toString({ fractionalSecondDigits: 6, roundingMode: "halfTrunc" }); +assert.sameValue(result2, "12:34:56.123987", + "roundingMode is halfTrunc (with 6 digits from fractionalSecondDigits)"); + +const result3 = time.toString({ smallestUnit: "millisecond", roundingMode: "halfTrunc" }); +assert.sameValue(result3, "12:34:56.124", + "roundingMode is halfTrunc (with 3 digits from smallestUnit)"); + +const result4 = time.toString({ fractionalSecondDigits: 3, roundingMode: "halfTrunc" }); +assert.sameValue(result4, "12:34:56.124", + "roundingMode is halfTrunc (with 3 digits from fractionalSecondDigits)"); + +const result5 = time.toString({ smallestUnit: "second", roundingMode: "halfTrunc" }); +assert.sameValue(result5, "12:34:56", + "roundingMode is halfTrunc (with 0 digits from smallestUnit)"); + +const result6 = time.toString({ fractionalSecondDigits: 0, roundingMode: "halfTrunc" }); +assert.sameValue(result6, "12:34:56", + "roundingMode is halfTrunc (with 0 digits from fractionalSecondDigits)"); + +const result7 = time.toString({ smallestUnit: "minute", roundingMode: "halfTrunc" }); +assert.sameValue(result7, "12:35", "roundingMode is halfTrunc (round to minute)"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-expand.js b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-expand.js new file mode 100644 index 0000000000..ddc636faaa --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-expand.js @@ -0,0 +1,38 @@ +// 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.plaintime.prototype.until +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); + +const expected = [ + ["hours", [0, 0, 0, 0, 5], [0, 0, 0, 0, -5]], + ["minutes", [0, 0, 0, 0, 4, 18], [0, 0, 0, 0, -4, -18]], + ["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 865], [0, 0, 0, 0, -4, -17, -4, -865]], + ["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfCeil.js b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfCeil.js new file mode 100644 index 0000000000..f830403595 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfCeil.js @@ -0,0 +1,38 @@ +// 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.plaintime.prototype.until +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); + +const expected = [ + ["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -4]], + ["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -17]], + ["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfEven.js b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfEven.js new file mode 100644 index 0000000000..6a8da4dd84 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfEven.js @@ -0,0 +1,38 @@ +// 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.plaintime.prototype.until +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); + +const expected = [ + ["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -4]], + ["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -17]], + ["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfFloor.js b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfFloor.js new file mode 100644 index 0000000000..af72c4e63a --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfFloor.js @@ -0,0 +1,38 @@ +// 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.plaintime.prototype.until +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); + +const expected = [ + ["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -4]], + ["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -17]], + ["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfTrunc.js b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..906052e33f --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfTrunc.js @@ -0,0 +1,38 @@ +// 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.plaintime.prototype.until +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); + +const expected = [ + ["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -4]], + ["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -17]], + ["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 198], [0, 0, 0, 0, -4, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-expand.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-expand.js new file mode 100644 index 0000000000..cd11c2d22b --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-expand.js @@ -0,0 +1,34 @@ +// 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.plainyearmonth.prototype.since +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +const expected = [ + ["years", [3], [-3]], + ["months", [2, 8], [-2, -8]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfCeil.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfCeil.js new file mode 100644 index 0000000000..a12dd19185 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfCeil.js @@ -0,0 +1,34 @@ +// 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.plainyearmonth.prototype.since +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +const expected = [ + ["years", [3], [-3]], + ["months", [2, 8], [-2, -8]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfEven.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfEven.js new file mode 100644 index 0000000000..23b34bd304 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfEven.js @@ -0,0 +1,34 @@ +// 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.plainyearmonth.prototype.since +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +const expected = [ + ["years", [3], [-3]], + ["months", [2, 8], [-2, -8]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfFloor.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfFloor.js new file mode 100644 index 0000000000..ae115f894c --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfFloor.js @@ -0,0 +1,34 @@ +// 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.plainyearmonth.prototype.since +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +const expected = [ + ["years", [3], [-3]], + ["months", [2, 8], [-2, -8]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfTrunc.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..9acf878e77 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfTrunc.js @@ -0,0 +1,34 @@ +// 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.plainyearmonth.prototype.since +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +const expected = [ + ["years", [3], [-3]], + ["months", [2, 8], [-2, -8]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-expand.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-expand.js new file mode 100644 index 0000000000..d80d0c00e9 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-expand.js @@ -0,0 +1,34 @@ +// 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.plainyearmonth.prototype.until +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +const expected = [ + ["years", [3], [-3]], + ["months", [2, 8], [-2, -8]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfCeil.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfCeil.js new file mode 100644 index 0000000000..ee06394036 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfCeil.js @@ -0,0 +1,34 @@ +// 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.plainyearmonth.prototype.until +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +const expected = [ + ["years", [3], [-3]], + ["months", [2, 8], [-2, -8]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfEven.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfEven.js new file mode 100644 index 0000000000..2b75441875 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfEven.js @@ -0,0 +1,34 @@ +// 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.plainyearmonth.prototype.until +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +const expected = [ + ["years", [3], [-3]], + ["months", [2, 8], [-2, -8]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfFloor.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfFloor.js new file mode 100644 index 0000000000..287e77f20d --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfFloor.js @@ -0,0 +1,34 @@ +// 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.plainyearmonth.prototype.until +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +const expected = [ + ["years", [3], [-3]], + ["months", [2, 8], [-2, -8]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfTrunc.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..baa2d31adf --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfTrunc.js @@ -0,0 +1,34 @@ +// 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.plainyearmonth.prototype.until +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); + +const expected = [ + ["years", [3], [-3]], + ["months", [2, 8], [-2, -8]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-expand.js b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-expand.js new file mode 100644 index 0000000000..768b5503bf --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-expand.js @@ -0,0 +1,29 @@ +// 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.zoneddatetime.prototype.round +description: Tests calculations with roundingMode "expand". +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */, "+01:00"); + +const expected = [ + ["day", 217206000_000_000_000n /* 1976-11-19T00:00:00+01:00 */], + ["minute", 217175040_000_000_000n /* 1976-11-18T15:24:00+01:00 */], + ["second", 217175011_000_000_000n /* 1976-11-18T15:23:31+01:00 */], + ["millisecond", 217175010_124_000_000n /* 1976-11-18T15:23:30.124+01:00 */], + ["microsecond", 217175010_123_457_000n /* 1976-11-18T15:23:30.123457+01:00 */], + ["nanosecond", 217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expected]) => { + assert.sameValue( + instance.round({ smallestUnit, roundingMode }).epochNanoseconds, + expected, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfCeil.js b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfCeil.js new file mode 100644 index 0000000000..962c500dbe --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfCeil.js @@ -0,0 +1,29 @@ +// 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.zoneddatetime.prototype.round +description: Tests calculations with roundingMode "halfCeil". +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */, "+01:00"); + +const expected = [ + ["day", 217206000_000_000_000n /* 1976-11-19T00:00:00+01:00 */], + ["minute", 217175040_000_000_000n /* 1976-11-18T15:24:00+01:00 */], + ["second", 217175010_000_000_000n /* 1976-11-18T15:23:30+01:00 */], + ["millisecond", 217175010_123_000_000n /* 1976-11-18T15:23:30.123+01:00 */], + ["microsecond", 217175010_123_457_000n /* 1976-11-18T15:23:30.123457+01:00 */], + ["nanosecond", 217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expected]) => { + assert.sameValue( + instance.round({ smallestUnit, roundingMode }).epochNanoseconds, + expected, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfEven.js b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfEven.js new file mode 100644 index 0000000000..8b623d62cd --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfEven.js @@ -0,0 +1,29 @@ +// 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.zoneddatetime.prototype.round +description: Tests calculations with roundingMode "halfEven". +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */, "+01:00"); + +const expected = [ + ["day", 217206000_000_000_000n /* 1976-11-19T00:00:00+01:00 */], + ["minute", 217175040_000_000_000n /* 1976-11-18T15:24:00+01:00 */], + ["second", 217175010_000_000_000n /* 1976-11-18T15:23:30+01:00 */], + ["millisecond", 217175010_123_000_000n /* 1976-11-18T15:23:30.123+01:00 */], + ["microsecond", 217175010_123_457_000n /* 1976-11-18T15:23:30.123457+01:00 */], + ["nanosecond", 217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expected]) => { + assert.sameValue( + instance.round({ smallestUnit, roundingMode }).epochNanoseconds, + expected, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfFloor.js b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfFloor.js new file mode 100644 index 0000000000..528fd0a2a8 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfFloor.js @@ -0,0 +1,29 @@ +// 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.zoneddatetime.prototype.round +description: Tests calculations with roundingMode "halfFloor". +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */, "+01:00"); + +const expected = [ + ["day", 217206000_000_000_000n /* 1976-11-19T00:00:00+01:00 */], + ["minute", 217175040_000_000_000n /* 1976-11-18T15:24:00+01:00 */], + ["second", 217175010_000_000_000n /* 1976-11-18T15:23:30+01:00 */], + ["millisecond", 217175010_123_000_000n /* 1976-11-18T15:23:30.123+01:00 */], + ["microsecond", 217175010_123_457_000n /* 1976-11-18T15:23:30.123457+01:00 */], + ["nanosecond", 217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expected]) => { + assert.sameValue( + instance.round({ smallestUnit, roundingMode }).epochNanoseconds, + expected, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfTrunc.js b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..306b6b81b9 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/round/roundingmode-halfTrunc.js @@ -0,0 +1,29 @@ +// 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.zoneddatetime.prototype.round +description: Tests calculations with roundingMode "halfTrunc". +features: [Temporal] +---*/ + +const instance = new Temporal.ZonedDateTime(217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */, "+01:00"); + +const expected = [ + ["day", 217206000_000_000_000n /* 1976-11-19T00:00:00+01:00 */], + ["minute", 217175040_000_000_000n /* 1976-11-18T15:24:00+01:00 */], + ["second", 217175010_000_000_000n /* 1976-11-18T15:23:30+01:00 */], + ["millisecond", 217175010_123_000_000n /* 1976-11-18T15:23:30.123+01:00 */], + ["microsecond", 217175010_123_457_000n /* 1976-11-18T15:23:30.123457+01:00 */], + ["nanosecond", 217175010_123_456_789n /* 1976-11-18T15:23:30.123456789+01:00 */], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expected]) => { + assert.sameValue( + instance.round({ smallestUnit, roundingMode }).epochNanoseconds, + expected, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode})` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-expand.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-expand.js new file mode 100644 index 0000000000..62a2205fbf --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-expand.js @@ -0,0 +1,42 @@ +// 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.zoneddatetime.prototype.since +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC"); +const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC"); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 140], [0, 0, -140]], + ["days", [0, 0, 0, 974], [0, 0, 0, -974]], + ["hours", [0, 0, 0, 0, 23357], [0, 0, 0, 0, -23357]], + ["minutes", [0, 0, 0, 0, 23356, 18], [0, 0, 0, 0, -23356, -18]], + ["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 865], [0, 0, 0, 0, -23356, -17, -4, -865]], + ["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfCeil.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfCeil.js new file mode 100644 index 0000000000..f72c4d1897 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfCeil.js @@ -0,0 +1,42 @@ +// 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.zoneddatetime.prototype.since +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC"); +const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC"); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23356]], + ["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -17]], + ["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfEven.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfEven.js new file mode 100644 index 0000000000..a27ca44c00 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfEven.js @@ -0,0 +1,42 @@ +// 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.zoneddatetime.prototype.since +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC"); +const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC"); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23356]], + ["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -17]], + ["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfFloor.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfFloor.js new file mode 100644 index 0000000000..58b47e6d2e --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfFloor.js @@ -0,0 +1,42 @@ +// 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.zoneddatetime.prototype.since +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC"); +const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC"); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23356]], + ["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -17]], + ["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfTrunc.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..87160b8513 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfTrunc.js @@ -0,0 +1,42 @@ +// 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.zoneddatetime.prototype.since +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC"); +const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC"); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23356]], + ["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -17]], + ["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + earlier.since(later, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-expand.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-expand.js new file mode 100644 index 0000000000..c7cda90c82 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-expand.js @@ -0,0 +1,37 @@ +// 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.zoneddatetime.prototype.tostring +description: expand value for roundingMode option +features: [Temporal] +---*/ + +const datetime = new Temporal.ZonedDateTime(1_000_000_000_123_987_500n, "UTC"); + +const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "expand" }); +assert.sameValue(result1, "2001-09-09T01:46:40.123988+00:00[UTC]", + "roundingMode is expand (with 6 digits from smallestUnit)"); + +const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "expand" }); +assert.sameValue(result2, "2001-09-09T01:46:40.123988+00:00[UTC]", + "roundingMode is expand (with 6 digits from fractionalSecondDigits)"); + +const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "expand" }); +assert.sameValue(result3, "2001-09-09T01:46:40.124+00:00[UTC]", + "roundingMode is expand (with 3 digits from smallestUnit)"); + +const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "expand" }); +assert.sameValue(result4, "2001-09-09T01:46:40.124+00:00[UTC]", + "roundingMode is expand (with 3 digits from fractionalSecondDigits)"); + +const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "expand" }); +assert.sameValue(result5, "2001-09-09T01:46:41+00:00[UTC]", + "roundingMode is expand (with 0 digits from smallestUnit)"); + +const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "expand" }); +assert.sameValue(result6, "2001-09-09T01:46:41+00:00[UTC]", + "roundingMode is expand (with 0 digits from fractionalSecondDigits)"); + +const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "expand" }); +assert.sameValue(result7, "2001-09-09T01:47+00:00[UTC]", "roundingMode is expand (round to minute)"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfCeil.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfCeil.js new file mode 100644 index 0000000000..315916c668 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfCeil.js @@ -0,0 +1,37 @@ +// 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.zoneddatetime.prototype.tostring +description: halfCeil value for roundingMode option +features: [Temporal] +---*/ + +const datetime = new Temporal.ZonedDateTime(1_000_000_000_123_987_500n, "UTC"); + +const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfCeil" }); +assert.sameValue(result1, "2001-09-09T01:46:40.123988+00:00[UTC]", + "roundingMode is halfCeil (with 6 digits from smallestUnit)"); + +const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfCeil" }); +assert.sameValue(result2, "2001-09-09T01:46:40.123988+00:00[UTC]", + "roundingMode is halfCeil (with 6 digits from fractionalSecondDigits)"); + +const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfCeil" }); +assert.sameValue(result3, "2001-09-09T01:46:40.124+00:00[UTC]", + "roundingMode is halfCeil (with 3 digits from smallestUnit)"); + +const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfCeil" }); +assert.sameValue(result4, "2001-09-09T01:46:40.124+00:00[UTC]", + "roundingMode is halfCeil (with 3 digits from fractionalSecondDigits)"); + +const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfCeil" }); +assert.sameValue(result5, "2001-09-09T01:46:40+00:00[UTC]", + "roundingMode is halfCeil (with 0 digits from smallestUnit)"); + +const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfCeil" }); +assert.sameValue(result6, "2001-09-09T01:46:40+00:00[UTC]", + "roundingMode is halfCeil (with 0 digits from fractionalSecondDigits)"); + +const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfCeil" }); +assert.sameValue(result7, "2001-09-09T01:47+00:00[UTC]", "roundingMode is halfCeil (round to minute)"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfEven.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfEven.js new file mode 100644 index 0000000000..7ef4fc91de --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfEven.js @@ -0,0 +1,37 @@ +// 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.zoneddatetime.prototype.tostring +description: halfEven value for roundingMode option +features: [Temporal] +---*/ + +const datetime = new Temporal.ZonedDateTime(1_000_000_000_123_987_500n, "UTC"); + +const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfEven" }); +assert.sameValue(result1, "2001-09-09T01:46:40.123988+00:00[UTC]", + "roundingMode is halfEven (with 6 digits from smallestUnit)"); + +const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfEven" }); +assert.sameValue(result2, "2001-09-09T01:46:40.123988+00:00[UTC]", + "roundingMode is halfEven (with 6 digits from fractionalSecondDigits)"); + +const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfEven" }); +assert.sameValue(result3, "2001-09-09T01:46:40.124+00:00[UTC]", + "roundingMode is halfEven (with 3 digits from smallestUnit)"); + +const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfEven" }); +assert.sameValue(result4, "2001-09-09T01:46:40.124+00:00[UTC]", + "roundingMode is halfEven (with 3 digits from fractionalSecondDigits)"); + +const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfEven" }); +assert.sameValue(result5, "2001-09-09T01:46:40+00:00[UTC]", + "roundingMode is halfEven (with 0 digits from smallestUnit)"); + +const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfEven" }); +assert.sameValue(result6, "2001-09-09T01:46:40+00:00[UTC]", + "roundingMode is halfEven (with 0 digits from fractionalSecondDigits)"); + +const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfEven" }); +assert.sameValue(result7, "2001-09-09T01:47+00:00[UTC]", "roundingMode is halfEven (round to minute)"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfFloor.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfFloor.js new file mode 100644 index 0000000000..7bfafc7bfa --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfFloor.js @@ -0,0 +1,37 @@ +// 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.zoneddatetime.prototype.tostring +description: halfFloor value for roundingMode option +features: [Temporal] +---*/ + +const datetime = new Temporal.ZonedDateTime(1_000_000_000_123_987_500n, "UTC"); + +const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfFloor" }); +assert.sameValue(result1, "2001-09-09T01:46:40.123987+00:00[UTC]", + "roundingMode is halfFloor (with 6 digits from smallestUnit)"); + +const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfFloor" }); +assert.sameValue(result2, "2001-09-09T01:46:40.123987+00:00[UTC]", + "roundingMode is halfFloor (with 6 digits from fractionalSecondDigits)"); + +const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfFloor" }); +assert.sameValue(result3, "2001-09-09T01:46:40.124+00:00[UTC]", + "roundingMode is halfFloor (with 3 digits from smallestUnit)"); + +const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfFloor" }); +assert.sameValue(result4, "2001-09-09T01:46:40.124+00:00[UTC]", + "roundingMode is halfFloor (with 3 digits from fractionalSecondDigits)"); + +const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfFloor" }); +assert.sameValue(result5, "2001-09-09T01:46:40+00:00[UTC]", + "roundingMode is halfFloor (with 0 digits from smallestUnit)"); + +const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfFloor" }); +assert.sameValue(result6, "2001-09-09T01:46:40+00:00[UTC]", + "roundingMode is halfFloor (with 0 digits from fractionalSecondDigits)"); + +const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfFloor" }); +assert.sameValue(result7, "2001-09-09T01:47+00:00[UTC]", "roundingMode is halfFloor (round to minute)"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfTrunc.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..481a30a238 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toString/roundingmode-halfTrunc.js @@ -0,0 +1,37 @@ +// 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.zoneddatetime.prototype.tostring +description: halfTrunc value for roundingMode option +features: [Temporal] +---*/ + +const datetime = new Temporal.ZonedDateTime(1_000_000_000_123_987_500n, "UTC"); + +const result1 = datetime.toString({ smallestUnit: "microsecond", roundingMode: "halfTrunc" }); +assert.sameValue(result1, "2001-09-09T01:46:40.123987+00:00[UTC]", + "roundingMode is halfTrunc (with 6 digits from smallestUnit)"); + +const result2 = datetime.toString({ fractionalSecondDigits: 6, roundingMode: "halfTrunc" }); +assert.sameValue(result2, "2001-09-09T01:46:40.123987+00:00[UTC]", + "roundingMode is halfTrunc (with 6 digits from fractionalSecondDigits)"); + +const result3 = datetime.toString({ smallestUnit: "millisecond", roundingMode: "halfTrunc" }); +assert.sameValue(result3, "2001-09-09T01:46:40.124+00:00[UTC]", + "roundingMode is halfTrunc (with 3 digits from smallestUnit)"); + +const result4 = datetime.toString({ fractionalSecondDigits: 3, roundingMode: "halfTrunc" }); +assert.sameValue(result4, "2001-09-09T01:46:40.124+00:00[UTC]", + "roundingMode is halfTrunc (with 3 digits from fractionalSecondDigits)"); + +const result5 = datetime.toString({ smallestUnit: "second", roundingMode: "halfTrunc" }); +assert.sameValue(result5, "2001-09-09T01:46:40+00:00[UTC]", + "roundingMode is halfTrunc (with 0 digits from smallestUnit)"); + +const result6 = datetime.toString({ fractionalSecondDigits: 0, roundingMode: "halfTrunc" }); +assert.sameValue(result6, "2001-09-09T01:46:40+00:00[UTC]", + "roundingMode is halfTrunc (with 0 digits from fractionalSecondDigits)"); + +const result7 = datetime.toString({ smallestUnit: "minute", roundingMode: "halfTrunc" }); +assert.sameValue(result7, "2001-09-09T01:47+00:00[UTC]", "roundingMode is halfTrunc (round to minute)"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-expand.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-expand.js new file mode 100644 index 0000000000..7cff73d9d3 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-expand.js @@ -0,0 +1,42 @@ +// 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.zoneddatetime.prototype.until +description: Tests calculations with roundingMode "expand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC"); +const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC"); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 140], [0, 0, -140]], + ["days", [0, 0, 0, 974], [0, 0, 0, -974]], + ["hours", [0, 0, 0, 0, 23357], [0, 0, 0, 0, -23357]], + ["minutes", [0, 0, 0, 0, 23356, 18], [0, 0, 0, 0, -23356, -18]], + ["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 865], [0, 0, 0, 0, -23356, -17, -4, -865]], + ["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "expand"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfCeil.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfCeil.js new file mode 100644 index 0000000000..f54e082108 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfCeil.js @@ -0,0 +1,42 @@ +// 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.zoneddatetime.prototype.until +description: Tests calculations with roundingMode "halfCeil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC"); +const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC"); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23356]], + ["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -17]], + ["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfCeil"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfEven.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfEven.js new file mode 100644 index 0000000000..487964d016 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfEven.js @@ -0,0 +1,42 @@ +// 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.zoneddatetime.prototype.until +description: Tests calculations with roundingMode "halfEven". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC"); +const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC"); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23356]], + ["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -17]], + ["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfEven"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfFloor.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfFloor.js new file mode 100644 index 0000000000..1c326ff1b3 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfFloor.js @@ -0,0 +1,42 @@ +// 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.zoneddatetime.prototype.until +description: Tests calculations with roundingMode "halfFloor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC"); +const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC"); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23356]], + ["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -17]], + ["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfFloor"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +}); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfTrunc.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfTrunc.js new file mode 100644 index 0000000000..bf2f0308aa --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfTrunc.js @@ -0,0 +1,42 @@ +// 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.zoneddatetime.prototype.until +description: Tests calculations with roundingMode "halfTrunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = new Temporal.ZonedDateTime(1546935756_123_456_789n, "UTC"); +const later = new Temporal.ZonedDateTime(1631018380_987_654_321n, "UTC"); + +const expected = [ + ["years", [3], [-3]], + ["months", [0, 32], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23356]], + ["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -17]], + ["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -864]], + ["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 198], [0, 0, 0, 0, -23356, -17, -4, -864, -198]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "halfTrunc"; + +expected.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + const [py, pm = 0, pw = 0, pd = 0, ph = 0, pmin = 0, ps = 0, pms = 0, pµs = 0, pns = 0] = expectedPositive; + const [ny, nm = 0, nw = 0, nd = 0, nh = 0, nmin = 0, ns = 0, nms = 0, nµs = 0, nns = 0] = expectedNegative; + TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit, roundingMode }), + py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` + ); + TemporalHelpers.assertDuration( + later.until(earlier, { smallestUnit, roundingMode }), + ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + ); +});