From ee1f96235b8fffb25141b812f3cee4f8863d4553 Mon Sep 17 00:00:00 2001 From: Jesse Alama Date: Fri, 4 Feb 2022 08:50:10 +0100 Subject: [PATCH] Ensure reference data is emitted when calendarName = 'always' References: + https://github.com/tc39/proposal-temporal/issues/1971 --- .../Temporal/PlainMonthDay/calendar-always.js | 24 +++++++++++++++++++ .../PlainYearMonth/calendar-always.js | 24 +++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 test/built-ins/Temporal/PlainMonthDay/calendar-always.js create mode 100644 test/built-ins/Temporal/PlainYearMonth/calendar-always.js diff --git a/test/built-ins/Temporal/PlainMonthDay/calendar-always.js b/test/built-ins/Temporal/PlainMonthDay/calendar-always.js new file mode 100644 index 00000000000..8b9d87ff0a0 --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/calendar-always.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.plainmonthday +description: If calendar name is to be emitted, include additional reference info +features: [Temporal] +---*/ + +const pmd = new Temporal.PlainMonthDay(10, 31, "iso8601", 2019); + +assert.sameValue( + pmd.toString({ calendarName: 'always' }), + "2019-10-31[u-ca=iso8601]", + "emit year-month-day if calendarName = 'always' (four-argument constructor)" +); + +const anotherPMD = Temporal.PlainMonthDay.from("2019-10-31"); // 2019 will get dropped + +assert.sameValue( + anotherPMD.toString({ calendarName: 'always' }), + "1972-10-31[u-ca=iso8601]", + "emit fallback year if calendarName = 'always' (static from)" +); diff --git a/test/built-ins/Temporal/PlainYearMonth/calendar-always.js b/test/built-ins/Temporal/PlainYearMonth/calendar-always.js new file mode 100644 index 00000000000..0aad58df09f --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/calendar-always.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.plainyearmonth +description: If calendar name is to be emitted, include additional reference info +features: [Temporal] +---*/ + +const pym = new Temporal.PlainYearMonth(2019, 10, "iso8601", 31); + +assert.sameValue( + pym.toString({ calendarName: 'always' }), + "2019-10-31[u-ca=iso8601]", + "emit year-month-day if calendarName = 'always' (four-argument constructor)" +); + +const anotherPYM = Temporal.PlainYearMonth.from("2019-10-31"); // 31 will get dropped + +assert.sameValue( + anotherPYM.toString({ calendarName: 'always' }), + "2019-10-01[u-ca=iso8601]", + "emit fallback day if calendarName = 'always' (static from)" +);