Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Editorial: More suggestions from Anba #3004

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions polyfill/lib/calendar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1860,9 +1860,11 @@ const helperDangi = { ...helperChinese, id: 'dangi' };
* ISO and non-ISO implementations vs. code that was very different.
*/
const nonIsoGeneralImpl = {
extraFields(type = 'date') {
if (type === 'month-day') return [];
return ['era', 'eraYear'];
extraFields(fields) {
if (this.helper.hasEra && Call(ArrayPrototypeIncludes, fields, ['year'])) {
return ['era', 'eraYear'];
}
return [];
},
resolveFields(fields /* , type */) {
if (this.helper.calendarType !== 'lunisolar') {
Expand Down
24 changes: 13 additions & 11 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,8 @@ export function GetTemporalRelativeToOption(options) {
const fields = PrepareCalendarFields(
calendar,
relativeTo,
['day', 'month', 'monthCode', 'year'],
['hour', 'microsecond', 'millisecond', 'minute', 'nanosecond', 'offset', 'second', 'timeZone'],
['year', 'month', 'monthCode', 'day'],
['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond', 'offset', 'timeZone'],
[]
);
({ isoDate, time } = InterpretTemporalDateTimeFields(calendar, fields, 'constrain'));
Expand Down Expand Up @@ -1075,7 +1075,7 @@ export function ISODateToFields(calendar, isoDate, type = 'date') {
}

export function PrepareCalendarFields(calendar, bag, calendarFieldNames, nonCalendarFieldNames, requiredFields) {
const extraFieldNames = calendarImplForID(calendar).extraFields();
const extraFieldNames = calendarImplForID(calendar).extraFields(calendarFieldNames);
const fields = Call(ArrayPrototypeConcat, calendarFieldNames, [nonCalendarFieldNames, extraFieldNames]);
const result = ObjectCreate(null);
let any = false;
Expand Down Expand Up @@ -1134,7 +1134,7 @@ export function ToTemporalDate(item, options = undefined) {
return CreateTemporalDate(GetSlot(item, ISO_DATE_TIME).isoDate, GetSlot(item, CALENDAR));
}
const calendar = GetTemporalCalendarIdentifierWithISODefault(item);
const fields = PrepareCalendarFields(calendar, item, ['day', 'month', 'monthCode', 'year'], [], []);
const fields = PrepareCalendarFields(calendar, item, ['year', 'month', 'monthCode', 'day'], [], []);
const overflow = GetTemporalOverflowOption(GetOptionsObject(options));
const isoDate = CalendarDateFromFields(calendar, fields, overflow);
return CreateTemporalDate(isoDate, calendar);
Expand Down Expand Up @@ -1186,8 +1186,8 @@ export function ToTemporalDateTime(item, options = undefined) {
const fields = PrepareCalendarFields(
calendar,
item,
['day', 'month', 'monthCode', 'year'],
['hour', 'microsecond', 'millisecond', 'minute', 'nanosecond', 'second'],
['year', 'month', 'monthCode', 'day'],
['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond'],
[]
);
const overflow = GetTemporalOverflowOption(GetOptionsObject(options));
Expand Down Expand Up @@ -1323,7 +1323,7 @@ export function ToTemporalMonthDay(item, options = undefined) {
if (calendar === undefined) calendar = 'iso8601';
calendar = ToTemporalCalendarIdentifier(calendar);
}
const fields = PrepareCalendarFields(calendar, item, ['day', 'month', 'monthCode', 'year'], [], []);
const fields = PrepareCalendarFields(calendar, item, ['year', 'month', 'monthCode', 'day'], [], []);
const overflow = GetTemporalOverflowOption(GetOptionsObject(options));
const isoDate = CalendarMonthDayFromFields(calendar, fields, overflow);
return CreateTemporalMonthDay(isoDate, calendar);
Expand Down Expand Up @@ -1382,7 +1382,7 @@ export function ToTemporalYearMonth(item, options = undefined) {
return CreateTemporalYearMonth(GetSlot(item, ISO_DATE), GetSlot(item, CALENDAR));
}
const calendar = GetTemporalCalendarIdentifierWithISODefault(item);
const fields = PrepareCalendarFields(calendar, item, ['month', 'monthCode', 'year'], [], []);
const fields = PrepareCalendarFields(calendar, item, ['year', 'month', 'monthCode'], [], []);
const overflow = GetTemporalOverflowOption(GetOptionsObject(options));
const isoDate = CalendarYearMonthFromFields(calendar, fields, overflow);
return CreateTemporalYearMonth(isoDate, calendar);
Expand Down Expand Up @@ -1498,8 +1498,8 @@ export function ToTemporalZonedDateTime(item, options = undefined) {
const fields = PrepareCalendarFields(
calendar,
item,
['day', 'month', 'monthCode', 'year'],
['hour', 'microsecond', 'millisecond', 'minute', 'nanosecond', 'offset', 'second', 'timeZone'],
['year', 'month', 'monthCode', 'day'],
['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond', 'offset', 'timeZone'],
['timeZone']
);
({ offset, timeZone } = fields);
Expand Down Expand Up @@ -1785,7 +1785,9 @@ export function CalendarYearMonthFromFields(calendar, fields, overflow) {
export function CalendarMonthDayFromFields(calendar, fields, overflow) {
const calendarImpl = calendarImplForID(calendar);
calendarImpl.resolveFields(fields, 'month-day');
return calendarImpl.monthDayToISOReferenceDate(fields, overflow);
const result = calendarImpl.monthDayToISOReferenceDate(fields, overflow);
RejectDateRange(result);
return result;
}

export function ToTemporalTimeZoneIdentifier(temporalTimeZoneLike) {
Expand Down
2 changes: 1 addition & 1 deletion polyfill/lib/plaindate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export class PlainDate {
const partialDate = ES.PrepareCalendarFields(
calendar,
temporalDateLike,
['day', 'month', 'monthCode', 'year'],
['year', 'month', 'monthCode', 'day'],
[],
'partial'
);
Expand Down
4 changes: 2 additions & 2 deletions polyfill/lib/plaindatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ export class PlainDateTime {
const partialDateTime = ES.PrepareCalendarFields(
calendar,
temporalDateTimeLike,
['day', 'month', 'monthCode', 'year'],
['hour', 'microsecond', 'millisecond', 'minute', 'nanosecond', 'second'],
['year', 'month', 'monthCode', 'day'],
['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond'],
'partial'
);
fields = ES.CalendarMergeFields(calendar, fields, partialDateTime);
Expand Down
2 changes: 1 addition & 1 deletion polyfill/lib/plainmonthday.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class PlainMonthDay {
const partialMonthDay = ES.PrepareCalendarFields(
calendar,
temporalMonthDayLike,
['day', 'month', 'monthCode', 'year'],
['year', 'month', 'monthCode', 'day'],
[],
'partial'
);
Expand Down
2 changes: 1 addition & 1 deletion polyfill/lib/plainyearmonth.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export class PlainYearMonth {
const partialYearMonth = ES.PrepareCalendarFields(
calendar,
temporalYearMonthLike,
['month', 'monthCode', 'year'],
['year', 'month', 'monthCode'],
[],
'partial'
);
Expand Down
4 changes: 2 additions & 2 deletions polyfill/lib/zoneddatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ export class ZonedDateTime {
const partialZonedDateTime = ES.PrepareCalendarFields(
calendar,
temporalZonedDateTimeLike,
['day', 'month', 'monthCode', 'year'],
['hour', 'microsecond', 'millisecond', 'minute', 'nanosecond', 'offset', 'second'],
['year', 'month', 'monthCode', 'day'],
['hour', 'minute', 'second', 'millisecond', 'microsecond', 'nanosecond', 'offset'],
'partial'
);
fields = ES.CalendarMergeFields(calendar, fields, partialZonedDateTime);
Expand Down
62 changes: 1 addition & 61 deletions spec/abstractops.html
Original file line number Diff line number Diff line change
Expand Up @@ -601,7 +601,7 @@ <h1>
1. Let _plainDate_ be ! CreateTemporalDate(_value_.[[ISODateTime]].[[ISODate]], _value_.[[Calendar]]).
1. Return the Record { [[PlainRelativeTo]]: _plainDate_, [[ZonedRelativeTo]]: *undefined* }.
1. Let _calendar_ be ? GetTemporalCalendarIdentifierWithISODefault(_value_).
1. Let _fields_ be ? PrepareCalendarFields(_calendar_, _value_, « ~day~, ~month~, ~month-code~, ~year~ », « ~hour~, ~microsecond~, ~millisecond~, ~minute~, ~nanosecond~, ~offset~, ~second~, ~time-zone~ », «»).
1. Let _fields_ be ? PrepareCalendarFields(_calendar_, _value_, « ~year~, ~month~, ~month-code~, ~day~ », « ~hour~, ~minute~, ~second~, ~millisecond~, ~microsecond~, ~nanosecond~, ~offset~, ~time-zone~ », «»).
1. Let _result_ be ? InterpretTemporalDateTimeFields(_calendar_, _fields_, ~constrain~).
1. Let _timeZone_ be _fields_.[[TimeZone]].
1. Let _offsetString_ be _fields_.[[Offset]].
Expand Down Expand Up @@ -1838,66 +1838,6 @@ <h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-preparecalendarfields" type="abstract operation">
<h1>
PrepareCalendarFields (
_calendar_: a calendar type,
_fields_: an Object,
_calendarFieldNames_: a List of values from the Enumeration Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref>,
_nonCalendarFieldNames_: a List of values from the Enumeration Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref>,
_requiredFieldNames_: ~partial~ or a List of values from the Enumeration Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref>,
): either a normal completion containing a Calendar Fields Record, or a throw completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>
It returns the result of reading from _fields_ all of the property names corresponding to _calendarFieldNames_ and _nonCalendarFieldNames_, plus any extra fields required by the calendar.
The returned Record has a non-~unset~ value for each element of _fieldNames_ that corresponds with a non-*undefined* property on _fields_ used as the input for relevant conversion.
When _requiredFields_ is ~partial~, this operation throws if none of the properties are present with a non-*undefined* value.
When _requiredFields_ is a List, this operation throws if any of the properties named by it are absent or *undefined*.
</dd>
</dl>
<emu-alg>
1. Assert: If _requiredFieldNames_ is a List, _requiredFieldNames_ contains zero or one of each of the elements of _calendarFieldNames_ and _nonCalendarFieldNames_.
1. Let _fieldNames_ be the list-concatenation of _calendarFieldNames_ and _nonCalendarFieldNames_.
1. Let _extraFieldNames_ be CalendarExtraFields(_calendar_, _calendarFieldNames_).
1. Set _fieldNames_ to the list-concatenation of _fieldNames_ and _extraFieldNames_.
1. Assert: _fieldNames_ contains no duplicate elements.
1. Let _result_ be a Calendar Fields Record with all fields equal to ~unset~.
1. Let _any_ be *false*.
1. Let _sortedPropertyNames_ be a List whose elements are the values in the Property Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref> corresponding to the elements of _fieldNames_, sorted according to lexicographic code unit order.
1. For each property name _property_ of _sortedPropertyNames_, do
1. Let _key_ be the value in the Enumeration Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref> corresponding to the row whose Property Key value is _property_.
1. Let _value_ be ? Get(_fields_, _property_).
1. If _value_ is not *undefined*, then
1. Set _any_ to *true*.
1. Let _Conversion_ be the Conversion value of the same row.
1. If _Conversion_ is ~to-integer-with-truncation~, then
1. Set _value_ to ? ToIntegerWithTruncation(_value_).
1. Set _value_ to 𝔽(_value_).
1. Else if _Conversion_ is ~to-positive-integer-with-truncation~, then
1. Set _value_ to ? ToPositiveIntegerWithTruncation(_value_).
1. Set _value_ to 𝔽(_value_).
1. Else if _Conversion_ is ~to-string~, then
1. Set _value_ to ? ToString(_value_).
1. Else if _Conversion_ is ~to-temporal-time-zone-identifier~, then
1. Set _value_ to ? ToTemporalTimeZoneIdentifier(_value_).
1. Else if _Conversion_ is ~to-month-code~, then
1. Set _value_ to ? ToMonthCode(_value_).
1. Else,
1. Assert: _Conversion_ is ~to-offset-string~.
1. Set _value_ to ? ToOffsetString(_value_).
1. Set _result_'s field whose name is given in the Field Name column of the same row to _value_.
1. Else if _requiredFieldNames_ is a List, then
1. If _requiredFieldNames_ contains _key_, then
1. Throw a *TypeError* exception.
1. Set _result_'s field whose name is given in the Field Name column of the same row to the corresponding Default value of the same row.
1. If _requiredFieldNames_ is ~partial~ and _any_ is *false*, then
1. Throw a *TypeError* exception.
1. Return _result_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-getdifferencesettings" type="abstract operation">
<h1>
GetDifferenceSettings (
Expand Down
68 changes: 65 additions & 3 deletions spec/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,66 @@ <h1>Calendar Fields Records</h1>
</emu-table>
</emu-clause>

<emu-clause id="sec-temporal-preparecalendarfields" type="abstract operation">
<h1>
PrepareCalendarFields (
_calendar_: a calendar type,
_fields_: an Object,
_calendarFieldNames_: a List of values from the Enumeration Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref>,
_nonCalendarFieldNames_: a List of values from the Enumeration Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref>,
_requiredFieldNames_: ~partial~ or a List of values from the Enumeration Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref>,
): either a normal completion containing a Calendar Fields Record, or a throw completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>
It returns the result of reading from _fields_ all of the property names corresponding to _calendarFieldNames_ and _nonCalendarFieldNames_, plus any extra fields required by the calendar.
The returned Record has a non-~unset~ value for each element of _fieldNames_ that corresponds with a non-*undefined* property on _fields_ used as the input for relevant conversion.
When _requiredFields_ is ~partial~, this operation throws if none of the properties are present with a non-*undefined* value.
When _requiredFields_ is a List, this operation throws if any of the properties named by it are absent or *undefined*.
</dd>
</dl>
<emu-alg>
1. Assert: If _requiredFieldNames_ is a List, _requiredFieldNames_ contains zero or one of each of the elements of _calendarFieldNames_ and _nonCalendarFieldNames_.
1. Let _fieldNames_ be the list-concatenation of _calendarFieldNames_ and _nonCalendarFieldNames_.
1. Let _extraFieldNames_ be CalendarExtraFields(_calendar_, _calendarFieldNames_).
1. Set _fieldNames_ to the list-concatenation of _fieldNames_ and _extraFieldNames_.
1. Assert: _fieldNames_ contains no duplicate elements.
1. Let _result_ be a Calendar Fields Record with all fields equal to ~unset~.
1. Let _any_ be *false*.
1. Let _sortedPropertyNames_ be a List whose elements are the values in the Property Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref> corresponding to the elements of _fieldNames_, sorted according to lexicographic code unit order.
1. For each property name _property_ of _sortedPropertyNames_, do
1. Let _key_ be the value in the Enumeration Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref> corresponding to the row whose Property Key value is _property_.
1. Let _value_ be ? Get(_fields_, _property_).
1. If _value_ is not *undefined*, then
1. Set _any_ to *true*.
1. Let _Conversion_ be the Conversion value of the same row.
1. If _Conversion_ is ~to-integer-with-truncation~, then
1. Set _value_ to ? ToIntegerWithTruncation(_value_).
1. Set _value_ to 𝔽(_value_).
1. Else if _Conversion_ is ~to-positive-integer-with-truncation~, then
1. Set _value_ to ? ToPositiveIntegerWithTruncation(_value_).
1. Set _value_ to 𝔽(_value_).
1. Else if _Conversion_ is ~to-string~, then
1. Set _value_ to ? ToString(_value_).
1. Else if _Conversion_ is ~to-temporal-time-zone-identifier~, then
1. Set _value_ to ? ToTemporalTimeZoneIdentifier(_value_).
1. Else if _Conversion_ is ~to-month-code~, then
1. Set _value_ to ? ToMonthCode(_value_).
1. Else,
1. Assert: _Conversion_ is ~to-offset-string~.
1. Set _value_ to ? ToOffsetString(_value_).
1. Set _result_'s field whose name is given in the Field Name column of the same row to _value_.
1. Else if _requiredFieldNames_ is a List, then
1. If _requiredFieldNames_ contains _key_, then
1. Throw a *TypeError* exception.
1. Set _result_'s field whose name is given in the Field Name column of the same row to the corresponding Default value of the same row.
1. If _requiredFieldNames_ is ~partial~ and _any_ is *false*, then
1. Throw a *TypeError* exception.
1. Return _result_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-calendarfieldkeyspresent" type="abstract operation">
<h1>
CalendarFieldKeysPresent (
Expand Down Expand Up @@ -605,7 +665,9 @@ <h1>
</dl>
<emu-alg>
1. Perform ? CalendarResolveFields(_calendar_, _fields_, ~month-day~).
1. Return ? CalendarMonthDayToISOReferenceDate(_calendar_, _fields_, _overflow_).
1. Let _result_ be ? CalendarMonthDayToISOReferenceDate(_calendar_, _fields_, _overflow_).
1. If ISODateWithinLimits(_result_) is *false*, throw a *RangeError* exception.
1. Return _result_.
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -860,12 +922,12 @@ <h1>
<h1>
CalendarExtraFields (
_calendar_: a calendar type,
_type_: ~date~, ~year-month~, ~month-day~, or a List of values from the Enumeration Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref>,
_fields_: a List of values from the Enumeration Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref>,
): a List of values from the Enumeration Key column of <emu-xref href="#table-temporal-calendar-fields-record-fields"></emu-xref>
</h1>
<dl class="header">
<dt>description</dt>
<dd>It characterizes calendar-specific fields that are relevant for values of the provided _type_ in the built-in calendar identified by _calendar_ (inferring the type when _type_ is a List by interpreting its elements as field names). For example, « ~era~, ~era-year~ » is returned when _calendar_ is *"gregory"* or *"japanese"* and _type_ is ~date~ or ~year-month~ or a List containing ~year~.</dd>
<dd>It characterizes calendar-specific fields that are relevant for the provided _fields_ in the built-in calendar identified by _calendar_. For example, « ~era~, ~era-year~ » is returned when _calendar_ is *"gregory"* or *"japanese"* and _fields_ is a List containing ~year~.</dd>
</dl>
<emu-alg>
1. If _calendar_ is *"iso8601"*, return an empty List.
Expand Down
Loading
Loading