Temporal: Change overflow behaviour of PYM/PMD.toPlainDate

These tests cover the proposed normative change:
https://github.com/tc39/proposal-temporal/issues/2706
This commit is contained in:
Philip Chimento 2023-11-02 17:22:41 -07:00 committed by Philip Chimento
parent 32540f3034
commit 6cbb6da947
3 changed files with 33 additions and 1 deletions

View File

@ -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 = {

View File

@ -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");

View File

@ -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");