Skip to content

Commit 28357ea

Browse files
ptomatosffc
andcommitted
Editorial: Introduce CreateMonthCode and ParseMonthCode
These operations are used in the Intl Era Monthcode proposal. They are also already useful in Temporal, so introduce them here. Co-Authored-By: Shane F. Carr <shane@unicode.org>
1 parent 5f15e4e commit 28357ea

File tree

1 file changed

+60
-12
lines changed

1 file changed

+60
-12
lines changed

spec/calendar.html

Lines changed: 60 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,59 @@ <h1>AvailableCalendars ( ): a List of calendar types</h1>
4343
</emu-clause>
4444
</emu-clause>
4545

46+
<emu-clause id="sec-temporal-month-codes">
47+
<h1>Month Codes</h1>
48+
49+
<emu-clause id="sec-temporal-parsemonthcode" type="abstract operation">
50+
<h1>
51+
ParseMonthCode (
52+
_monthCode_: a String,
53+
): a Record with fields [[MonthNumber]] (an integer) and [[IsLeapMonth]] (a Boolean)
54+
</h1>
55+
<dl class="header">
56+
<dt>description</dt>
57+
<dd>
58+
It parses a valid month code string (such as one returned by ToMonthCode or CreateMonthCode) into its parts.
59+
</dd>
60+
</dl>
61+
<p>It performs the following steps when called:</p>
62+
<emu-alg>
63+
1. If the length of _monthCode_ is 3, then
64+
1. Let _isLeapMonth_ be *false*.
65+
1. Else,
66+
1. Assert: The length of _monthCode_ is 4.
67+
1. Let _isLeapMonth_ be *true*.
68+
1. Let _monthCodeDigits_ be the substring of _monthCode_ from 1 to 3.
69+
1. Let _monthNumber_ be ℝ(StringToNumber(_monthCodeDigits_)).
70+
1. Return the Record { [[MonthNumber]]: _monthNumber_, [[IsLeapMonth]]: _isLeapMonth_ }.
71+
</emu-alg>
72+
</emu-clause>
73+
74+
<emu-clause id="sec-temporal-createmonthcode" type="abstract operation">
75+
<h1>
76+
CreateMonthCode (
77+
_monthNumber_: an integer in the inclusive interval from 0 to 99,
78+
_isLeapMonth_: a Boolean,
79+
): a String
80+
</h1>
81+
<dl class="header">
82+
<dt>description</dt>
83+
<dd>
84+
It creates a month code with the given month number and leap month flag.
85+
</dd>
86+
</dl>
87+
<p>It performs the following steps when called:</p>
88+
<emu-alg>
89+
1. Assert: If _isLeapMonth_ is *false*, _monthNumber_ > 0.
90+
1. Let _numberPart_ be ToZeroPaddedDecimalString(_monthNumber_, 2).
91+
1. If _isLeapMonth_ is *true*, then
92+
1. Return the string-concatenation of the code unit 0x004D (LATIN CAPITAL LETTER M), _numberPart_, and the code unit 0x004C (LATIN CAPITAL LETTER L).
93+
1. Else,
94+
1. Return the string-concatenation of the code unit 0x004D (LATIN CAPITAL LETTER M) and _numberPart_.
95+
</emu-alg>
96+
</emu-clause>
97+
</emu-clause>
98+
4699
<emu-clause id="sec-temporal-calendar-abstract-ops">
47100
<h1>Abstract Operations</h1>
48101

@@ -973,15 +1026,13 @@ <h1>
9731026
</dl>
9741027
<emu-alg>
9751028
1. If _calendar_ is *"iso8601"*, then
976-
1. Let _monthNumberPart_ be ToZeroPaddedDecimalString(_isoDate_.[[Month]], 2).
977-
1. Let _monthCode_ be the string-concatenation of *"M"* and _monthNumberPart_.
9781029
1. If MathematicalInLeapYear(EpochTimeForYear(_isoDate_.[[Year]])) = 1, let _inLeapYear_ be *true*; else let _inLeapYear_ be *false*.
9791030
1. Return Calendar Date Record {
9801031
[[Era]]: *undefined*,
9811032
[[EraYear]]: *undefined*,
9821033
[[Year]]: _isoDate_.[[Year]],
9831034
[[Month]]: _isoDate_.[[Month]],
984-
[[MonthCode]]: _monthCode_,
1035+
[[MonthCode]]: CreateMonthCode(_isoDate_.[[Month]], *false*),
9851036
[[Day]]: _isoDate_.[[Day]],
9861037
[[DayOfWeek]]: ISODayOfWeek(_isoDate_),
9871038
[[DayOfYear]]: ISODayOfYear(_isoDate_),
@@ -1173,15 +1224,12 @@ <h1>
11731224
1. If _monthCode_ is ~unset~, then
11741225
1. If _month_ is ~unset~, throw a *TypeError* exception.
11751226
1. Return ~unused~.
1176-
1. Assert: _monthCode_ is a String.
1177-
1. NOTE: The ISO 8601 calendar does not include leap months.
1178-
1. If the length of _monthCode_ is not 3, throw a *RangeError* exception.
1179-
1. If the first code unit of _monthCode_ is not 0x004D (LATIN CAPITAL LETTER M), throw a *RangeError* exception.
1180-
1. Let _monthCodeDigits_ be the substring of _monthCode_ from 1.
1181-
1. If ParseText(StringToCodePoints(_monthCodeDigits_), |DateMonth|) is a List of errors, throw a *RangeError* exception.
1182-
1. Let _monthCodeInteger_ be ℝ(StringToNumber(_monthCodeDigits_)).
1183-
1. If _month_ is not ~unset~ and _month__monthCodeInteger_, throw a *RangeError* exception.
1184-
1. Set _fields_.[[Month]] to _monthCodeInteger_.
1227+
1. Perform ? ToMonthCode(_monthCode_).
1228+
1. Let _parsedMonthCode_ be ParseMonthCode(_monthCode_).
1229+
1. If _parsedMonthCode_.[[IsLeapMonth]] is *true*, throw a *RangeError* exception.
1230+
1. If _parsedMonthCode_.[[MonthNumber]] > 12, throw a *RangeError* exception.
1231+
1. If _month_ is not ~unset~ and _month__parsedMonthCode_.[[MonthNumber]], throw a *RangeError* exception.
1232+
1. Set _fields_.[[Month]] to _parsedMonthCode_.[[MonthNumber]].
11851233
1. Else,
11861234
1. Perform ? NonISOResolveFields(_calendar_, _fields_, _type_).
11871235
1. Return ~unused~.

0 commit comments

Comments
 (0)