From 6cbb6da9473c56d95358d8e679c5a6d2b4574efb Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 2 Nov 2023 17:22:41 -0700 Subject: [PATCH] Temporal: Change overflow behaviour of PYM/PMD.toPlainDate These tests cover the proposed normative change: https://github.com/tc39/proposal-temporal/issues/2706 --- .../prototype/toPlainDate/basic.js | 1 - .../toPlainDate/default-overflow-behaviour.js | 14 ++++++++++++++ .../toPlainDate/default-overflow-behaviour.js | 19 +++++++++++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 test/built-ins/Temporal/PlainMonthDay/prototype/toPlainDate/default-overflow-behaviour.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/prototype/toPlainDate/default-overflow-behaviour.js diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toPlainDate/basic.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toPlainDate/basic.js index 48785b0a5b..7b81c451cb 100644 --- a/test/built-ins/Temporal/PlainMonthDay/prototype/toPlainDate/basic.js +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toPlainDate/basic.js @@ -15,7 +15,6 @@ TemporalHelpers.assertPlainDate(d, 2002, 1, "M01", 22); assert.throws(TypeError, () => md.toPlainDate({ something: 'nothing' }), "missing fields"); const leapDay = Temporal.PlainMonthDay.from('02-29'); -assert.throws(RangeError, () => leapDay.toPlainDate({ year: 2019 })); TemporalHelpers.assertPlainDate(leapDay.toPlainDate({ year: 2020 }), 2020, 2, "M02", 29); const options = { diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toPlainDate/default-overflow-behaviour.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toPlainDate/default-overflow-behaviour.js new file mode 100644 index 0000000000..13110ccc88 --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toPlainDate/default-overflow-behaviour.js @@ -0,0 +1,14 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.toplaindate +description: A nonexistent resulting date is constrained to an existing date +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const leapDay = new Temporal.PlainMonthDay(2, 29); +const result = leapDay.toPlainDate({ year: 2023 }); +// 2023-02-29 does not exist because 2023 is a common year +TemporalHelpers.assertPlainDate(result, 2023, 2, "M02", 28, "2023 + 02-29 = 2023-02-28"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toPlainDate/default-overflow-behaviour.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toPlainDate/default-overflow-behaviour.js new file mode 100644 index 0000000000..08ce198956 --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toPlainDate/default-overflow-behaviour.js @@ -0,0 +1,19 @@ +// Copyright (C) 2021 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.toplaindate +description: A nonexistent resulting date is constrained to an existing date +includes: [temporalHelpers.js] +features: [Temporal] +---*/ + +const febCommonYear = new Temporal.PlainYearMonth(2023, 2); +const result = febCommonYear.toPlainDate({ day: 29 }); +// 2023-02-29 does not exist because 2023 is a common year +TemporalHelpers.assertPlainDate(result, 2023, 2, "M02", 28, "2023-02 + 29 = 2023-02-28"); + +const juneAnyYear = new Temporal.PlainYearMonth(1998, 6); +const result2 = juneAnyYear.toPlainDate({ day: 31 }); +// 06-31 does not exist in any year +TemporalHelpers.assertPlainDate(result2, 1998, 6, "M06", 30, "1998-06 + 31 = 1998-06-31");