From a788188c2f5a8794d9c44d07b73846bcb2e8dcf5 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 29 Jul 2022 17:28:04 -0700 Subject: [PATCH] Temporal: Regularize and expand tests for difference rounding modes Take all the existing tests for since/until calculations using different rounding modes and standardize them. Add tests for Instant and ZonedDateTime, which were still in the old format in staging. --- .../prototype/since/roundingmode-ceil.js | 39 +++ .../prototype/since/roundingmode-floor.js | 39 +++ .../since/roundingmode-halfExpand.js | 39 +++ .../prototype/since/roundingmode-trunc.js | 39 +++ .../prototype/until/roundingmode-ceil.js | 39 +++ .../prototype/until/roundingmode-floor.js | 39 +++ .../until/roundingmode-halfExpand.js | 39 +++ .../prototype/until/roundingmode-trunc.js | 39 +++ .../prototype/since/roundingmode-ceil.js | 50 ++-- .../prototype/since/roundingmode-floor.js | 50 ++-- .../since/roundingmode-halfExpand.js | 50 ++-- .../prototype/since/roundingmode-trunc.js | 50 ++-- .../prototype/until/roundingmode-ceil.js | 50 ++-- .../prototype/until/roundingmode-floor.js | 50 ++-- .../until/roundingmode-halfExpand.js | 50 ++-- .../prototype/until/roundingmode-trunc.js | 50 ++-- .../roundingmode-ceil.js} | 23 +- ...e-floor-basic.js => roundingmode-floor.js} | 12 +- .../since/roundingmode-halfExpand.js | 42 ++++ .../since/roundingmode-halfexpand-basic.js | 52 ---- .../since/roundingmode-trunc-basic.js | 54 ---- .../prototype/since/roundingmode-trunc.js | 42 ++++ .../roundingmode-ceil.js} | 16 +- ...e-floor-basic.js => roundingmode-floor.js} | 21 +- .../until/roundingmode-halfExpand.js | 42 ++++ .../until/roundingmode-halfexpand-basic.js | 51 ---- .../until/roundingmode-trunc-basic.js | 51 ---- .../prototype/until/roundingmode-trunc.js | 42 ++++ .../prototype/since/roundingmode-ceil.js | 66 ++--- .../prototype/since/roundingmode-floor.js | 67 ++--- .../since/roundingmode-halfExpand.js | 66 ++--- .../prototype/since/roundingmode-trunc.js | 66 ++--- .../prototype/until/roundingmode-ceil.js | 66 ++--- .../prototype/until/roundingmode-floor.js | 66 ++--- .../until/roundingmode-halfExpand.js | 66 ++--- .../prototype/until/roundingmode-trunc.js | 66 ++--- .../prototype/since/roundingmode-ceil.js | 36 +-- .../prototype/since/roundingmode-floor.js | 36 +-- .../since/roundingmode-halfExpand.js | 36 +-- .../prototype/since/roundingmode-trunc.js | 36 +-- .../prototype/until/roundingmode-ceil.js | 36 +-- .../prototype/until/roundingmode-floor.js | 36 +-- .../until/roundingmode-halfExpand.js | 36 +-- .../prototype/until/roundingmode-trunc.js | 36 +-- .../prototype/since/roundingmode-ceil.js | 42 ++++ .../prototype/since/roundingmode-floor.js | 42 ++++ .../since/roundingmode-halfExpand.js | 42 ++++ .../prototype/since/roundingmode-trunc.js | 42 ++++ .../prototype/until/roundingmode-ceil.js | 42 ++++ .../prototype/until/roundingmode-floor.js | 42 ++++ .../until/roundingmode-halfExpand.js | 42 ++++ .../prototype/until/roundingmode-trunc.js | 42 ++++ test/staging/Temporal/Instant/old/since.js | 176 ------------- test/staging/Temporal/Instant/old/until.js | 176 ------------- .../Temporal/ZonedDateTime/old/since.js | 232 ------------------ .../Temporal/ZonedDateTime/old/until.js | 232 ------------------ 56 files changed, 1416 insertions(+), 1713 deletions(-) create mode 100644 test/built-ins/Temporal/Instant/prototype/since/roundingmode-ceil.js create mode 100644 test/built-ins/Temporal/Instant/prototype/since/roundingmode-floor.js create mode 100644 test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfExpand.js create mode 100644 test/built-ins/Temporal/Instant/prototype/since/roundingmode-trunc.js create mode 100644 test/built-ins/Temporal/Instant/prototype/until/roundingmode-ceil.js create mode 100644 test/built-ins/Temporal/Instant/prototype/until/roundingmode-floor.js create mode 100644 test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfExpand.js create mode 100644 test/built-ins/Temporal/Instant/prototype/until/roundingmode-trunc.js rename test/built-ins/Temporal/PlainDateTime/prototype/{until/roundingmode-ceil-basic.js => since/roundingmode-ceil.js} (70%) rename test/built-ins/Temporal/PlainDateTime/prototype/since/{roundingmode-floor-basic.js => roundingmode-floor.js} (80%) create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfExpand.js delete mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfexpand-basic.js delete mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-trunc-basic.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-trunc.js rename test/built-ins/Temporal/PlainDateTime/prototype/{since/roundingmode-ceil-basic.js => until/roundingmode-ceil.js} (78%) rename test/built-ins/Temporal/PlainDateTime/prototype/until/{roundingmode-floor-basic.js => roundingmode-floor.js} (73%) create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfExpand.js delete mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfexpand-basic.js delete mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-trunc-basic.js create mode 100644 test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-trunc.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-ceil.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-floor.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfExpand.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-trunc.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-ceil.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-floor.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfExpand.js create mode 100644 test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-trunc.js diff --git a/test/built-ins/Temporal/Instant/prototype/since/roundingmode-ceil.js b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-ceil.js new file mode 100644 index 0000000000..2d12777942 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-ceil.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 "ceil". +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, -376435]], + ["minutes", [0, 0, 0, 0, 376435, 24], [0, 0, 0, 0, -376435, -23]], + ["seconds", [0, 0, 0, 0, 376435, 23, 9], [0, 0, 0, 0, -376435, -23, -8]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -148]], + ["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 530], [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 = "ceil"; +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-floor.js b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-floor.js new file mode 100644 index 0000000000..b44ae659fb --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-floor.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 "floor". +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, -376436]], + ["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -24]], + ["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -9]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 148], [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, -530]], + ["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]], +]; + +const roundingMode = "floor"; +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-halfExpand.js b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfExpand.js new file mode 100644 index 0000000000..99e4ccece3 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-halfExpand.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 "halfExpand". +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 = "halfExpand"; +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-trunc.js b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-trunc.js new file mode 100644 index 0000000000..a6936e2774 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/since/roundingmode-trunc.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 "trunc". +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, 148], [0, 0, 0, 0, -376435, -23, -8, -148]], + ["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 = "trunc"; +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/until/roundingmode-ceil.js b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-ceil.js new file mode 100644 index 0000000000..facf5fea70 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-ceil.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 "ceil". +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, -376435]], + ["minutes", [0, 0, 0, 0, 376435, 24], [0, 0, 0, 0, -376435, -23]], + ["seconds", [0, 0, 0, 0, 376435, 23, 9], [0, 0, 0, 0, -376435, -23, -8]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 149], [0, 0, 0, 0, -376435, -23, -8, -148]], + ["microseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 530], [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 = "ceil"; +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-floor.js b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-floor.js new file mode 100644 index 0000000000..c53ddb4e1b --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-floor.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 "floor". +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, -376436]], + ["minutes", [0, 0, 0, 0, 376435, 23], [0, 0, 0, 0, -376435, -24]], + ["seconds", [0, 0, 0, 0, 376435, 23, 8], [0, 0, 0, 0, -376435, -23, -9]], + ["milliseconds", [0, 0, 0, 0, 376435, 23, 8, 148], [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, -530]], + ["nanoseconds", [0, 0, 0, 0, 376435, 23, 8, 148, 529, 313], [0, 0, 0, 0, -376435, -23, -8, -148, -529, -313]], +]; + +const roundingMode = "floor"; +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-halfExpand.js b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfExpand.js new file mode 100644 index 0000000000..9d38b71558 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-halfExpand.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 "halfExpand". +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 = "halfExpand"; +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-trunc.js b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-trunc.js new file mode 100644 index 0000000000..ed35d3b797 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/until/roundingmode-trunc.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 "trunc". +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, 148], [0, 0, 0, 0, -376435, -23, -8, -148]], + ["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 = "trunc"; +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-ceil.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-ceil.js index cf9a9f116d..3c73c58de8 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-ceil.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-ceil.js @@ -8,33 +8,29 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainDate.from("2019-01-08"); -const later = Temporal.PlainDate.from("2021-09-07"); +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "years", roundingMode: "ceil" }), - /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "years", roundingMode: "ceil" }), - /* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [3], [-2]], + ["months", [0, 32], [0, -31]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "months", roundingMode: "ceil" }), - 0, /* months = */ 32, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "months", roundingMode: "ceil" }), - 0, /* months = */ -31, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "ceil"; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "weeks", roundingMode: "ceil" }), - 0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "weeks", roundingMode: "ceil" }), - 0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "days", roundingMode: "ceil" }), - 0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "days", roundingMode: "ceil" }), - 0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days"); +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-floor.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-floor.js index 3629833c13..d765a01129 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-floor.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-floor.js @@ -8,33 +8,29 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainDate.from("2019-01-08"); -const later = Temporal.PlainDate.from("2021-09-07"); +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "years", roundingMode: "floor" }), - /* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "years", roundingMode: "floor" }), - /* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [2], [-3]], + ["months", [0, 31], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "months", roundingMode: "floor" }), - 0, /* months = */ 31, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "months", roundingMode: "floor" }), - 0, /* months = */ -32, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "floor"; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "weeks", roundingMode: "floor" }), - 0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "weeks", roundingMode: "floor" }), - 0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "days", roundingMode: "floor" }), - 0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "days", roundingMode: "floor" }), - 0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days"); +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-halfExpand.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfExpand.js index c2d62ed4a5..9b49462787 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfExpand.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfExpand.js @@ -8,33 +8,29 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainDate.from("2019-01-08"); -const later = Temporal.PlainDate.from("2021-09-07"); +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "years", roundingMode: "halfExpand" }), - /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "years", roundingMode: "halfExpand" }), - /* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +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]], +]; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "months", roundingMode: "halfExpand" }), - 0, /* months = */ 32, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "months", roundingMode: "halfExpand" }), - 0, /* months = */ -32, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "halfExpand"; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "weeks", roundingMode: "halfExpand" }), - 0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "weeks", roundingMode: "halfExpand" }), - 0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "days", roundingMode: "halfExpand" }), - 0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "days", roundingMode: "halfExpand" }), - 0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days"); +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-trunc.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-trunc.js index c511fa1967..3a30bac94d 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-trunc.js +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-trunc.js @@ -8,33 +8,29 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainDate.from("2019-01-08"); -const later = Temporal.PlainDate.from("2021-09-07"); +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "years", roundingMode: "trunc" }), - /* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "years", roundingMode: "trunc" }), - /* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [2], [-2]], + ["months", [0, 31], [0, -31]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "months", roundingMode: "trunc" }), - 0, /* months = */ 31, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "months", roundingMode: "trunc" }), - 0, /* months = */ -31, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "trunc"; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "weeks", roundingMode: "trunc" }), - 0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "weeks", roundingMode: "trunc" }), - 0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "days", roundingMode: "trunc" }), - 0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "days", roundingMode: "trunc" }), - 0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days"); +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-ceil.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-ceil.js index 1707a31f05..44aa2e3b44 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-ceil.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-ceil.js @@ -8,33 +8,29 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainDate.from("2019-01-08"); -const later = Temporal.PlainDate.from("2021-09-07"); +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "years", roundingMode: "ceil" }), - /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "years", roundingMode: "ceil" }), - /* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [3], [-2]], + ["months", [0, 32], [0, -31]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "months", roundingMode: "ceil" }), - 0, /* months = */ 32, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "months", roundingMode: "ceil" }), - 0, /* months = */ -31, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "ceil"; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "weeks", roundingMode: "ceil" }), - 0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "weeks", roundingMode: "ceil" }), - 0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "days", roundingMode: "ceil" }), - 0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "days", roundingMode: "ceil" }), - 0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days"); +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-floor.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-floor.js index f2bfd839ad..7af7fa28af 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-floor.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-floor.js @@ -8,33 +8,29 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainDate.from("2019-01-08"); -const later = Temporal.PlainDate.from("2021-09-07"); +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "years", roundingMode: "floor" }), - /* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "years", roundingMode: "floor" }), - /* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [2], [-3]], + ["months", [0, 31], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "months", roundingMode: "floor" }), - 0, /* months = */ 31, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "months", roundingMode: "floor" }), - 0, /* months = */ -32, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "floor"; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "weeks", roundingMode: "floor" }), - 0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "weeks", roundingMode: "floor" }), - 0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "days", roundingMode: "floor" }), - 0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "days", roundingMode: "floor" }), - 0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days"); +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-halfExpand.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfExpand.js index 652b31edc7..5b308f9b15 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfExpand.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfExpand.js @@ -8,33 +8,29 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainDate.from("2019-01-08"); -const later = Temporal.PlainDate.from("2021-09-07"); +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "years", roundingMode: "halfExpand" }), - /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "years", roundingMode: "halfExpand" }), - /* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +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]], +]; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "months", roundingMode: "halfExpand" }), - 0, /* months = */ 32, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "months", roundingMode: "halfExpand" }), - 0, /* months = */ -32, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "halfExpand"; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "weeks", roundingMode: "halfExpand" }), - 0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "weeks", roundingMode: "halfExpand" }), - 0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "days", roundingMode: "halfExpand" }), - 0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "days", roundingMode: "halfExpand" }), - 0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days"); +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-trunc.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-trunc.js index aed446983a..c7b69d3b7f 100644 --- a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-trunc.js +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-trunc.js @@ -8,33 +8,29 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainDate.from("2019-01-08"); -const later = Temporal.PlainDate.from("2021-09-07"); +const earlier = new Temporal.PlainDate(2019, 1, 8); +const later = new Temporal.PlainDate(2021, 9, 7); -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "years", roundingMode: "trunc" }), - /* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "years", roundingMode: "trunc" }), - /* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [2], [-2]], + ["months", [0, 31], [0, -31]], + ["weeks", [0, 0, 139], [0, 0, -139]], + ["days", [0, 0, 0, 973], [0, 0, 0, -973]], +]; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "months", roundingMode: "trunc" }), - 0, /* months = */ 31, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "months", roundingMode: "trunc" }), - 0, /* months = */ -31, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "trunc"; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "weeks", roundingMode: "trunc" }), - 0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "weeks", roundingMode: "trunc" }), - 0, 0, /* weeks = */ -139, 0, 0, 0, 0, 0, 0, 0, "weeks"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "days", roundingMode: "trunc" }), - 0, 0, 0, /* days = */ 973, 0, 0, 0, 0, 0, 0, "days"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "days", roundingMode: "trunc" }), - 0, 0, 0, /* days = */ -973, 0, 0, 0, 0, 0, 0, "days"); +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-ceil-basic.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-ceil.js similarity index 70% rename from test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-ceil-basic.js rename to test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-ceil.js index 4f4a4ded7d..048ecc5a53 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-ceil-basic.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-ceil.js @@ -2,16 +2,16 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.plaindatetime.prototype.until -description: Checking that ceiling rounding mode rounds correctly -features: [Temporal] +esid: sec-temporal.plaindatetime.prototype.since +description: Tests calculations with roundingMode "ceil". 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 incrementOneCeil = [ +const expected = [ ["years", [3], [-2]], ["months", [0, 32], [0, -31]], ["weeks", [0, 0, 140], [0, 0, -139]], @@ -21,19 +21,22 @@ const incrementOneCeil = [ ["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -4]], ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 865], [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, -197]], - ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]] + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], ]; -incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + +const roundingMode = "ceil"; + +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: "ceil" }), + later.since(earlier, { smallestUnit, roundingMode }), py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, - `rounds up to ${smallestUnit} (roundingMode = ceil, positive case)` + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` ); TemporalHelpers.assertDuration( - later.until(earlier, {smallestUnit, roundingMode: "ceil"}), + earlier.since(later, { smallestUnit, roundingMode }), ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, - `rounds up to ${smallestUnit} (rounding mode = ceil, negative case)` + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` ); }); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-floor-basic.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-floor.js similarity index 80% rename from test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-floor-basic.js rename to test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-floor.js index e075d51dbf..11dca6d296 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-floor-basic.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-floor.js @@ -3,7 +3,7 @@ /*--- esid: sec-temporal.plaindatetime.prototype.since -description: Floor rounding mode basic tests +description: Tests calculations with roundingMode "floor". includes: [temporalHelpers.js] features: [Temporal] ---*/ @@ -11,7 +11,7 @@ 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 incrementOneFloor = [ +const expected = [ ["years", [2], [-3]], ["months", [0, 31], [0, -32]], ["weeks", [0, 0, 139], [0, 0, -140]], @@ -21,22 +21,22 @@ const incrementOneFloor = [ ["seconds", [0, 0, 0, 973, 4, 17, 4], [0, 0, 0, -973, -4, -17, -5]], ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -865]], ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197], [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]] + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], ]; const roundingMode = "floor"; -incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { +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 down to ${smallestUnit} (rounding mode = ${roundingMode}, positive case)` + `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 down to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` ); }); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfExpand.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfExpand.js new file mode 100644 index 0000000000..3e84508af9 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfExpand.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 "halfExpand". +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 = "halfExpand"; + +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-halfexpand-basic.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfexpand-basic.js deleted file mode 100644 index 92d28c3734..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-halfexpand-basic.js +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.plaindatetime.prototype.since -description: Half-expand rounding mode basic tests -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); - -function ensureUnsignedZero(x) { - return Object.is(x, -0) ? 0 : x; -} - -const incrementOneNearest = [ - ["years", [3]], - ["months", [0, 32]], - ["weeks", [0, 0, 139]], - ["days", [0, 0, 0, 973]], - ["hours", [0, 0, 0, 973, 4]], - ["minutes", [0, 0, 0, 973, 4, 17]], - ["seconds", [0, 0, 0, 973, 4, 17, 5]], - ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864]], - ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198]], - ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532]] -]; -const roundingMode = "halfExpand"; -incrementOneNearest.forEach(([smallestUnit, expected]) => { - const [y, m = 0, w = 0, d = 0, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; - TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit, roundingMode }), - y, m, w, d, h, min, s, ms, µs, ns, - `rounds to nearest ${smallestUnit} (rounding mode = ${roundingMode}, positive case)` - ); - TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit, roundingMode }), - ensureUnsignedZero(-y), - ensureUnsignedZero(-m), - ensureUnsignedZero(-w), - ensureUnsignedZero(-d), - ensureUnsignedZero(-h), - ensureUnsignedZero(-min), - ensureUnsignedZero(-s), - ensureUnsignedZero(-ms), - ensureUnsignedZero(-µs), - ensureUnsignedZero(-ns), - `rounds to nearest ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` - ); -}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-trunc-basic.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-trunc-basic.js deleted file mode 100644 index 4874694cc9..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-trunc-basic.js +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.plaindatetime.prototype.since -description: Truncation rounding mode basic tests -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); - -function ensureUnsignedZero(x) { - return Object.is(x, -0) ? 0 : x; -} - -const incrementOneTrunc = [ - ["years", [2]], - ["months", [0, 31]], - ["weeks", [0, 0, 139]], - ["days", [0, 0, 0, 973]], - ["hours", [0, 0, 0, 973, 4]], - ["minutes", [0, 0, 0, 973, 4, 17]], - ["seconds", [0, 0, 0, 973, 4, 17, 4]], - ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864]], - ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197]], - ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532]] -]; - -const roundingMode = "trunc"; - -incrementOneTrunc.forEach(([smallestUnit, expected]) => { - const [y, m = 0, w = 0, d = 0, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; - TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit, roundingMode }), - y, m, w, d, h, min, s, ms, µs, ns, - `truncates to ${smallestUnit} (rounding mode = ${roundingMode}, positive case)` - ); - TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit, roundingMode }), - ensureUnsignedZero(-y), - ensureUnsignedZero(-m), - ensureUnsignedZero(-w), - ensureUnsignedZero(-d), - ensureUnsignedZero(-h), - ensureUnsignedZero(-min), - ensureUnsignedZero(-s), - ensureUnsignedZero(-ms), - ensureUnsignedZero(-µs), - ensureUnsignedZero(-ns), - `truncates to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` - ); -}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-trunc.js b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-trunc.js new file mode 100644 index 0000000000..7d7a89e019 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-trunc.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 "trunc". +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", [2], [-2]], + ["months", [0, 31], [0, -31]], + ["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, 4], [0, 0, 0, -973, -4, -17, -4]], + ["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, 197], [0, 0, 0, -973, -4, -17, -4, -864, -197]], + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "trunc"; + +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-ceil-basic.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-ceil.js similarity index 78% rename from test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-ceil-basic.js rename to test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-ceil.js index fd82fdbfdf..7d5e0110c4 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/since/roundingmode-ceil-basic.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-ceil.js @@ -2,8 +2,8 @@ // This code is governed by the BSD license found in the LICENSE file. /*--- -esid: sec-temporal.plaindatetime.prototype.since -description: Ceiling rounding mode basic tests +esid: sec-temporal.plaindatetime.prototype.until +description: Tests calculations with roundingMode "ceil". includes: [temporalHelpers.js] features: [Temporal] ---*/ @@ -11,7 +11,7 @@ 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 incrementOneCeil = [ +const expected = [ ["years", [3], [-2]], ["months", [0, 32], [0, -31]], ["weeks", [0, 0, 140], [0, 0, -139]], @@ -21,20 +21,22 @@ const incrementOneCeil = [ ["seconds", [0, 0, 0, 973, 4, 17, 5], [0, 0, 0, -973, -4, -17, -4]], ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 865], [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, -197]], - ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]] + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], ]; + const roundingMode = "ceil"; -incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + +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 up to ${smallestUnit} (roundingMode = ceil, positive case)` + `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 up to ${smallestUnit} (rounding mode = ceil, negative case)` + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` ); }); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-floor-basic.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-floor.js similarity index 73% rename from test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-floor-basic.js rename to test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-floor.js index d9a021e9ac..3225334dbb 100644 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-floor-basic.js +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-floor.js @@ -3,15 +3,15 @@ /*--- esid: sec-temporal.plaindatetime.prototype.until -description: Checking that floor rounding mode rounds correctly -features: [Temporal] +description: Tests calculations with roundingMode "floor". 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 incrementOneFloor = [ +const expected = [ ["years", [2], [-3]], ["months", [0, 31], [0, -32]], ["weeks", [0, 0, 139], [0, 0, -140]], @@ -21,19 +21,22 @@ const incrementOneFloor = [ ["seconds", [0, 0, 0, 973, 4, 17, 4], [0, 0, 0, -973, -4, -17, -5]], ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864], [0, 0, 0, -973, -4, -17, -4, -865]], ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197], [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]] + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], ]; -incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { + +const roundingMode = "floor"; + +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: "floor" }), + earlier.until(later, { smallestUnit, roundingMode }), py, pm, pw, pd, ph, pmin, ps, pms, pµs, pns, - `rounds down to ${smallestUnit} (rounding mode = floor, positive case)` + `rounds to ${smallestUnit} (roundingMode = ${roundingMode}, positive case)` ); TemporalHelpers.assertDuration( - later.until(earlier, {smallestUnit, roundingMode: "floor"}), + later.until(earlier, { smallestUnit, roundingMode }), ny, nm, nw, nd, nh, nmin, ns, nms, nµs, nns, - `rounds down to ${smallestUnit} (rounding mode = floor, negative case)` + `rounds to ${smallestUnit} (rounding mode = ${roundingMode}, negative case)` ); }); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfExpand.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfExpand.js new file mode 100644 index 0000000000..a70628b4ea --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfExpand.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 "halfExpand". +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 = "halfExpand"; + +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-halfexpand-basic.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfexpand-basic.js deleted file mode 100644 index f0d4ff1cd5..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-halfexpand-basic.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.plaindatetime.prototype.until -description: Checking that half-expand rounding mode rounds correctly -features: [Temporal] -includes: [temporalHelpers.js] ----*/ - -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); - -function ensureUnsignedZero(x) { - return Object.is(x, -0) ? 0 : x; -} - -const incrementOneNearest = [ - ["years", [3]], - ["months", [0, 32]], - ["weeks", [0, 0, 139]], - ["days", [0, 0, 0, 973]], - ["hours", [0, 0, 0, 973, 4]], - ["minutes", [0, 0, 0, 973, 4, 17]], - ["seconds", [0, 0, 0, 973, 4, 17, 5]], - ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864]], - ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 198]], - ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532]] -]; -incrementOneNearest.forEach(([smallestUnit, expected]) => { - const [y, m = 0, w = 0, d = 0, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; - TemporalHelpers.assertDuration( - earlier.until(later, {smallestUnit, roundingMode: "halfExpand"}), - y, m, w, d, h, min, s, ms, µs, ns, - `rounds to nearest ${smallestUnit} (positive case, rounding mode = halfExpand)` - ); - TemporalHelpers.assertDuration( - later.until(earlier, {smallestUnit, roundingMode: "halfExpand"}), - ensureUnsignedZero(-y), - ensureUnsignedZero(-m), - ensureUnsignedZero(-w), - ensureUnsignedZero(-d), - ensureUnsignedZero(-h), - ensureUnsignedZero(-min), - ensureUnsignedZero(-s), - ensureUnsignedZero(-ms), - ensureUnsignedZero(-µs), - ensureUnsignedZero(-ns), - `rounds to nearest ${smallestUnit} (negative case, rounding mode = halfExpand)` - ); -}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-trunc-basic.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-trunc-basic.js deleted file mode 100644 index 844e3083c2..0000000000 --- a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-trunc-basic.js +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (C) 2022 Igalia, S.L. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal.plaindatetime.prototype.until -description: A variety of tests for truncation (trunc) round mode -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); - -function ensureUnsignedZero(x) { - return Object.is(x, -0) ? 0 : x; -} - -const incrementOneTrunc = [ - ["years", [2]], - ["months", [0, 31]], - ["weeks", [0, 0, 139]], - ["days", [0, 0, 0, 973]], - ["hours", [0, 0, 0, 973, 4]], - ["minutes", [0, 0, 0, 973, 4, 17]], - ["seconds", [0, 0, 0, 973, 4, 17, 4]], - ["milliseconds", [0, 0, 0, 973, 4, 17, 4, 864]], - ["microseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197]], - ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532]] -]; -incrementOneTrunc.forEach(([smallestUnit, expected]) => { - const [y, m = 0, w = 0, d = 0, h = 0, min = 0, s = 0, ms = 0, µs = 0, ns = 0] = expected; - TemporalHelpers.assertDuration( - earlier.until(later, {smallestUnit, roundingMode: "trunc"}), - y, m, w, d, h, min, s, ms, µs, ns, - `truncates to ${smallestUnit} (rounding mode = trunc, positive case)` - ); - TemporalHelpers.assertDuration( - later.until(earlier, {smallestUnit, roundingMode: "trunc"}), - ensureUnsignedZero(-y), - ensureUnsignedZero(-m), - ensureUnsignedZero(-w), - ensureUnsignedZero(-d), - ensureUnsignedZero(-h), - ensureUnsignedZero(-min), - ensureUnsignedZero(-s), - ensureUnsignedZero(-ms), - ensureUnsignedZero(-µs), - ensureUnsignedZero(-ns), - `truncates to ${smallestUnit} (rounding mode = trunc, negative case)` - ); -}); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-trunc.js b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-trunc.js new file mode 100644 index 0000000000..eb87726eac --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/until/roundingmode-trunc.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 "trunc". +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", [2], [-2]], + ["months", [0, 31], [0, -31]], + ["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, 4], [0, 0, 0, -973, -4, -17, -4]], + ["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, 197], [0, 0, 0, -973, -4, -17, -4, -864, -197]], + ["nanoseconds", [0, 0, 0, 973, 4, 17, 4, 864, 197, 532], [0, 0, 0, -973, -4, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "trunc"; + +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/since/roundingmode-ceil.js b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-ceil.js index 6d83292fbc..3d1578d7d7 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-ceil.js +++ b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-ceil.js @@ -8,47 +8,31 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainTime.from("08:22:36.123456789"); -const later = Temporal.PlainTime.from("12:39:40.987654321"); +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "hours", roundingMode: "ceil" }), - 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, "hours"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "hours", roundingMode: "ceil" }), - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours"); +const expected = [ + ["hours", [0, 0, 0, 0, 5], [0, 0, 0, 0, -4]], + ["minutes", [0, 0, 0, 0, 4, 18], [0, 0, 0, 0, -4, -17]], + ["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -4]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 865], [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, -197]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "minutes", roundingMode: "ceil" }), - 0, 0, 0, 0, 4, 18, 0, 0, 0, 0, "minutes"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "minutes", roundingMode: "ceil" }), - 0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes"); +const roundingMode = "ceil"; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "seconds", roundingMode: "ceil" }), - 0, 0, 0, 0, 4, 17, 5, 0, 0, 0, "seconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "seconds", roundingMode: "ceil" }), - 0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "milliseconds", roundingMode: "ceil" }), - 0, 0, 0, 0, 4, 17, 4, 865, 0, 0, "milliseconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "milliseconds", roundingMode: "ceil" }), - 0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "microseconds", roundingMode: "ceil" }), - 0, 0, 0, 0, 4, 17, 4, 864, 198, 0, "microseconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "microseconds", roundingMode: "ceil" }), - 0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: "ceil" }), - 0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: "ceil" }), - 0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds"); +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-floor.js b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-floor.js index 65ffaae110..88a8530e98 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-floor.js +++ b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-floor.js @@ -8,48 +8,31 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainTime.from("08:22:36.123456789"); -const later = Temporal.PlainTime.from("12:39:40.987654321"); +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "hours", roundingMode: "floor" }), - 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "hours", roundingMode: "floor" }), - 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, "hours"); +const expected = [ + ["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -5]], + ["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -18]], + ["seconds", [0, 0, 0, 0, 4, 17, 4], [0, 0, 0, 0, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -865]], + ["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197], [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]], +]; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "minutes", roundingMode: "floor" }), - 0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "minutes", roundingMode: "floor" }), - 0, 0, 0, 0, -4, -18, 0, 0, 0, 0, "minutes"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "seconds", roundingMode: "floor" }), - 0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "seconds", roundingMode: "floor" }), - 0, 0, 0, 0, -4, -17, -5, 0, 0, 0, "seconds"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "milliseconds", roundingMode: "floor" }), - 0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "milliseconds", roundingMode: "floor" }), - 0, 0, 0, 0, -4, -17, -4, -865, 0, 0, "milliseconds"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "microseconds", roundingMode: "floor" }), - 0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "microseconds", roundingMode: "floor" }), - 0, 0, 0, 0, -4, -17, -4, -864, -198, 0, "microseconds"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: "floor" }), - 0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: "floor" }), - 0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds"); +const roundingMode = "floor"; +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-halfExpand.js b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfExpand.js index 22ad25414d..1c3445f685 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfExpand.js +++ b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-halfExpand.js @@ -8,47 +8,31 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainTime.from("08:22:36.123456789"); -const later = Temporal.PlainTime.from("12:39:40.987654321"); +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "hours", roundingMode: "halfExpand" }), - 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "hours", roundingMode: "halfExpand" }), - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours"); +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]], +]; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "minutes", roundingMode: "halfExpand" }), - 0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "minutes", roundingMode: "halfExpand" }), - 0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes"); +const roundingMode = "halfExpand"; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "seconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, 4, 17, 5, 0, 0, 0, "seconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "seconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, -4, -17, -5, 0, 0, 0, "seconds"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "milliseconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "milliseconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "microseconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, 4, 17, 4, 864, 198, 0, "microseconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "microseconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, -4, -17, -4, -864, -198, 0, "microseconds"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds"); +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-trunc.js b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-trunc.js index 521dead757..5c96dc3494 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-trunc.js +++ b/test/built-ins/Temporal/PlainTime/prototype/since/roundingmode-trunc.js @@ -8,47 +8,31 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainTime.from("08:22:36.123456789"); -const later = Temporal.PlainTime.from("12:39:40.987654321"); +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "hours", roundingMode: "trunc" }), - 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "hours", roundingMode: "trunc" }), - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours"); +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, 4], [0, 0, 0, 0, -4, -17, -4]], + ["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, 197], [0, 0, 0, 0, -4, -17, -4, -864, -197]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "minutes", roundingMode: "trunc" }), - 0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "minutes", roundingMode: "trunc" }), - 0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes"); +const roundingMode = "trunc"; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "seconds", roundingMode: "trunc" }), - 0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "seconds", roundingMode: "trunc" }), - 0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "milliseconds", roundingMode: "trunc" }), - 0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "milliseconds", roundingMode: "trunc" }), - 0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "microseconds", roundingMode: "trunc" }), - 0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "microseconds", roundingMode: "trunc" }), - 0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds"); - -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "nanoseconds", roundingMode: "trunc" }), - 0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "nanoseconds", roundingMode: "trunc" }), - 0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds"); +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/until/roundingmode-ceil.js b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-ceil.js index 5d15c343f0..451e1f0380 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-ceil.js +++ b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-ceil.js @@ -8,47 +8,31 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainTime.from("08:22:36.123456789"); -const later = Temporal.PlainTime.from("12:39:40.987654321"); +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "hours", roundingMode: "ceil" }), - 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, "hours"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "hours", roundingMode: "ceil" }), - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours"); +const expected = [ + ["hours", [0, 0, 0, 0, 5], [0, 0, 0, 0, -4]], + ["minutes", [0, 0, 0, 0, 4, 18], [0, 0, 0, 0, -4, -17]], + ["seconds", [0, 0, 0, 0, 4, 17, 5], [0, 0, 0, 0, -4, -17, -4]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 865], [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, -197]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "minutes", roundingMode: "ceil" }), - 0, 0, 0, 0, 4, 18, 0, 0, 0, 0, "minutes"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "minutes", roundingMode: "ceil" }), - 0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes"); +const roundingMode = "ceil"; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "seconds", roundingMode: "ceil" }), - 0, 0, 0, 0, 4, 17, 5, 0, 0, 0, "seconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "seconds", roundingMode: "ceil" }), - 0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "milliseconds", roundingMode: "ceil" }), - 0, 0, 0, 0, 4, 17, 4, 865, 0, 0, "milliseconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "milliseconds", roundingMode: "ceil" }), - 0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "microseconds", roundingMode: "ceil" }), - 0, 0, 0, 0, 4, 17, 4, 864, 198, 0, "microseconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "microseconds", roundingMode: "ceil" }), - 0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: "ceil" }), - 0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: "ceil" }), - 0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds"); +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-floor.js b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-floor.js index 1ab01526c5..3618978674 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-floor.js +++ b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-floor.js @@ -8,47 +8,31 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainTime.from("08:22:36.123456789"); -const later = Temporal.PlainTime.from("12:39:40.987654321"); +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "hours", roundingMode: "floor" }), - 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "hours", roundingMode: "floor" }), - 0, 0, 0, 0, -5, 0, 0, 0, 0, 0, "hours"); +const expected = [ + ["hours", [0, 0, 0, 0, 4], [0, 0, 0, 0, -5]], + ["minutes", [0, 0, 0, 0, 4, 17], [0, 0, 0, 0, -4, -18]], + ["seconds", [0, 0, 0, 0, 4, 17, 4], [0, 0, 0, 0, -4, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 4, 17, 4, 864], [0, 0, 0, 0, -4, -17, -4, -865]], + ["microseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197], [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]], +]; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "minutes", roundingMode: "floor" }), - 0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "minutes", roundingMode: "floor" }), - 0, 0, 0, 0, -4, -18, 0, 0, 0, 0, "minutes"); +const roundingMode = "floor"; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "seconds", roundingMode: "floor" }), - 0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "seconds", roundingMode: "floor" }), - 0, 0, 0, 0, -4, -17, -5, 0, 0, 0, "seconds"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "milliseconds", roundingMode: "floor" }), - 0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "milliseconds", roundingMode: "floor" }), - 0, 0, 0, 0, -4, -17, -4, -865, 0, 0, "milliseconds"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "microseconds", roundingMode: "floor" }), - 0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "microseconds", roundingMode: "floor" }), - 0, 0, 0, 0, -4, -17, -4, -864, -198, 0, "microseconds"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: "floor" }), - 0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: "floor" }), - 0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds"); +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-halfExpand.js b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfExpand.js index fe4dbd69c5..9e5f867362 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfExpand.js +++ b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-halfExpand.js @@ -8,47 +8,31 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainTime.from("08:22:36.123456789"); -const later = Temporal.PlainTime.from("12:39:40.987654321"); +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "hours", roundingMode: "halfExpand" }), - 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "hours", roundingMode: "halfExpand" }), - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours"); +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]], +]; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "minutes", roundingMode: "halfExpand" }), - 0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "minutes", roundingMode: "halfExpand" }), - 0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes"); +const roundingMode = "halfExpand"; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "seconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, 4, 17, 5, 0, 0, 0, "seconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "seconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, -4, -17, -5, 0, 0, 0, "seconds"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "milliseconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "milliseconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "microseconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, 4, 17, 4, 864, 198, 0, "microseconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "microseconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, -4, -17, -4, -864, -198, 0, "microseconds"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: "halfExpand" }), - 0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds"); +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-trunc.js b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-trunc.js index 5897a126fe..9aed1bd48c 100644 --- a/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-trunc.js +++ b/test/built-ins/Temporal/PlainTime/prototype/until/roundingmode-trunc.js @@ -8,47 +8,31 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainTime.from("08:22:36.123456789"); -const later = Temporal.PlainTime.from("12:39:40.987654321"); +const earlier = new Temporal.PlainTime(8, 22, 36, 123, 456, 789); +const later = new Temporal.PlainTime(12, 39, 40, 987, 654, 321); -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "hours", roundingMode: "trunc" }), - 0, 0, 0, 0, 4, 0, 0, 0, 0, 0, "hours"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "hours", roundingMode: "trunc" }), - 0, 0, 0, 0, -4, 0, 0, 0, 0, 0, "hours"); +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, 4], [0, 0, 0, 0, -4, -17, -4]], + ["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, 197], [0, 0, 0, 0, -4, -17, -4, -864, -197]], + ["nanoseconds", [0, 0, 0, 0, 4, 17, 4, 864, 197, 532], [0, 0, 0, 0, -4, -17, -4, -864, -197, -532]], +]; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "minutes", roundingMode: "trunc" }), - 0, 0, 0, 0, 4, 17, 0, 0, 0, 0, "minutes"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "minutes", roundingMode: "trunc" }), - 0, 0, 0, 0, -4, -17, 0, 0, 0, 0, "minutes"); +const roundingMode = "trunc"; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "seconds", roundingMode: "trunc" }), - 0, 0, 0, 0, 4, 17, 4, 0, 0, 0, "seconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "seconds", roundingMode: "trunc" }), - 0, 0, 0, 0, -4, -17, -4, 0, 0, 0, "seconds"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "milliseconds", roundingMode: "trunc" }), - 0, 0, 0, 0, 4, 17, 4, 864, 0, 0, "milliseconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "milliseconds", roundingMode: "trunc" }), - 0, 0, 0, 0, -4, -17, -4, -864, 0, 0, "milliseconds"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "microseconds", roundingMode: "trunc" }), - 0, 0, 0, 0, 4, 17, 4, 864, 197, 0, "microseconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "microseconds", roundingMode: "trunc" }), - 0, 0, 0, 0, -4, -17, -4, -864, -197, 0, "microseconds"); - -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "nanoseconds", roundingMode: "trunc" }), - 0, 0, 0, 0, 4, 17, 4, 864, 197, 532, "nanoseconds"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "nanoseconds", roundingMode: "trunc" }), - 0, 0, 0, 0, -4, -17, -4, -864, -197, -532, "nanoseconds"); +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-ceil.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-ceil.js index 5b6264cd78..2c3c0e3e02 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-ceil.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-ceil.js @@ -8,19 +8,27 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainYearMonth.from("2019-01"); -const later = Temporal.PlainYearMonth.from("2021-09"); +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "years", roundingMode: "ceil" }), - /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "years", roundingMode: "ceil" }), - /* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [3], [-2]], + ["months", [2, 8], [-2, -8]], +]; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "months", roundingMode: "ceil" }), - /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "months", roundingMode: "ceil" }), - /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "ceil"; + +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-floor.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-floor.js index f11231fd0b..0a68373f57 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-floor.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-floor.js @@ -8,19 +8,27 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainYearMonth.from("2019-01"); -const later = Temporal.PlainYearMonth.from("2021-09"); +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "years", roundingMode: "floor" }), - /* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "years", roundingMode: "floor" }), - /* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [2], [-3]], + ["months", [2, 8], [-2, -8]], +]; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "months", roundingMode: "floor" }), - /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "months", roundingMode: "floor" }), - /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "floor"; + +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-halfExpand.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfExpand.js index e17a39e7c7..436827b345 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfExpand.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-halfExpand.js @@ -8,19 +8,27 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainYearMonth.from("2019-01"); -const later = Temporal.PlainYearMonth.from("2021-09"); +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "years", roundingMode: "halfExpand" }), - /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "years", roundingMode: "halfExpand" }), - /* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [3], [-3]], + ["months", [2, 8], [-2, -8]], +]; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "months", roundingMode: "halfExpand" }), - /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "months", roundingMode: "halfExpand" }), - /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "halfExpand"; + +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-trunc.js b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-trunc.js index 98f2dc030e..7274730529 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-trunc.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/since/roundingmode-trunc.js @@ -8,19 +8,27 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainYearMonth.from("2019-01"); -const later = Temporal.PlainYearMonth.from("2021-09"); +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "years", roundingMode: "trunc" }), - /* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "years", roundingMode: "trunc" }), - /* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [2], [-2]], + ["months", [2, 8], [-2, -8]], +]; -TemporalHelpers.assertDuration( - later.since(earlier, { smallestUnit: "months", roundingMode: "trunc" }), - /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - earlier.since(later, { smallestUnit: "months", roundingMode: "trunc" }), - /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "trunc"; + +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-ceil.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-ceil.js index 550223b1be..0a1ac1c547 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-ceil.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-ceil.js @@ -8,19 +8,27 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainYearMonth.from("2019-01"); -const later = Temporal.PlainYearMonth.from("2021-09"); +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "years", roundingMode: "ceil" }), - /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "years", roundingMode: "ceil" }), - /* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [3], [-2]], + ["months", [2, 8], [-2, -8]], +]; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "months", roundingMode: "ceil" }), - /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "months", roundingMode: "ceil" }), - /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "ceil"; + +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-floor.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-floor.js index 26b5359ca9..4d06467b06 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-floor.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-floor.js @@ -8,19 +8,27 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainYearMonth.from("2019-01"); -const later = Temporal.PlainYearMonth.from("2021-09"); +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "years", roundingMode: "floor" }), - /* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "years", roundingMode: "floor" }), - /* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [2], [-3]], + ["months", [2, 8], [-2, -8]], +]; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "months", roundingMode: "floor" }), - /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "months", roundingMode: "floor" }), - /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "floor"; + +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-halfExpand.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfExpand.js index 9f52de0975..12e0b6ab2e 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfExpand.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-halfExpand.js @@ -8,19 +8,27 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainYearMonth.from("2019-01"); -const later = Temporal.PlainYearMonth.from("2021-09"); +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "years", roundingMode: "halfExpand" }), - /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "years", roundingMode: "halfExpand" }), - /* years = */ -3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [3], [-3]], + ["months", [2, 8], [-2, -8]], +]; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "months", roundingMode: "halfExpand" }), - /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "months", roundingMode: "halfExpand" }), - /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "halfExpand"; + +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-trunc.js b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-trunc.js index 25a2b9f808..fdc0f7cd5a 100644 --- a/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-trunc.js +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/until/roundingmode-trunc.js @@ -8,19 +8,27 @@ includes: [temporalHelpers.js] features: [Temporal] ---*/ -const earlier = Temporal.PlainYearMonth.from("2019-01"); -const later = Temporal.PlainYearMonth.from("2021-09"); +const earlier = new Temporal.PlainYearMonth(2019, 1); +const later = new Temporal.PlainYearMonth(2021, 9); -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "years", roundingMode: "trunc" }), - /* years = */ 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "years", roundingMode: "trunc" }), - /* years = */ -2, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); +const expected = [ + ["years", [2], [-2]], + ["months", [2, 8], [-2, -8]], +]; -TemporalHelpers.assertDuration( - earlier.until(later, { smallestUnit: "months", roundingMode: "trunc" }), - /* years = */ 2, /* months = */ 8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); -TemporalHelpers.assertDuration( - later.until(earlier, { smallestUnit: "months", roundingMode: "trunc" }), - /* years = */ -2, /* months = */ -8, 0, 0, 0, 0, 0, 0, 0, 0, "months"); +const roundingMode = "trunc"; + +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/since/roundingmode-ceil.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-ceil.js new file mode 100644 index 0000000000..dacdf1f4a2 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-ceil.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 "ceil". +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], [-2]], + ["months", [0, 32], [0, -31]], + ["weeks", [0, 0, 140], [0, 0, -139]], + ["days", [0, 0, 0, 974], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 0, 23357], [0, 0, 0, 0, -23356]], + ["minutes", [0, 0, 0, 0, 23356, 18], [0, 0, 0, 0, -23356, -17]], + ["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -4]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 865], [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, -197]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "ceil"; + +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-floor.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-floor.js new file mode 100644 index 0000000000..7eb1b57ca9 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-floor.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 "floor". +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", [2], [-3]], + ["months", [0, 31], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -140]], + ["days", [0, 0, 0, 973], [0, 0, 0, -974]], + ["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23357]], + ["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -18]], + ["seconds", [0, 0, 0, 0, 23356, 17, 4], [0, 0, 0, 0, -23356, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -865]], + ["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197], [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 = "floor"; + +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-halfExpand.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfExpand.js new file mode 100644 index 0000000000..2dd5f75552 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-halfExpand.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 "halfExpand". +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 = "halfExpand"; + +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-trunc.js b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-trunc.js new file mode 100644 index 0000000000..4d869c353d --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/since/roundingmode-trunc.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 "trunc". +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", [2], [-2]], + ["months", [0, 31], [0, -31]], + ["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, 4], [0, 0, 0, 0, -23356, -17, -4]], + ["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, 197], [0, 0, 0, 0, -23356, -17, -4, -864, -197]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "trunc"; + +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/until/roundingmode-ceil.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-ceil.js new file mode 100644 index 0000000000..566bd259ef --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-ceil.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 "ceil". +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], [-2]], + ["months", [0, 32], [0, -31]], + ["weeks", [0, 0, 140], [0, 0, -139]], + ["days", [0, 0, 0, 974], [0, 0, 0, -973]], + ["hours", [0, 0, 0, 0, 23357], [0, 0, 0, 0, -23356]], + ["minutes", [0, 0, 0, 0, 23356, 18], [0, 0, 0, 0, -23356, -17]], + ["seconds", [0, 0, 0, 0, 23356, 17, 5], [0, 0, 0, 0, -23356, -17, -4]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 865], [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, -197]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "ceil"; + +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-floor.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-floor.js new file mode 100644 index 0000000000..04cab27c0d --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-floor.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 "floor". +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", [2], [-3]], + ["months", [0, 31], [0, -32]], + ["weeks", [0, 0, 139], [0, 0, -140]], + ["days", [0, 0, 0, 973], [0, 0, 0, -974]], + ["hours", [0, 0, 0, 0, 23356], [0, 0, 0, 0, -23357]], + ["minutes", [0, 0, 0, 0, 23356, 17], [0, 0, 0, 0, -23356, -18]], + ["seconds", [0, 0, 0, 0, 23356, 17, 4], [0, 0, 0, 0, -23356, -17, -5]], + ["milliseconds", [0, 0, 0, 0, 23356, 17, 4, 864], [0, 0, 0, 0, -23356, -17, -4, -865]], + ["microseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197], [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 = "floor"; + +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-halfExpand.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfExpand.js new file mode 100644 index 0000000000..709e0d4f64 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-halfExpand.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 "halfExpand". +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 = "halfExpand"; + +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-trunc.js b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-trunc.js new file mode 100644 index 0000000000..fc9b131627 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/until/roundingmode-trunc.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 "trunc". +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", [2], [-2]], + ["months", [0, 31], [0, -31]], + ["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, 4], [0, 0, 0, 0, -23356, -17, -4]], + ["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, 197], [0, 0, 0, 0, -23356, -17, -4, -864, -197]], + ["nanoseconds", [0, 0, 0, 0, 23356, 17, 4, 864, 197, 532], [0, 0, 0, 0, -23356, -17, -4, -864, -197, -532]], +]; + +const roundingMode = "trunc"; + +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/staging/Temporal/Instant/old/since.js b/test/staging/Temporal/Instant/old/since.js index 39314d43d2..fa9773de9a 100644 --- a/test/staging/Temporal/Instant/old/since.js +++ b/test/staging/Temporal/Instant/old/since.js @@ -56,182 +56,6 @@ assert.sameValue(`${ later.since(earlier, { }) }`, "PT22586123M"); var largestUnit = "hours"; -// halfExpand -var roundingMode = "halfExpand"; -var incrementOneNearest = [ - [ - "hours", - "PT376435H" - ], - [ - "minutes", - "PT376435H23M" - ], - [ - "seconds", - "PT376435H23M8S" - ], - [ - "milliseconds", - "PT376435H23M8.149S" - ], - [ - "microseconds", - "PT376435H23M8.148529S" - ], - [ - "nanoseconds", - "PT376435H23M8.148529313S" - ] -]; -incrementOneNearest.forEach(([smallestUnit, expected]) => { - assert.sameValue(`${ later.since(earlier, { - largestUnit, - smallestUnit, - roundingMode - }) }`, expected); - assert.sameValue(`${ earlier.since(later, { - largestUnit, - smallestUnit, - roundingMode - }) }`, `-${ expected }`); -}); - -// ceil -var roundingMode = "ceil"; -var incrementOneCeil = [ - [ - "hours", - "PT376436H", - "-PT376435H" - ], - [ - "minutes", - "PT376435H24M", - "-PT376435H23M" - ], - [ - "seconds", - "PT376435H23M9S", - "-PT376435H23M8S" - ], - [ - "milliseconds", - "PT376435H23M8.149S", - "-PT376435H23M8.148S" - ], - [ - "microseconds", - "PT376435H23M8.14853S", - "-PT376435H23M8.148529S" - ], - [ - "nanoseconds", - "PT376435H23M8.148529313S", - "-PT376435H23M8.148529313S" - ] -]; -incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { - assert.sameValue(`${ later.since(earlier, { - largestUnit, - smallestUnit, - roundingMode - }) }`, expectedPositive); - assert.sameValue(`${ earlier.since(later, { - largestUnit, - smallestUnit, - roundingMode - }) }`, expectedNegative); -}); - -// floor -var roundingMode = "floor"; -var incrementOneFloor = [ - [ - "hours", - "PT376435H", - "-PT376436H" - ], - [ - "minutes", - "PT376435H23M", - "-PT376435H24M" - ], - [ - "seconds", - "PT376435H23M8S", - "-PT376435H23M9S" - ], - [ - "milliseconds", - "PT376435H23M8.148S", - "-PT376435H23M8.149S" - ], - [ - "microseconds", - "PT376435H23M8.148529S", - "-PT376435H23M8.14853S" - ], - [ - "nanoseconds", - "PT376435H23M8.148529313S", - "-PT376435H23M8.148529313S" - ] -]; -incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { - assert.sameValue(`${ later.since(earlier, { - largestUnit, - smallestUnit, - roundingMode - }) }`, expectedPositive); - assert.sameValue(`${ earlier.since(later, { - largestUnit, - smallestUnit, - roundingMode - }) }`, expectedNegative); -}); - -// trunc -var roundingMode = "trunc"; -var incrementOneTrunc = [ - [ - "hours", - "PT376435H" - ], - [ - "minutes", - "PT376435H23M" - ], - [ - "seconds", - "PT376435H23M8S" - ], - [ - "milliseconds", - "PT376435H23M8.148S" - ], - [ - "microseconds", - "PT376435H23M8.148529S" - ], - [ - "nanoseconds", - "PT376435H23M8.148529313S" - ] -]; -incrementOneTrunc.forEach(([smallestUnit, expected]) => { - assert.sameValue(`${ later.since(earlier, { - largestUnit, - smallestUnit, - roundingMode - }) }`, expected); - assert.sameValue(`${ earlier.since(later, { - largestUnit, - smallestUnit, - roundingMode - }) }`, `-${ expected }`); -}); - // rounds to an increment of hours assert.sameValue(`${ later.since(earlier, { largestUnit, diff --git a/test/staging/Temporal/Instant/old/until.js b/test/staging/Temporal/Instant/old/until.js index 04ee8804b9..3c4c33ad31 100644 --- a/test/staging/Temporal/Instant/old/until.js +++ b/test/staging/Temporal/Instant/old/until.js @@ -56,182 +56,6 @@ assert.sameValue(`${ earlier.until(later, { }) }`, "PT26436596M"); var largestUnit = "hours"; -// halfExpand -var roundingMode = "halfExpand"; -var incrementOneNearest = [ - [ - "hours", - "PT440610H" - ], - [ - "minutes", - "PT440609H56M" - ], - [ - "seconds", - "PT440609H56M3S" - ], - [ - "milliseconds", - "PT440609H56M3.149S" - ], - [ - "microseconds", - "PT440609H56M3.148529S" - ], - [ - "nanoseconds", - "PT440609H56M3.148529313S" - ] -]; -incrementOneNearest.forEach(([smallestUnit, expected]) => { - assert.sameValue(`${ earlier.until(later, { - largestUnit, - smallestUnit, - roundingMode - }) }`, expected); - assert.sameValue(`${ later.until(earlier, { - largestUnit, - smallestUnit, - roundingMode - }) }`, `-${ expected }`); -}); - -// ceil -var roundingMode = "ceil"; -var incrementOneCeil = [ - [ - "hours", - "PT440610H", - "-PT440609H" - ], - [ - "minutes", - "PT440609H57M", - "-PT440609H56M" - ], - [ - "seconds", - "PT440609H56M4S", - "-PT440609H56M3S" - ], - [ - "milliseconds", - "PT440609H56M3.149S", - "-PT440609H56M3.148S" - ], - [ - "microseconds", - "PT440609H56M3.14853S", - "-PT440609H56M3.148529S" - ], - [ - "nanoseconds", - "PT440609H56M3.148529313S", - "-PT440609H56M3.148529313S" - ] -]; -incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { - assert.sameValue(`${ earlier.until(later, { - largestUnit, - smallestUnit, - roundingMode - }) }`, expectedPositive); - assert.sameValue(`${ later.until(earlier, { - largestUnit, - smallestUnit, - roundingMode - }) }`, expectedNegative); -}); - -// floor -var roundingMode = "floor"; -var incrementOneFloor = [ - [ - "hours", - "PT440609H", - "-PT440610H" - ], - [ - "minutes", - "PT440609H56M", - "-PT440609H57M" - ], - [ - "seconds", - "PT440609H56M3S", - "-PT440609H56M4S" - ], - [ - "milliseconds", - "PT440609H56M3.148S", - "-PT440609H56M3.149S" - ], - [ - "microseconds", - "PT440609H56M3.148529S", - "-PT440609H56M3.14853S" - ], - [ - "nanoseconds", - "PT440609H56M3.148529313S", - "-PT440609H56M3.148529313S" - ] -]; -incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { - assert.sameValue(`${ earlier.until(later, { - largestUnit, - smallestUnit, - roundingMode - }) }`, expectedPositive); - assert.sameValue(`${ later.until(earlier, { - largestUnit, - smallestUnit, - roundingMode - }) }`, expectedNegative); -}); - -// trunc -var roundingMode = "trunc"; -var incrementOneTrunc = [ - [ - "hours", - "PT440609H" - ], - [ - "minutes", - "PT440609H56M" - ], - [ - "seconds", - "PT440609H56M3S" - ], - [ - "milliseconds", - "PT440609H56M3.148S" - ], - [ - "microseconds", - "PT440609H56M3.148529S" - ], - [ - "nanoseconds", - "PT440609H56M3.148529313S" - ] -]; -incrementOneTrunc.forEach(([smallestUnit, expected]) => { - assert.sameValue(`${ earlier.until(later, { - largestUnit, - smallestUnit, - roundingMode - }) }`, expected); - assert.sameValue(`${ later.until(earlier, { - largestUnit, - smallestUnit, - roundingMode - }) }`, `-${ expected }`); -}); - // rounds to an increment of hours assert.sameValue(`${ earlier.until(later, { largestUnit, diff --git a/test/staging/Temporal/ZonedDateTime/old/since.js b/test/staging/Temporal/ZonedDateTime/old/since.js index 59b4dc4886..68fcea6719 100644 --- a/test/staging/Temporal/ZonedDateTime/old/since.js +++ b/test/staging/Temporal/ZonedDateTime/old/since.js @@ -105,238 +105,6 @@ assert.sameValue(`${ later.since(earlier, { smallestUnit: "weeks", roundingMode: "halfExpand" }) }`, "P139W"); -var incrementOneNearest = [ - [ - "years", - "P3Y" - ], - [ - "months", - "P32M" - ], - [ - "weeks", - "P139W" - ], - [ - "days", - "P973D" - ], - [ - "hours", - "PT23356H" - ], - [ - "minutes", - "PT23356H17M" - ], - [ - "seconds", - "PT23356H17M5S" - ], - [ - "milliseconds", - "PT23356H17M4.864S" - ], - [ - "microseconds", - "PT23356H17M4.864198S" - ], - [ - "nanoseconds", - "PT23356H17M4.864197532S" - ] -]; -incrementOneNearest.forEach(([smallestUnit, expected]) => { - var roundingMode = "halfExpand"; - assert.sameValue(`${ later.since(earlier, { - smallestUnit, - roundingMode - }) }`, expected); - assert.sameValue(`${ earlier.since(later, { - smallestUnit, - roundingMode - }) }`, `-${ expected }`); -}); -var incrementOneCeil = [ - [ - "years", - "P3Y", - "-P2Y" - ], - [ - "months", - "P32M", - "-P31M" - ], - [ - "weeks", - "P140W", - "-P139W" - ], - [ - "days", - "P974D", - "-P973D" - ], - [ - "hours", - "PT23357H", - "-PT23356H" - ], - [ - "minutes", - "PT23356H18M", - "-PT23356H17M" - ], - [ - "seconds", - "PT23356H17M5S", - "-PT23356H17M4S" - ], - [ - "milliseconds", - "PT23356H17M4.865S", - "-PT23356H17M4.864S" - ], - [ - "microseconds", - "PT23356H17M4.864198S", - "-PT23356H17M4.864197S" - ], - [ - "nanoseconds", - "PT23356H17M4.864197532S", - "-PT23356H17M4.864197532S" - ] -]; -incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { - var roundingMode = "ceil"; - assert.sameValue(`${ later.since(earlier, { - smallestUnit, - roundingMode - }) }`, expectedPositive); - assert.sameValue(`${ earlier.since(later, { - smallestUnit, - roundingMode - }) }`, expectedNegative); -}); -var incrementOneFloor = [ - [ - "years", - "P2Y", - "-P3Y" - ], - [ - "months", - "P31M", - "-P32M" - ], - [ - "weeks", - "P139W", - "-P140W" - ], - [ - "days", - "P973D", - "-P974D" - ], - [ - "hours", - "PT23356H", - "-PT23357H" - ], - [ - "minutes", - "PT23356H17M", - "-PT23356H18M" - ], - [ - "seconds", - "PT23356H17M4S", - "-PT23356H17M5S" - ], - [ - "milliseconds", - "PT23356H17M4.864S", - "-PT23356H17M4.865S" - ], - [ - "microseconds", - "PT23356H17M4.864197S", - "-PT23356H17M4.864198S" - ], - [ - "nanoseconds", - "PT23356H17M4.864197532S", - "-PT23356H17M4.864197532S" - ] -]; -incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { - var roundingMode = "floor"; - assert.sameValue(`${ later.since(earlier, { - smallestUnit, - roundingMode - }) }`, expectedPositive); - assert.sameValue(`${ earlier.since(later, { - smallestUnit, - roundingMode - }) }`, expectedNegative); -}); -var incrementOneTrunc = [ - [ - "years", - "P2Y" - ], - [ - "months", - "P31M" - ], - [ - "weeks", - "P139W" - ], - [ - "days", - "P973D" - ], - [ - "hours", - "PT23356H" - ], - [ - "minutes", - "PT23356H17M" - ], - [ - "seconds", - "PT23356H17M4S" - ], - [ - "milliseconds", - "PT23356H17M4.864S" - ], - [ - "microseconds", - "PT23356H17M4.864197S" - ], - [ - "nanoseconds", - "PT23356H17M4.864197532S" - ] -]; -incrementOneTrunc.forEach(([smallestUnit, expected]) => { - var roundingMode = "trunc"; - assert.sameValue(`${ later.since(earlier, { - smallestUnit, - roundingMode - }) }`, expected); - assert.sameValue(`${ earlier.since(later, { - smallestUnit, - roundingMode - }) }`, `-${ expected }`); -}); // rounds to an increment of hours assert.sameValue(`${ later.since(earlier, { diff --git a/test/staging/Temporal/ZonedDateTime/old/until.js b/test/staging/Temporal/ZonedDateTime/old/until.js index 43ab4c2294..81c37404fd 100644 --- a/test/staging/Temporal/ZonedDateTime/old/until.js +++ b/test/staging/Temporal/ZonedDateTime/old/until.js @@ -109,238 +109,6 @@ assert.sameValue(`${ earlier.until(later, { smallestUnit: "days", roundingMode: "halfExpand" }) }`, "P973D"); -var incrementOneNearest = [ - [ - "years", - "P3Y" - ], - [ - "months", - "P32M" - ], - [ - "weeks", - "P139W" - ], - [ - "days", - "P973D" - ], - [ - "hours", - "PT23356H" - ], - [ - "minutes", - "PT23356H17M" - ], - [ - "seconds", - "PT23356H17M5S" - ], - [ - "milliseconds", - "PT23356H17M4.864S" - ], - [ - "microseconds", - "PT23356H17M4.864198S" - ], - [ - "nanoseconds", - "PT23356H17M4.864197532S" - ] -]; -incrementOneNearest.forEach(([smallestUnit, expected]) => { - var roundingMode = "halfExpand"; - assert.sameValue(`${ earlier.until(later, { - smallestUnit, - roundingMode - }) }`, expected); - assert.sameValue(`${ later.until(earlier, { - smallestUnit, - roundingMode - }) }`, `-${ expected }`); -}); -var incrementOneCeil = [ - [ - "years", - "P3Y", - "-P2Y" - ], - [ - "months", - "P32M", - "-P31M" - ], - [ - "weeks", - "P140W", - "-P139W" - ], - [ - "days", - "P974D", - "-P973D" - ], - [ - "hours", - "PT23357H", - "-PT23356H" - ], - [ - "minutes", - "PT23356H18M", - "-PT23356H17M" - ], - [ - "seconds", - "PT23356H17M5S", - "-PT23356H17M4S" - ], - [ - "milliseconds", - "PT23356H17M4.865S", - "-PT23356H17M4.864S" - ], - [ - "microseconds", - "PT23356H17M4.864198S", - "-PT23356H17M4.864197S" - ], - [ - "nanoseconds", - "PT23356H17M4.864197532S", - "-PT23356H17M4.864197532S" - ] -]; -incrementOneCeil.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { - var roundingMode = "ceil"; - assert.sameValue(`${ earlier.until(later, { - smallestUnit, - roundingMode - }) }`, expectedPositive); - assert.sameValue(`${ later.until(earlier, { - smallestUnit, - roundingMode - }) }`, expectedNegative); -}); -var incrementOneFloor = [ - [ - "years", - "P2Y", - "-P3Y" - ], - [ - "months", - "P31M", - "-P32M" - ], - [ - "weeks", - "P139W", - "-P140W" - ], - [ - "days", - "P973D", - "-P974D" - ], - [ - "hours", - "PT23356H", - "-PT23357H" - ], - [ - "minutes", - "PT23356H17M", - "-PT23356H18M" - ], - [ - "seconds", - "PT23356H17M4S", - "-PT23356H17M5S" - ], - [ - "milliseconds", - "PT23356H17M4.864S", - "-PT23356H17M4.865S" - ], - [ - "microseconds", - "PT23356H17M4.864197S", - "-PT23356H17M4.864198S" - ], - [ - "nanoseconds", - "PT23356H17M4.864197532S", - "-PT23356H17M4.864197532S" - ] -]; -incrementOneFloor.forEach(([smallestUnit, expectedPositive, expectedNegative]) => { - var roundingMode = "floor"; - assert.sameValue(`${ earlier.until(later, { - smallestUnit, - roundingMode - }) }`, expectedPositive); - assert.sameValue(`${ later.until(earlier, { - smallestUnit, - roundingMode - }) }`, expectedNegative); -}); -var incrementOneTrunc = [ - [ - "years", - "P2Y" - ], - [ - "months", - "P31M" - ], - [ - "weeks", - "P139W" - ], - [ - "days", - "P973D" - ], - [ - "hours", - "PT23356H" - ], - [ - "minutes", - "PT23356H17M" - ], - [ - "seconds", - "PT23356H17M4S" - ], - [ - "milliseconds", - "PT23356H17M4.864S" - ], - [ - "microseconds", - "PT23356H17M4.864197S" - ], - [ - "nanoseconds", - "PT23356H17M4.864197532S" - ] -]; -incrementOneTrunc.forEach(([smallestUnit, expected]) => { - var roundingMode = "trunc"; - assert.sameValue(`${ earlier.until(later, { - smallestUnit, - roundingMode - }) }`, expected); - assert.sameValue(`${ later.until(earlier, { - smallestUnit, - roundingMode - }) }`, `-${ expected }`); -}); // rounds to an increment of hours assert.sameValue(`${ earlier.until(later, {