From 3dfc587f3632e3f9634d16964354af23beab13ea Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 20 Jan 2022 11:54:12 +0100 Subject: [PATCH] Test PlainDate#{since,until}. --- .../prototype/since/days-in-month.js | 19 +++++++++ .../PlainDate/prototype/since/days-in-year.js | 21 ++++++++++ .../prototype/since/rounding-relative.js | 34 ++++++++++++++++ .../prototype/since/roundingincrement.js | 28 +++++++++++++ .../prototype/since/roundingmode-ceil.js | 40 +++++++++++++++++++ .../prototype/since/roundingmode-floor.js | 40 +++++++++++++++++++ .../since/roundingmode-halfExpand.js | 40 +++++++++++++++++++ .../prototype/since/roundingmode-trunc.js | 40 +++++++++++++++++++ .../since/smallestunit-higher-units.js | 24 +++++++++++ .../PlainDate/prototype/since/weeks-months.js | 16 ++++++++ .../prototype/until/rounding-relative.js | 34 ++++++++++++++++ .../prototype/until/roundingincrement.js | 28 +++++++++++++ .../prototype/until/roundingmode-ceil.js | 40 +++++++++++++++++++ .../prototype/until/roundingmode-floor.js | 40 +++++++++++++++++++ .../until/roundingmode-halfExpand.js | 40 +++++++++++++++++++ .../prototype/until/roundingmode-trunc.js | 40 +++++++++++++++++++ .../until/smallestunit-higher-units.js | 24 +++++++++++ 17 files changed, 548 insertions(+) create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/days-in-month.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/days-in-year.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/rounding-relative.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/roundingincrement.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-ceil.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-floor.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfExpand.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-trunc.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/smallestunit-higher-units.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/since/weeks-months.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/until/rounding-relative.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/until/roundingincrement.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-ceil.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-floor.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfExpand.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-trunc.js create mode 100644 test/built-ins/Temporal/PlainDate/prototype/until/smallestunit-higher-units.js diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/days-in-month.js b/test/built-ins/Temporal/PlainDate/prototype/since/days-in-month.js new file mode 100644 index 0000000000..8aa412937b --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/days-in-month.js @@ -0,0 +1,19 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: since() should take length of month into account. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const plainDate1 = Temporal.PlainDate.from("2019-01-01"); +const plainDate2 = Temporal.PlainDate.from("2019-02-01"); +const plainDate3 = Temporal.PlainDate.from("2019-03-01"); +TemporalHelpers.assertDuration(plainDate2.since(plainDate1), 0, 0, 0, /* days = */ 31, 0, 0, 0, 0, 0, 0, "January 2019"); +TemporalHelpers.assertDuration(plainDate3.since(plainDate2), 0, 0, 0, /* days = */ 28, 0, 0, 0, 0, 0, 0, "February 2019"); + +const plainDate4 = Temporal.PlainDate.from("2020-02-01"); +const plainDate5 = Temporal.PlainDate.from("2020-03-01"); +TemporalHelpers.assertDuration(plainDate5.since(plainDate4), 0, 0, 0, /* days = */ 29, 0, 0, 0, 0, 0, 0, "February 2020"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/days-in-year.js b/test/built-ins/Temporal/PlainDate/prototype/since/days-in-year.js new file mode 100644 index 0000000000..eeaf5db211 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/days-in-year.js @@ -0,0 +1,21 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: since() should take length of year into account. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const plainDate1 = Temporal.PlainDate.from("2019-01-01"); +const plainDate2 = Temporal.PlainDate.from("2020-01-01"); +const plainDate3 = Temporal.PlainDate.from("2021-01-01"); +TemporalHelpers.assertDuration(plainDate2.since(plainDate1), 0, 0, 0, /* days = */ 365, 0, 0, 0, 0, 0, 0, "From January 2019"); +TemporalHelpers.assertDuration(plainDate3.since(plainDate2), 0, 0, 0, /* days = */ 366, 0, 0, 0, 0, 0, 0, "From January 2020"); + +const plainDate4 = Temporal.PlainDate.from("2019-06-01"); +const plainDate5 = Temporal.PlainDate.from("2020-06-01"); +const plainDate6 = Temporal.PlainDate.from("2021-06-01"); +TemporalHelpers.assertDuration(plainDate5.since(plainDate4), 0, 0, 0, /* days = */ 366, 0, 0, 0, 0, 0, 0, "From June 2019"); +TemporalHelpers.assertDuration(plainDate6.since(plainDate5), 0, 0, 0, /* days = */ 365, 0, 0, 0, 0, 0, 0, "From June 2020"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/rounding-relative.js b/test/built-ins/Temporal/PlainDate/prototype/since/rounding-relative.js new file mode 100644 index 0000000000..03cb400ce5 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/rounding-relative.js @@ -0,0 +1,34 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: Should round relative to the receiver. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const date1 = Temporal.PlainDate.from("2019-01-01"); +const date2 = Temporal.PlainDate.from("2019-02-15"); + +TemporalHelpers.assertDuration( + date2.since(date1, { smallestUnit: "months", roundingMode: "halfExpand" }), + 0, /* months = */ 1, 0, 0, 0, 0, 0, 0, 0, 0); +TemporalHelpers.assertDuration( + date1.since(date2, { smallestUnit: "months", roundingMode: "halfExpand" }), + 0, /* months = */ -2, 0, 0, 0, 0, 0, 0, 0, 0); + +const cases = [ + ["2019-03-01", "2019-01-29", 1, 3], + ["2019-01-29", "2019-03-01", -1, -1], + ["2019-03-29", "2019-01-30", 1, 29], + ["2019-01-30", "2019-03-29", -1, -29], + ["2019-03-30", "2019-01-31", 1, 28], + ["2019-01-31", "2019-03-30", -1, -30], + ["2019-03-31", "2019-01-31", 2, 0], + ["2019-01-31", "2019-03-31", -2, 0] +]; +for (const [end, start, months, days] of cases) { + const result = Temporal.PlainDate.from(end).since(start, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, 0, months, 0, days, 0, 0, 0, 0, 0, 0, `${end} - ${start}`); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/roundingincrement.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingincrement.js new file mode 100644 index 0000000000..9efe9caf2d --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingincrement.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: Tests calculations with roundingMode "trunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainDate.from("2019-01-08"); +const later = Temporal.PlainDate.from("2021-09-07"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "years", roundingIncrement: 4, roundingMode: "halfExpand" }), + /* years = */ 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "months", roundingIncrement: 10, roundingMode: "halfExpand" }), + 0, /* months = */ 30, 0, 0, 0, 0, 0, 0, 0, 0, "months"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "weeks", roundingIncrement: 12, roundingMode: "halfExpand" }), + 0, 0, /* weeks = */ 144, 0, 0, 0, 0, 0, 0, 0, "weeks"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "days", roundingIncrement: 100, roundingMode: "halfExpand" }), + 0, 0, 0, /* days = */ 1000, 0, 0, 0, 0, 0, 0, "days"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-ceil.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-ceil.js new file mode 100644 index 0000000000..cf9a9f116d --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-ceil.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: Tests calculations with roundingMode "ceil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainDate.from("2019-01-08"); +const later = Temporal.PlainDate.from("2021-09-07"); + +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"); + +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"); + +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"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-floor.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-floor.js new file mode 100644 index 0000000000..3629833c13 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-floor.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: Tests calculations with roundingMode "floor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainDate.from("2019-01-08"); +const later = Temporal.PlainDate.from("2021-09-07"); + +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"); + +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"); + +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"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfExpand.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfExpand.js new file mode 100644 index 0000000000..c2d62ed4a5 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-halfExpand.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: Tests calculations with roundingMode "halfExpand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainDate.from("2019-01-08"); +const later = Temporal.PlainDate.from("2021-09-07"); + +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"); + +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"); + +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"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-trunc.js b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-trunc.js new file mode 100644 index 0000000000..c511fa1967 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/roundingmode-trunc.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: Tests calculations with roundingMode "trunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainDate.from("2019-01-08"); +const later = Temporal.PlainDate.from("2021-09-07"); + +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"); + +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"); + +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"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/smallestunit-higher-units.js b/test/built-ins/Temporal/PlainDate/prototype/since/smallestunit-higher-units.js new file mode 100644 index 0000000000..4532cf542e --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/smallestunit-higher-units.js @@ -0,0 +1,24 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: Tests calculations with higher smallestUnit than the default of "days" +includes: [compareArray.js, temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainDate.from("2019-01-08"); +const later = Temporal.PlainDate.from("2021-09-07"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "years", roundingMode: "halfExpand" }), + /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "months", roundingMode: "halfExpand" }), + 0, /* months = */ 32, 0, 0, 0, 0, 0, 0, 0, 0, "months"); + +TemporalHelpers.assertDuration( + later.since(earlier, { smallestUnit: "weeks", roundingMode: "halfExpand" }), + 0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/since/weeks-months.js b/test/built-ins/Temporal/PlainDate/prototype/since/weeks-months.js new file mode 100644 index 0000000000..fdaeb5b2c9 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/since/weeks-months.js @@ -0,0 +1,16 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.since +description: since() should not return weeks and months together. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const date = new Temporal.PlainDate(1969, 7, 24); +const laterDate = new Temporal.PlainDate(1969, 9, 4); +TemporalHelpers.assertDuration(laterDate.since(date, { largestUnit: "weeks" }), + 0, 0, /* weeks = */ 6, 0, 0, 0, 0, 0, 0, 0, "weeks"); +TemporalHelpers.assertDuration(laterDate.since(date, { largestUnit: "months" }), + 0, /* months = */ 1, 0, 11, 0, 0, 0, 0, 0, 0, "months"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/rounding-relative.js b/test/built-ins/Temporal/PlainDate/prototype/until/rounding-relative.js new file mode 100644 index 0000000000..90d0e0297d --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/rounding-relative.js @@ -0,0 +1,34 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: Should round relative to the receiver. +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const date1 = Temporal.PlainDate.from("2019-01-01"); +const date2 = Temporal.PlainDate.from("2019-02-15"); + +TemporalHelpers.assertDuration( + date1.until(date2, { smallestUnit: "months", roundingMode: "halfExpand" }), + 0, /* months = */ 2, 0, 0, 0, 0, 0, 0, 0, 0); +TemporalHelpers.assertDuration( + date2.until(date1, { smallestUnit: "months", roundingMode: "halfExpand" }), + 0, /* months = */ -1, 0, 0, 0, 0, 0, 0, 0, 0); + +const cases = [ + ["2019-03-01", "2019-01-29", 1, 1], + ["2019-01-29", "2019-03-01", -1, -3], + ["2019-03-29", "2019-01-30", 1, 29], + ["2019-01-30", "2019-03-29", -1, -29], + ["2019-03-30", "2019-01-31", 1, 30], + ["2019-01-31", "2019-03-30", -1, -28], + ["2019-03-31", "2019-01-31", 2, 0], + ["2019-01-31", "2019-03-31", -2, 0] +]; +for (const [end, start, months, days] of cases) { + const result = Temporal.PlainDate.from(start).until(end, { largestUnit: "months" }); + TemporalHelpers.assertDuration(result, 0, months, 0, days, 0, 0, 0, 0, 0, 0, `${end} - ${start}`); +} diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/roundingincrement.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingincrement.js new file mode 100644 index 0000000000..6e8e9bea9a --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingincrement.js @@ -0,0 +1,28 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: Tests calculations with roundingMode "trunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainDate.from("2019-01-08"); +const later = Temporal.PlainDate.from("2021-09-07"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "years", roundingIncrement: 4, roundingMode: "halfExpand" }), + /* years = */ 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "months", roundingIncrement: 10, roundingMode: "halfExpand" }), + 0, /* months = */ 30, 0, 0, 0, 0, 0, 0, 0, 0, "months"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "weeks", roundingIncrement: 12, roundingMode: "halfExpand" }), + 0, 0, /* weeks = */ 144, 0, 0, 0, 0, 0, 0, 0, "weeks"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "days", roundingIncrement: 100, roundingMode: "halfExpand" }), + 0, 0, 0, /* days = */ 1000, 0, 0, 0, 0, 0, 0, "days"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-ceil.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-ceil.js new file mode 100644 index 0000000000..1707a31f05 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-ceil.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: Tests calculations with roundingMode "ceil". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainDate.from("2019-01-08"); +const later = Temporal.PlainDate.from("2021-09-07"); + +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"); + +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"); + +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"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-floor.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-floor.js new file mode 100644 index 0000000000..f2bfd839ad --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-floor.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: Tests calculations with roundingMode "floor". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainDate.from("2019-01-08"); +const later = Temporal.PlainDate.from("2021-09-07"); + +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"); + +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"); + +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"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfExpand.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfExpand.js new file mode 100644 index 0000000000..652b31edc7 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-halfExpand.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: Tests calculations with roundingMode "halfExpand". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainDate.from("2019-01-08"); +const later = Temporal.PlainDate.from("2021-09-07"); + +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"); + +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"); + +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"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-trunc.js b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-trunc.js new file mode 100644 index 0000000000..aed446983a --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/roundingmode-trunc.js @@ -0,0 +1,40 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: Tests calculations with roundingMode "trunc". +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainDate.from("2019-01-08"); +const later = Temporal.PlainDate.from("2021-09-07"); + +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"); + +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"); + +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"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/until/smallestunit-higher-units.js b/test/built-ins/Temporal/PlainDate/prototype/until/smallestunit-higher-units.js new file mode 100644 index 0000000000..1dfad04808 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/until/smallestunit-higher-units.js @@ -0,0 +1,24 @@ +// Copyright (C) 2022 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.until +description: Tests calculations with higher smallestUnit than the default of "days" +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const earlier = Temporal.PlainDate.from("2019-01-08"); +const later = Temporal.PlainDate.from("2021-09-07"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "years", roundingMode: "halfExpand" }), + /* years = */ 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, "years"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "months", roundingMode: "halfExpand" }), + 0, /* months = */ 32, 0, 0, 0, 0, 0, 0, 0, 0, "months"); + +TemporalHelpers.assertDuration( + earlier.until(later, { smallestUnit: "weeks", roundingMode: "halfExpand" }), + 0, 0, /* weeks = */ 139, 0, 0, 0, 0, 0, 0, 0, "weeks");