Skip to content

Commit 6abbe6e

Browse files
committed
RegulateNonISOYearMonth => ConstrainMonthCodeToArithmeticalMonth
1 parent 9e7ee19 commit 6abbe6e

File tree

1 file changed

+82
-90
lines changed

1 file changed

+82
-90
lines changed

spec.emu

Lines changed: 82 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -533,36 +533,111 @@ contributors: Google, Ecma International
533533
<tr>
534534
<th>Calendar</th>
535535
<th>Additional Month Codes</th>
536+
<th>Leap to Common Month Transformation</th>
536537
</tr>
537538
</thead>
538539
<tr>
539540
<td>*"chinese"*</td>
540541
<td>*"M01L"*, *"M02L"*, *"M03L"*, *"M04L"*, *"M05L"*, *"M06L"*, *"M07L"*, *"M08L"*, *"M09L"*, *"M10L"*, *"M11L"*, *"M12L"*</td>
542+
<td>Remove the *"L"*</td>
541543
</tr>
542544
<tr>
543545
<td>*"coptic"*</td>
544546
<td>*"M13"*</td>
547+
<td></td>
545548
</tr>
546549
<tr>
547550
<td>*"dangi"*</td>
548551
<td>*"M01L"*, *"M02L"*, *"M03L"*, *"M04L"*, *"M05L"*, *"M06L"*, *"M07L"*, *"M08L"*, *"M09L"*, *"M10L"*, *"M11L"*, *"M12L"*</td>
552+
<td>Remove the *"L"*</td>
549553
</tr>
550554
<tr>
551555
<td>*"ethioaa"*</td>
552556
<td>*"M13"*</td>
557+
<td></td>
553558
</tr>
554559
<tr>
555560
<td>*"ethiopic"*</td>
556561
<td>*"M13"*</td>
562+
<td></td>
557563
</tr>
558564
<tr>
559565
<td>*"hebrew"*</td>
560566
<td>*"M05L"*</td>
567+
<td>Change *"M05L"* to *"M06"*</td>
561568
</tr>
562569
</table>
563570
</emu-table>
564571
</emu-clause>
565572

