From c3c318cf113b3aff9e6e4bbd9b22d8e908355ad0 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Thu, 17 Apr 2025 17:24:20 -0700 Subject: [PATCH] Temporal: Add coverage for weird PlainMonthDay leap day constrain case If you have a leap day, such as February 29, and you get input such as { monthCode: "M02", day: 30 }, { overflow: "constrain" }, then you want the day to be constrained to the leap day February 29, not February 28 as the maximum day would be in a common year. Add tests for this case for each supported calendar. --- .../from/constrain-to-leap-day.js | 11 +++++++ .../from/constrain-to-leap-day.js | 32 +++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 test/built-ins/Temporal/PlainMonthDay/from/constrain-to-leap-day.js create mode 100644 test/intl402/Temporal/PlainMonthDay/from/constrain-to-leap-day.js diff --git a/test/built-ins/Temporal/PlainMonthDay/from/constrain-to-leap-day.js b/test/built-ins/Temporal/PlainMonthDay/from/constrain-to-leap-day.js new file mode 100644 index 0000000000..67cb445833 --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/from/constrain-to-leap-day.js @@ -0,0 +1,11 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.from +description: Properly constrain February 30 to February 29, not 28 +features: [Temporal] +---*/ + +const md = Temporal.PlainMonthDay.from({ monthCode: "M02", day: 30 }, { overflow: "constrain" }); +assert.sameValue(md.day, 29, "M02-30 should constrain to 29, not 28"); diff --git a/test/intl402/Temporal/PlainMonthDay/from/constrain-to-leap-day.js b/test/intl402/Temporal/PlainMonthDay/from/constrain-to-leap-day.js new file mode 100644 index 0000000000..be1e3de17a --- /dev/null +++ b/test/intl402/Temporal/PlainMonthDay/from/constrain-to-leap-day.js @@ -0,0 +1,32 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.from +description: Properly constrain a day that is one past a leap day +features: [Temporal] +---*/ + +const tests = [ + ["buddhist", "M02", 30], + ["chinese", "M01", 31], + ["coptic", "M13", 7], + ["dangi", "M01", 31], + ["ethioaa", "M13", 7], + ["ethiopic", "M13", 7], + ["gregory", "M02", 30], + ["hebrew", "M02", 31], + ["indian", "M01", 32], + ["islamic-civil", "M01", 31], + ["islamic-tbla", "M01", 31], + ["islamic-umalqura", "M01", 31], + ["japanese", "M02", 30], + ["persian", "M12", 31], + ["roc", "M02", 30], +]; + +for (const [calendar, monthCode, day] of tests) { + const md = Temporal.PlainMonthDay.from({ calendar, monthCode, day }, { overflow: "constrain" }); + assert.sameValue(md.day, day - 1, + `${calendar}: ${monthCode}-${day} should constrain to ${day - 1}, not ${day - 2}`) +}