You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Editorial: Combine chinese/dangi and other reference year clauses
After having fixed the assertion failures etc. in the previous commits,
these two clauses look a lot more alike. It's possible to combine them,
only special-casing two things for chinese/dangi: the maximum number 30
of days in month, and the extra lookup in the table to handle rare
month codes.
Closes: #123
Copy file name to clipboardExpand all lines: spec.emu
+17-33Lines changed: 17 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -1311,45 +1311,29 @@ contributors: Google, Ecma International
1311
1311
1. Let _month_ be _monthsInYear_.
1312
1312
1. Else,
1313
1313
1. Let _month_ be _fields_.[[Month]].
1314
+
1. If _fields_.[[Year]] is not ~unset~, then
1315
+
1. [declared="isoDate"] If there exists no combination of inputs such that ! CalendarIntegersToISO(_calendar_, _fields_.[[Year]], ..., ...) would return an ISO Date Record _isoDate_ for which ISODateWithinLimits(_isoDate_) is *true*, throw a *RangeError* exception.
1316
+
1. NOTE: The above step exists so as not to require calculating whether the month and day described in _fields_ exist in user-provided years arbitrarily far in the future or past.
1317
+
1. If _monthCode_ is ~unset~, then
1318
+
1. Let _fieldsISODate_ be ! CalendarIntegersToISO(_calendar_, _fields_.[[Year]], _month_, 1).
1319
+
1. Set _monthCode_ to NonISOCalendarISOToDate(_calendar_, _fieldsISODate_).[[MonthCode]].
1320
+
1. Else,
1321
+
1. Set _monthCode_ to ? ConstrainMonthCode(_calendar_, _fields_.[[Year]], _monthCode_, _overflow_).
1322
+
1. Let _daysInMonth_ be CalendarDaysInMonth(_calendar_, _fields_.[[Year]], _month_).
1323
+
1. Else,
1324
+
1. Assert: _monthCode_ is not ~unset~.
1325
+
1. If _calendar_ is *"chinese"* or *"dangi"*, let _daysInMonth_ be 30; else, let _daysInMonth_ be the maximum number of days in the month described by _monthCode_ in any year.
1326
+
1. If _fields_.[[Day]] > _daysInMonth_, then
1327
+
1. If _overflow_ is ~reject~, throw a *RangeError* exception.
1328
+
1. Let _day_ be _daysInMonth_.
1329
+
1. Else,
1330
+
1. Let _day_ be _fields_.[[Day]].
1314
1331
1. If _calendar_ is *"chinese"* or *"dangi"*, then
1315
1332
1. NOTE: This special case handles combinations of month and day that theoretically could occur but are not known to have occurred historically and cannot be accurately calculated to occur in the future, even if it may be possible to construct a PlainDate with such combinations due to inaccurate approximations. This is explicitly mentioned here because as time goes on, these dates may become known to have occurred historically, or may be more accurately calculated to occur in the future.
1316
-
1. If _fields_.[[Year]] is not ~unset~, then
1317
-
1. [declared="isoDate"] If there exists no combination of inputs such that ! CalendarIntegersToISO(_calendar_, _fields_.[[Year]], ..., ...) would return an ISO Date Record _isoDate_ for which ISODateWithinLimits(_isoDate_) is *true*, throw a *RangeError* exception.
1318
-
1. NOTE: The above step exists so as not to require calculating whether the month and day described in _fields_ exist in user-provided years arbitrarily far in the future or past.
1319
-
1. If _monthCode_ is ~unset~, then
1320
-
1. Let _fieldsISODate_ be ! CalendarIntegersToISO(_calendar_, _fields_.[[Year]], _month_, 1).
1321
-
1. Set _monthCode_ to NonISOCalendarISOToDate(_calendar_, _fieldsISODate_).[[MonthCode]].
1322
-
1. Else,
1323
-
1. Set _monthCode_ to ? ConstrainMonthCode(_calendar_, _fields_.[[Year]], _monthCode_, _overflow_).
1324
-
1. Let _daysInMonth_ be CalendarDaysInMonth(_calendar_, _fields_.[[Year]], _month_).
1325
-
1. Else,
1326
-
1. Let _daysInMonth_ be 30.
1327
-
1. If _fields_.[[Day]] > _daysInMonth_, then
1328
-
1. If _overflow_ is ~reject~, throw a *RangeError* exception.
1329
-
1. Let _day_ be _daysInMonth_.
1330
-
1. Else,
1331
-
1. Let _day_ be _fields_.[[Day]].
1332
1333
1. Let _row_ be the row in <emu-xref href="#chinese-dangi-iso-reference-years"></emu-xref> with a value in the "Month Code" column matching _monthCode_.
1333
1334
1. If the "Reference Year (Days 1-29)" column of _row_ is "—", or _day_ = 30 and the "Reference Year (<emu-not-ref>Day</emu-not-ref> 30)" column of _row_ is "—", then
1334
1335
1. If _overflow_ is ~reject~, throw a *RangeError* exception.
1335
1336
1. Set _monthCode_ to CreateMonthCode(! ParseMonthCode(_monthCode_).[[MonthNumber]], *false*).
1336
-
1. Else,
1337
-
1. If _fields_.[[Year]] is not ~unset~, then
1338
-
1. If there exists no combination of inputs such that ! CalendarIntegersToISO(_calendar_, _fields_.[[Year]], ..., ...) would return an ISO Date Record _isoDate_ for which ISODateWithinLimits(_isoDate_) is *true*, throw a *RangeError* exception.
1339
-
1. If _monthCode_ is ~unset~, then
1340
-
1. Let _fieldsISODate_ be ! CalendarIntegersToISO(_calendar_, _fields_.[[Year]], _month_, 1).
1341
-
1. Set _monthCode_ to NonISOCalendarISOToDate(_calendar_, _fieldsISODate_).[[MonthCode]].
1342
-
1. Else,
1343
-
1. Set _monthCode_ to ? ConstrainMonthCode(_calendar_, _fields_.[[Year]], _monthCode_, _overflow_).
1344
-
1. Let _daysInMonth_ be CalendarDaysInMonth(_calendar_, _fields_.[[Year]], _month_).
1345
-
1. Else,
1346
-
1. Assert: _monthCode_ is not ~unset~.
1347
-
1. Let _daysInMonth_ be the maximum number of days in the month described by _monthCode_ in any year.
1348
-
1. If _fields_.[[Day]] > _daysInMonth_, then
1349
-
1. If _overflow_ is ~reject~, throw a *RangeError* exception.
1350
-
1. Let _day_ be _daysInMonth_.
1351
-
1. Else,
1352
-
1. Let _day_ be _fields_.[[Day]].
1353
1337
1. Let _referenceYear_ be the ISO reference year for _monthCode_ and _day_ as described above. If _calendar_ is *"chinese"* or *"dangi"*, the reference years in <emu-xref href="#chinese-dangi-iso-reference-years"></emu-xref> are to be used.
1354
1338
1. Return the latest possible ISO Date Record _isoDate_ such that _isoDate_.[[Year]] = _referenceYear_ and NonISOCalendarISOToDate(_calendar_, _isoDate_) returns a Calendar Date Record whose [[MonthCode]] and [[Day]] field values respectively equal _monthCode_ and _day_.
0 commit comments