From ad82406c1646be365501e2cf45c3c7bff5389bbc Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Thu, 14 Aug 2025 22:00:14 -0700 Subject: [PATCH 1/3] Pull out CalendarIntegersToISO, CalendarDaysInMonth --- spec.emu | 52 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/spec.emu b/spec.emu index 6cd16c6..80cf90d 100644 --- a/spec.emu +++ b/spec.emu @@ -662,6 +662,26 @@ contributors: Google, Ecma International + +

+ CalendarDaysInMonth ( + _calendar_: a calendar type that is not *"iso8601"*, + _arithmeticYear_: an integer, + _ordinalMonth_: a positive integer, + ): an integer +

+
+
description
+
+ It returns the number of days in the _calendar_-specific _arithmeticYear_ and _ordinalMonth_. +
+
+

It performs the following steps when called:

+ + 1. Return the number of days in the month of _calendar_ corresponding to _arithmeticYear_ and _ordinalMonth_. + +
+

IsValidEraYearForCalendar ( @@ -844,6 +864,29 @@ contributors: Google, Ecma International + +

+ CalendarIntegersToISO ( + _calendar_: a calendar type that is not *"iso8601"*, + _arithmeticYear_: an integer, + _ordinalMonth_: a positive integer, + _day_: an integer, + ): either a normal completion containing an ISO Date Record or a throw completion +

+
+
description
+
+ It returns an ISO Date Record that corresponds with the given _calendar_-specific _arithmeticYear_, _ordinalMonth_, and _day_. +
+
+

It performs the following steps when called:

+ + 1. If _arithmeticYear_, _ordinalMonth_, and _day_ do not form a valid date in _calendar_, throw a RangeError exception. + 1. Let _isoDate_ be an ISO Date Record such that CalendarISOToDate(_calendar_, _isoDate_) returns a Calendar Date Record whose [[Year]], [[Month]], and [[Day]] field values respectively equal _arithmeticYear_, _ordinalMonth_, and _day_. + 1. Return _isoDate_. + +
+

Calendar Date Records

@@ -1087,8 +1130,13 @@ contributors: Google, Ecma International 1. Let _ordinalMonth_ be _fields_.[[Month]]. 1. Let _day_ be _fields_.[[Day]]. 1. Assert: _day_ is not ~unset~. - 1. If the date described by _calendar_, _arithmeticYear_, _ordinalMonth_, and _day_ does not exist, set _day_ to the closest day in the same month. If there are two equally-close dates in the same month, pick the later one. - 1. Return an implementation-defined ISO Date Record that corresponds to the date described by _calendar_, _arithmeticYear_, _ordinalMonth_, and _day_. + 1. Let _daysInMonth_ be CalendarDaysInMonth(_calendar_, _arithmeticYear_, _ordinalMonth_). + 1. If _daysInMonth_ < _day_, then + 1. If _overflow_ is ~reject~, throw a *RangeError* exception. + 1. Let _regulatedDay_ be _daysInMonth_. + 1. Else, + 1. Let _regulatedDay_ be _day_. + 1. Return ? CalendarIntegersToISO(_calendar_, _arithmeticYear_, _ordinalMonth_, _regulatedDay_). From 61325b1826d594b2d956d25f7bd0ee4dc3a47ec8 Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Fri, 22 Aug 2025 18:23:19 -0500 Subject: [PATCH 2/3] Day should be positive --- spec.emu | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec.emu b/spec.emu index 80cf90d..c541172 100644 --- a/spec.emu +++ b/spec.emu @@ -870,7 +870,7 @@ contributors: Google, Ecma International _calendar_: a calendar type that is not *"iso8601"*, _arithmeticYear_: an integer, _ordinalMonth_: a positive integer, - _day_: an integer, + _day_: a positive integer, ): either a normal completion containing an ISO Date Record or a throw completion

@@ -1134,6 +1134,9 @@ contributors: Google, Ecma International 1. If _daysInMonth_ < _day_, then 1. If _overflow_ is ~reject~, throw a *RangeError* exception. 1. Let _regulatedDay_ be _daysInMonth_. + 1. Else if _day_ < 1, then + 1. If _overflow_ is ~reject~, throw a *RangeError* exception. + 1. Let _regulatedDay_ be 1. 1. Else, 1. Let _regulatedDay_ be _day_. 1. Return ? CalendarIntegersToISO(_calendar_, _arithmeticYear_, _ordinalMonth_, _regulatedDay_). From 7611c40c2ae88fdda1f3ac512bcf12ad49047ff0 Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Thu, 11 Sep 2025 17:18:12 -0500 Subject: [PATCH 3/3] Review feedback --- spec.emu | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/spec.emu b/spec.emu index c541172..a346a98 100644 --- a/spec.emu +++ b/spec.emu @@ -1134,10 +1134,8 @@ contributors: Google, Ecma International 1. If _daysInMonth_ < _day_, then 1. If _overflow_ is ~reject~, throw a *RangeError* exception. 1. Let _regulatedDay_ be _daysInMonth_. - 1. Else if _day_ < 1, then - 1. If _overflow_ is ~reject~, throw a *RangeError* exception. - 1. Let _regulatedDay_ be 1. 1. Else, + 1. Assert: _day_ ≥ 1. 1. Let _regulatedDay_ be _day_. 1. Return ? CalendarIntegersToISO(_calendar_, _arithmeticYear_, _ordinalMonth_, _regulatedDay_).