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

Normative: Fix inconsistency in order of observable operations in ...FromFields() for non-ISO calendars #2377

Merged
merged 1 commit into from
Sep 15, 2022
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
12 changes: 6 additions & 6 deletions polyfill/lib/calendar.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -233,24 +233,24 @@ DefineIntrinsic('Temporal.Calendar.from', Calendar.from);

impl['iso8601'] = {
dateFromFields(fields, options, calendar) {
const overflow = ES.ToTemporalOverflow(options);
fields = ES.PrepareTemporalFields(fields, ['day', 'month', 'monthCode', 'year'], ['year', 'day']);
const overflow = ES.ToTemporalOverflow(options);
fields = resolveNonLunisolarMonth(fields);
let { year, month, day } = fields;
({ year, month, day } = ES.RegulateISODate(year, month, day, overflow));
return ES.CreateTemporalDate(year, month, day, calendar);
},
yearMonthFromFields(fields, options, calendar) {
const overflow = ES.ToTemporalOverflow(options);
fields = ES.PrepareTemporalFields(fields, ['month', 'monthCode', 'year'], ['year']);
const overflow = ES.ToTemporalOverflow(options);
fields = resolveNonLunisolarMonth(fields);
let { year, month } = fields;
({ year, month } = ES.RegulateISOYearMonth(year, month, overflow));
return ES.CreateTemporalYearMonth(year, month, calendar, /* referenceISODay = */ 1);
},
monthDayFromFields(fields, options, calendar) {
const overflow = ES.ToTemporalOverflow(options);
fields = ES.PrepareTemporalFields(fields, ['day', 'month', 'monthCode', 'year'], ['day']);
const overflow = ES.ToTemporalOverflow(options);
if (fields.month !== undefined && fields.year === undefined && fields.monthCode === undefined) {
throw new TypeError('either year or monthCode required with month');
}
Expand Down Expand Up @@ -1874,35 +1874,35 @@ const helperDangi = ObjectAssign({}, { ...helperChinese, id: 'dangi' });
*/
const nonIsoGeneralImpl = {
dateFromFields(fields, options, calendar) {
const overflow = ES.ToTemporalOverflow(options);
const cache = new OneObjectCache();
const fieldNames = this.fields(['day', 'month', 'monthCode', 'year']);
ES.Call(ArrayPrototypeSort, fieldNames, []);
fields = ES.PrepareTemporalFields(fields, fieldNames, []);
const overflow = ES.ToTemporalOverflow(options);
const { year, month, day } = this.helper.calendarToIsoDate(fields, overflow, cache);
const result = ES.CreateTemporalDate(year, month, day, calendar);
cache.setObject(result);
return result;
},
yearMonthFromFields(fields, options, calendar) {
const overflow = ES.ToTemporalOverflow(options);
const cache = new OneObjectCache();
const fieldNames = this.fields(['month', 'monthCode', 'year']);
ES.Call(ArrayPrototypeSort, fieldNames, []);
fields = ES.PrepareTemporalFields(fields, fieldNames, []);
const overflow = ES.ToTemporalOverflow(options);
const { year, month, day } = this.helper.calendarToIsoDate({ ...fields, day: 1 }, overflow, cache);
const result = ES.CreateTemporalYearMonth(year, month, calendar, /* referenceISODay = */ day);
cache.setObject(result);
return result;
},
monthDayFromFields(fields, options, calendar) {
const overflow = ES.ToTemporalOverflow(options);
const cache = new OneObjectCache();
// For lunisolar calendars, either `monthCode` or `year` must be provided
// because `month` is ambiguous without a year or a code.
const fieldNames = this.fields(['day', 'month', 'monthCode', 'year']);
ES.Call(ArrayPrototypeSort, fieldNames, []);
fields = ES.PrepareTemporalFields(fields, fieldNames, []);
const overflow = ES.ToTemporalOverflow(options);
const { year, month, day } = this.helper.monthDayFromFields(fields, overflow, cache);
// `year` is a reference year where this month/day exists in this calendar
const result = ES.CreateTemporalMonthDay(month, day, calendar, /* referenceISOYear = */ year);
Expand Down
2 changes: 1 addition & 1 deletion polyfill/test262
Submodule test262 updated 47 files
+32 −0 test/built-ins/Array/prototype/group/array-like.js
+35 −0 test/built-ins/Array/prototype/group/callback-arg.js
+24 −0 test/built-ins/Array/prototype/group/callback-throws.js
+28 −0 test/built-ins/Array/prototype/group/emptyList.js
+30 −0 test/built-ins/Array/prototype/group/evenOdd.js
+31 −0 test/built-ins/Array/prototype/group/get-throws.js
+28 −0 test/built-ins/Array/prototype/group/groupLength.js
+29 −0 test/built-ins/Array/prototype/group/invalid-callback.js
+28 −0 test/built-ins/Array/prototype/group/invalid-object.js
+28 −0 test/built-ins/Array/prototype/group/invalid-property-key.js
+36 −0 test/built-ins/Array/prototype/group/length-throw.js
+26 −0 test/built-ins/Array/prototype/group/length.js
+25 −0 test/built-ins/Array/prototype/group/name.js
+27 −0 test/built-ins/Array/prototype/group/null-prototype.js
+36 −0 test/built-ins/Array/prototype/group/sparse-array.js
+57 −0 test/built-ins/Array/prototype/group/this-arg-strict.js
+60 −0 test/built-ins/Array/prototype/group/this-arg.js
+37 −0 test/built-ins/Array/prototype/group/toPropertyKey.js
+35 −0 test/built-ins/Array/prototype/groupToMap/array-like.js
+33 −0 test/built-ins/Array/prototype/groupToMap/callback-arg.js
+24 −0 test/built-ins/Array/prototype/groupToMap/callback-throws.js
+28 −0 test/built-ins/Array/prototype/groupToMap/emptyList.js
+30 −0 test/built-ins/Array/prototype/groupToMap/evenOdd.js
+31 −0 test/built-ins/Array/prototype/groupToMap/get-throws.js
+28 −0 test/built-ins/Array/prototype/groupToMap/groupLength.js
+29 −0 test/built-ins/Array/prototype/groupToMap/invalid-callback.js
+28 −0 test/built-ins/Array/prototype/groupToMap/invalid-object.js
+31 −0 test/built-ins/Array/prototype/groupToMap/invalid-property-key.js
+36 −0 test/built-ins/Array/prototype/groupToMap/length-throw.js
+26 −0 test/built-ins/Array/prototype/groupToMap/length.js
+26 −0 test/built-ins/Array/prototype/groupToMap/map-instance.js
+25 −0 test/built-ins/Array/prototype/groupToMap/name.js
+25 −0 test/built-ins/Array/prototype/groupToMap/negativeZero.js
+37 −0 test/built-ins/Array/prototype/groupToMap/sparse-array.js
+57 −0 test/built-ins/Array/prototype/groupToMap/this-arg-strict.js
+60 −0 test/built-ins/Array/prototype/groupToMap/this-arg.js
+39 −0 test/built-ins/Array/prototype/groupToMap/toPropertyKey.js
+3 −3 test/built-ins/Temporal/Calendar/prototype/dateFromFields/order-of-operations.js
+3 −3 test/built-ins/Temporal/Calendar/prototype/monthDayFromFields/order-of-operations.js
+3 −3 test/built-ins/Temporal/Calendar/prototype/yearMonthFromFields/order-of-operations.js
+10 −9 test/intl402/DurationFormat/constructor-options-defaults.js
+0 −1 test/intl402/DurationFormat/constructor-options-fractionalDigits-valid.js
+2 −2 test/intl402/DurationFormat/constructor-options-style-valid.js
+1 −1 test/intl402/DurationFormat/prototype/format/basic-format-en.js
+3 −3 test/intl402/Temporal/Calendar/prototype/dateFromFields/order-of-operations.js
+3 −3 test/intl402/Temporal/Calendar/prototype/monthDayFromFields/order-of-operations.js
+3 −3 test/intl402/Temporal/Calendar/prototype/yearMonthFromFields/order-of-operations.js
6 changes: 3 additions & 3 deletions spec/calendar.html
Original file line number Diff line number Diff line change
Expand Up @@ -572,8 +572,8 @@ <h1>ISODateFromFields ( _fields_, _options_ )</h1>
</p>
<emu-alg>
1. Assert: Type(_fields_) is Object.
1. Let _overflow_ be ? ToTemporalOverflow(_options_).
1. Set _fields_ to ? PrepareTemporalFields(_fields_, « *"day"*, *"month"*, *"monthCode"*, *"year"* », « *"year"*, *"day"* »).
1. Let _overflow_ be ? ToTemporalOverflow(_options_).
1. Let _year_ be ! Get(_fields_, *"year"*).
1. Assert: Type(_year_) is Number.
1. Let _month_ be ? ResolveISOMonth(_fields_).
Expand All @@ -591,8 +591,8 @@ <h1>ISOYearMonthFromFields ( _fields_, _options_ )</h1>
</p>
<emu-alg>
1. Assert: Type(_fields_) is Object.
1. Let _overflow_ be ? ToTemporalOverflow(_options_).
1. Set _fields_ to ? PrepareTemporalFields(_fields_, « *"month"*, *"monthCode"*, *"year"* », « *"year"* »).
1. Let _overflow_ be ? ToTemporalOverflow(_options_).
1. Let _year_ be ! Get(_fields_, *"year"*).
1. Assert: Type(_year_) is Number.
1. Let _month_ be ? ResolveISOMonth(_fields_).
Expand All @@ -612,8 +612,8 @@ <h1>ISOMonthDayFromFields ( _fields_, _options_ )</h1>
</p>
<emu-alg>
1. Assert: Type(_fields_) is Object.
1. Let _overflow_ be ? ToTemporalOverflow(_options_).
1. Set _fields_ to ? PrepareTemporalFields(_fields_, « *"day"*, *"month"*, *"monthCode"*, *"year"* », « *"day"* »).
1. Let _overflow_ be ? ToTemporalOverflow(_options_).
1. Let _month_ be ! Get(_fields_, *"month"*).
1. Let _monthCode_ be ! Get(_fields_, *"monthCode"*).
1. Let _year_ be ! Get(_fields_, *"year"*).
Expand Down
4 changes: 2 additions & 2 deletions spec/intl.html
Original file line number Diff line number Diff line change
Expand Up @@ -1649,10 +1649,10 @@ <h1>Temporal.Calendar.prototype.dateFromFields ( _fields_ [ , _options_ ] )</h1>
1. If _calendar_.[[Identifier]] is *"iso8601"*, then
1. Let _result_ be ? ISODateFromFields(_fields_, _options_).
1. Else,
1. Let _overflow_ be ? ToTemporalOverflow(_options_).
1. Let _fieldNames_ be CalendarDateFields(_calendar_.[[Identifier]], « *"day"*, *"month"*, *"monthCode"*, *"year"* »).
1. Sort _fieldNames_ into the same order as if an Array of the same values had been sorted using %Array.prototype.sort% with *undefined* as _comparefn_.
1. Set _fields_ to ? PrepareTemporalFields(_fields_, _fieldNames_, « »).
1. Let _overflow_ be ? ToTemporalOverflow(_options_).
1. Let _result_ be ? CalendarDateToISO(_calendar_.[[Identifier]], _fields_, _overflow_).
1. Return ? CreateTemporalDate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _calendar_).
</emu-alg>
Expand All @@ -1672,10 +1672,10 @@ <h1>Temporal.Calendar.prototype.yearMonthFromFields ( _fields_ [ , _options_ ] )
1. If _calendar_.[[Identifier]] is *"iso8601"*, then
1. Let _result_ be ? ISOYearMonthFromFields(_fields_, _options_).
1. Else,
1. Let _overflow_ be ? ToTemporalOverflow(_options_).
1. Let _fieldNames_ be CalendarDateFields(_calendar_.[[Identifier]], « *"month"*, *"monthCode"*, *"year"* »).
1. Sort _fieldNames_ into the same order as if an Array of the same values had been sorted using %Array.prototype.sort% with *undefined* as _comparefn_.
1. Set _fields_ to ? PrepareTemporalFields(_fields_, _fieldNames_, « »).
1. Let _overflow_ be ? ToTemporalOverflow(_options_).
1. Let _result_ be ? CalendarDateToISO(_calendar_.[[Identifier]], _fields_, _overflow_).
1. Set _result_.[[ReferenceISODay]] to _result_.[[Day]].
1. Return ? CreateTemporalYearMonth(_result_.[[Year]], _result_.[[Month]], _calendar_, _result_.[[ReferenceISODay]]).
Expand Down