573+
<emu-clause id="sec-temporal-constrainmonthcodetoarithmeticalmonth" type="abstract operation">
574+
<h1>
575+
ConstrainMonthCodeToArithmeticalMonth (
576+
_calendar_: a calendar type that is not *"iso8601"*,
577+
_year_: an integer,
578+
_monthCode_: a String,
579+
_overflow_: ~constrain~ or ~reject~,
580+
): either a normal completion containing an integer or a throw completion
581+
</h1>
582+
<dl class="header">
583+
<dt>description</dt>
584+
<dd>
585+
It returns the arithmetical month in _year_ that best matches the given _monthCode_ in _calendar_. If _monthCode_ does not exist in _year_, it is constrained to the best common month if _overflow_ is ~constrain~, or an error is thrown if _overflow_ is ~reject~.
586+
</dd>
587+
</dl>
588+
<p>It performs the following steps when called:</p>
589+
<emu-alg>
590+
1. Assert: IsValidMonthCodeForCalendar(_calendar_, _monthCode_) is *true*.
591+
1. Let _monthCodeParts_ be ParseMonthCode(_monthCode_).
592+
1. If _calendar_ is not listed in the Calendar column of <emu-xref href="#table-additional-month-codes"></emu-xref>, return _monthCodeParts_.[[Number]].
593+
1. Let _r_ be the row in <emu-xref href="#table-additional-month-codes"></emu-xref> which the _calendar_ is in the Calendar column.
594+
1. If the *"Leap to Common Month Transformation"* column of _r_ is empty, return _monthCodeParts_.[[Number]].
595+
1. If YearContainsMonthCode(_calendar_, _year_, _monthCode_) is *false*, then
596+
1. If _overflow_ is ~reject~, throw a *RangeError* exception.
597+
1. Let _resolvedMonthCode_ be the result of applying the algorithm described in the *"Leap to Common Month Transformation"* column of _r_ to _monthCode_.
598+
1. Else,
599+
1. Let _resolvedMonthCode_ be _monthCode_.
600+
1. Let _monthsBefore_ be 0.
601+
1. Let _number_ be 1.
602+
1. Let _isLeap_ be *false*.
603+
1. Assert: The *"Additional Month Codes"* column of _r_ does not contain *"M00"* or *"M13"*.
604+
1. Repeat, while _number_ &le; 12,
605+
1. Let _currentMonthCode_ be CreateMonthCode(_number_, _isLeap_).
606+
1. If YearContainsMonthCode(_calendar_, _year_, _currentMonthCode_), then
607+
1. Set _monthsBefore_ to _monthsBefore_ + 1.
608+
1. If _currentMonthCode_ is _resolvedMonthCode_, then
609+
1. Return _monthsBefore_.
610+
1. If _isLeap_ is *false*, then
611+
1. Set _isLeap_ to *true*.
612+
1. Else,
613+
1. Set _isLeap_ to *false*.
614+
1. Set _number_ to _number_ + 1.
615+
1. Assert: The above loop should have returned before terminating.
616+
</emu-alg>
617+
</emu-clause>
618+
619+
<emu-clause id="sec-temporal-yearcontainsmonthcode" type="abstract operation">
620+
<h1>
621+
YearContainsMonthCode (
622+
_calendar_: a calendar type that is not *"iso8601"*,
623+
_year_: an integer,
624+
_monthCode_: a String,
625+
): a Boolean
626+
</h1>
627+
<dl class="header">
628+
<dt>description</dt>
629+
<dd>
630+
It returns whether the given _monthCode_ exists in _year_ of _calendar_.
631+
</dd>
632+
</dl>
633+
<p>It performs the following steps when called:</p>
634+
<emu-alg>
635+
1. Assert: IsValidMonthCodeForCalendar(_calendar_, _monthCode_) is *true*.
636+
1. If ParseMonthCode(_monthCode_).[[IsLeap]] is *false*, return *true*.
637+
1. Return whether the leap month indicated by _monthCode_ exists in the arithmetical year _year_ in _calendar_, using calendar-dependent behaviour.
638+
</emu-alg>
639+
</emu-clause>
640+
566641
<emu-clause id="sec-temporal-isvaliderayearforcalendar" type="abstract operation">
567642
<h1>
568643
IsValidEraYearForCalendar (
@@ -930,44 +1005,6 @@ contributors: Google, Ecma International
9301005
</emu-alg>
9311006
</emu-clause>
9321007

933-
<emu-clause id="sec-temporal-monthcodetoarithmeticalmonth" type="implementation-defined abstract operation">
934-
<h1>
935-
MonthCodeToArithmeticalMonth (
936-
_calendar_: a calendar type that is not *"iso8601"*,
937-
_year_: an integer,
938-
_monthCode_: a String,
939-
): an integer or ~invalid~
940-
</h1>
941-
<dl class="header">
942-
<dt>description</dt>
943-
<dd>
944-
It interprets _year_ as arithmetical year in the given _calendar_, returning an integer if there is a month with the given _monthCode_ in that year, or ~invalid~ otherwise.
945-
</dd>
946-
</dl>
947-
<p>It performs the following steps when called:</p>
948-
<emu-alg>
949-
1. If IsValidMonthCodeForCalendar(_calendar_, _monthCode_) is *false*, then
950-
1. Return ~invalid~.
951-
1. Let _monthCodeParts_ be ParseMonthCode(_monthCode_).
952-
1. If _calendar_ is not *"chinese"*, *"dangi"*, or *"hebrew"*, then
953-
1. Return _monthCodeParts_.[[Number]].
954-
1. Let _monthsBefore_ be 0.
955-
1. Let _number_ be 1.
956-
1. Let _isLeap_ be *false*.
957-
1. Repeat, while _number_ &le; 12,
958-
1. If _calendar_ contains CreateMonthCode(_number_, _isLeap_) in _year_, according to a calendar-dependent algorithm, then
959-
1. Set _monthsBefore_ to _monthsBefore_ + 1.
960-
1. If _monthCodeParts_.[[Number]] is _number_ and _monthCodeParts.[[IsLeap]] is _isLeap_, then
961-
1. Return _monthsBefore_.
962-
1. If _isLeap_ is *false*, then
963-
1. Set _isLeap_ to *true*.
964-
1. Else,
965-
1. Set _isLeap_ to *false*.
966-
1. Set _number_ to _number_ + 1.
967-
1. Return ~invalid~.
968-
</emu-alg>
969-
</emu-clause>
970-
9711008
<emu-clause id="sec-temporal-calendardatearithmeticaltoiso" type="implementation-defined abstract operation">
9721009
<h1>
9731010
CalendarDateArithmeticalToISO (
@@ -1029,49 +1066,6 @@ contributors: Google, Ecma International
10291066
</emu-alg>
10301067
</emu-clause>
10311068

1032-
<emu-clause id="sec-temporal-regulatenonisoyearmonth" type="implementation-defined abstract operation">
1033-
<h1>
1034-
RegulateNonISOYearMonth (
1035-
_calendar_: a calendar type that is not *"iso8601"*,
1036-
_arithmeticalYear_: an integer,
1037-
_monthCode_: a String,
1038-
_years_: an integer,
1039-
): a Record with fields [[Year]] (an integer) and [[Month]] (an integer)
1040-
</h1>
1041-
<dl class="header">
1042-
<dt>description</dt>
1043-
<dd>
1044-
Interprets _isoDate_ as a date in _calendar_, adds _years_, and returns the best-match arithmetic _year_ and _month_ according to the calendar.
1045-
</dd>
1046-
</dl>
1047-
<p>It performs the following steps when called:</p>
1048-
<emu-alg>
1049-
1. Let _y2_ be _arithmeticalYear_ + _years_.
1050-
1. If _calendar_ is *"chinese"*, *"dangi"*, or *"hebrew"*, then
1051-
1. If _calendar_ is *"chinese"* or *"dangi"*, then
1052-
1. Let _month_ be MonthCodeToArithmeticalMonth(_calendar_, _y2_, _monthCode_).
1053-
1. If _month_ is ~invalid~, then
1054-
1. Let _monthCode_ be CreateMonthCode(ParseMonthCode(_monthCode_).[[Number]], *false*).
1055-
1. Set _month_ to MonthCodeToArithmeticalMonth(_calendar_, _y2_, _monthCode_).
1056-
1. Assert: _month_ is not ~invalid~.
1057-
1. Else,
1058-
1. Assert: _calendar_ is *"hebrew"*.
1059-
1. Let _isLeap1_ be *true* if _arithmeticalYear_ is a leap year in the Hebrew calendar, or *false* otherwise.
1060-
1. Let _isLeap2_ be *true* if _y2_ is a leap year in the Hebrew calendar, or *false* otherwise.
1061-
1. If _isLeap1_ is *true* and _isLeap2_ is *false*, then
1062-
1. If _monthCode_ is *"M05L"*, then
1063-
1. Set _monthCode_ to *"M06"*.
1064-
1. Else if _isLeap1_ is *false* and _isLeap2_ is *true*, then
1065-
1. If _monthCode_ is *"M06"*, then
1066-
1. Set _monthCode_ to *"M05L"*.
1067-
1. Let _month_ be MonthCodeToArithmeticalMonth(_calendar_, _monthCode_, _y2_).
1068-
1. Assert: _month_ is not ~invalid~.
1069-
1. Else,
1070-
1. Let _month_ be ParseMonthCode(_monthCode_).[[Number]].
1071-
1. Return the Record { [[Year]]: _y2_, [[Month]]: _month_ }.
1072-
</emu-alg>
1073-
</emu-clause>
1074-
10751069
<emu-clause id="sec-temporal-balancenonisodate" type="implementation-defined abstract operation">
10761070
<h1>
10771071
BalanceNonISODate (
@@ -1146,8 +1140,9 @@ contributors: Google, Ecma International
11461140
<p>It performs the following steps when called:</p>
11471141
<emu-alg>
11481142
1. Let _parts_ be CalendarISOToDate(_calendar_, _baseDate_).
1149-
1. Let _yearMonth_ be RegulateNonISOYearMonth(_calendar_, _parts_.[[Year]], _parts_.[[MonthCode]], _years_).
1150-
1. Let _endOfMonth_ be BalanceNonISODate(_calendar_, _yearMonth_.[[Year]], _yearMonth_.[[Month]] + _months_ + 1, 0).
1143+
1. Let _y0_ be _parts_.[[Year]] + _years_.
1144+
1. Let _m0_ be ! ConstrainMonthCodeToArithmeticalMonth(_calendar_, _y0_, _parts_.[[MonthCode]], ~constrain~).
1145+
1. Let _endOfMonth_ be BalanceNonISODate(_calendar_, _y0_, _m0_ + _months_ + 1, 0).
11511146
1. Let _baseDay_ be _parts_.[[Day]].
11521147
1. If _weeks_ is not 0 or _days_ is not 0, then
11531148
1. If _baseDay_ &lt; _endOfMonth_.[[Day]], then
@@ -1194,8 +1189,9 @@ contributors: Google, Ecma International
11941189
<p>It performs the following steps when called:</p>
11951190
<emu-alg>
11961191
1. Let _parts_ be CalendarISOToDate(_calendar_, _isoDate_).
1197-
1. Let _yearMonth_ be RegulateNonISOYearMonth(_calendar_, _parts_.[[Year]], _parts_.[[MonthCode]], _duration_.[[Years]]).
1198-
1. Let _endOfMonth_ be BalanceNonISODate(_calendar_, _yearMonth_.[[Year]], _yearMonth_.[[Month]] + _duration_.[[Months]] + 1, 0).
1192+
1. Let _y0_ be _parts_.[[Year]] + _duration_.[[Years]].
1193+
1. Let _m0_ be ! ConstrainMonthCodeToArithmeticalMonth(_calendar_, _y0_, _parts_.[[MonthCode]], ~constrain~).
1194+
1. Let _endOfMonth_ be BalanceNonISODate(_calendar_, _y0_, _m0_ + _duration_.[[Months]] + 1, 0).
11991195
1. Let _baseDay_ be _parts_.[[Day]].
12001196
1. If _endOfMonth_.[[Day]] &lt; _baseDay_, then
12011197
1. If _overflow_ is ~reject~, throw a *RangeError* exception.
@@ -1287,11 +1283,7 @@ contributors: Google, Ecma International
12871283
1. Let _year_ be _fields_.[[Year]].
12881284
1. If _fields_.[[MonthCode]] is not ~unset~, then
12891285
1. If IsValidMonthCodeForCalendar(_calendar_, _fields_.[[MonthCode]]) is *false*, throw a *RangeError* exception.
1290-
1. If _overflow_ is ~reject~, then
1291-
1. Let _month_ be MonthCodeToArithmeticalMonth(_calendar_, _year_, _fields_.[[MonthCode]]).
1292-
1. If _month_ is ~invalid~, throw a *RangeError* exception.
1293-
1. Else,
1294-
1. Let _month_ be RegulateNonISOYearMonth(_calendar_, _year_, _fields_.[[MonthCode]], 0).[[Month]].
1286+
1. Let _month_ be ? ConstrainMonthCodeToArithmeticalMonth(_calendar_, _year_, _fields_.[[MonthCode]], _overflow_).
12951287
1. Else,
12961288
1. Assert: _fields_.[[Month]] is not ~unset~.
12971289
1. Let _month_ be _fields_.[[Month]].

0 commit comments

Comments
 (0)