Skip to content

Commit

Permalink
Temporal: Change overflow behaviour of PYM/PMD.toPlainDate
Browse files Browse the repository at this point in the history
These tests cover the proposed normative change:
tc39/proposal-temporal#2706
  • Loading branch information
ptomato committed Dec 4, 2023
1 parent 32540f3 commit 6cbb6da
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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");

0 comments on commit 6cbb6da

Please sign in to comment.