diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs index 34c60fbb13..8185ad9f3c 100644 --- a/polyfill/lib/ecmascript.mjs +++ b/polyfill/lib/ecmascript.mjs @@ -1123,10 +1123,10 @@ export const ES = ObjectAssign({}, ES2020, { ['month', undefined], ['monthCode', undefined], ['nanosecond', 0], - ['offset', undefined], ['second', 0], - ['timeZone'], - ['year', undefined] + ['year', undefined], + ['offset', undefined], + ['timeZone'] ]; // Add extra fields from the calendar at the end fieldNames.forEach((fieldName) => { diff --git a/polyfill/lib/plaindate.mjs b/polyfill/lib/plaindate.mjs index 1c9e5b795f..27b99c4687 100644 --- a/polyfill/lib/plaindate.mjs +++ b/polyfill/lib/plaindate.mjs @@ -141,6 +141,7 @@ export class PlainDate { } let fields = ES.ToTemporalDateFields(this, fieldNames); fields = ES.CalendarMergeFields(calendar, fields, props); + fields = ES.ToTemporalDateFields(fields, fieldNames); options = ES.NormalizeOptionsObject(options); diff --git a/polyfill/lib/plaindatetime.mjs b/polyfill/lib/plaindatetime.mjs index f587163458..d6d9321932 100644 --- a/polyfill/lib/plaindatetime.mjs +++ b/polyfill/lib/plaindatetime.mjs @@ -232,6 +232,7 @@ export class PlainDateTime { } let fields = ES.ToTemporalDateTimeFields(this, fieldNames); fields = ES.CalendarMergeFields(calendar, fields, props); + fields = ES.ToTemporalDateTimeFields(fields, fieldNames); const { year, month, diff --git a/polyfill/lib/plainmonthday.mjs b/polyfill/lib/plainmonthday.mjs index e1cd568053..198fd74c8a 100644 --- a/polyfill/lib/plainmonthday.mjs +++ b/polyfill/lib/plainmonthday.mjs @@ -88,6 +88,7 @@ export class PlainMonthDay { } let fields = ES.ToTemporalMonthDayFields(this, fieldNames); fields = ES.CalendarMergeFields(calendar, fields, props); + fields = ES.ToTemporalMonthDayFields(fields, fieldNames); options = ES.NormalizeOptionsObject(options); return ES.MonthDayFromFields(calendar, fields, options); @@ -124,18 +125,28 @@ export class PlainMonthDay { const calendar = GetSlot(this, CALENDAR); const receiverFieldNames = ES.CalendarFields(calendar, ['day', 'monthCode']); - const fields = ES.ToTemporalMonthDayFields(this, receiverFieldNames); + let fields = ES.ToTemporalMonthDayFields(this, receiverFieldNames); const inputFieldNames = ES.CalendarFields(calendar, ['year']); - const entries = [['year']]; + const inputEntries = [['year']]; // Add extra fields from the calendar at the end inputFieldNames.forEach((fieldName) => { - if (!entries.some(([name]) => name === fieldName)) { - entries.push([fieldName, undefined]); + if (!inputEntries.some(([name]) => name === fieldName)) { + inputEntries.push([fieldName, undefined]); } }); - ObjectAssign(fields, ES.PrepareTemporalFields(item, entries)); - return ES.DateFromFields(calendar, fields); + const inputFields = ES.PrepareTemporalFields(item, inputEntries); + let mergedFields = ES.CalendarMergeFields(calendar, fields, inputFields); + + const mergedFieldNames = [...new Set([...receiverFieldNames, ...inputFieldNames])]; + const mergedEntries = []; + mergedFieldNames.forEach((fieldName) => { + if (!mergedEntries.some(([name]) => name === fieldName)) { + mergedEntries.push([fieldName, undefined]); + } + }); + mergedFields = ES.PrepareTemporalFields(mergedFields, mergedEntries); + return ES.DateFromFields(calendar, mergedFields); } getISOFields() { if (!ES.IsTemporalMonthDay(this)) throw new TypeError('invalid receiver'); diff --git a/polyfill/lib/plainyearmonth.mjs b/polyfill/lib/plainyearmonth.mjs index 2b651cb4c5..5e0d0e302c 100644 --- a/polyfill/lib/plainyearmonth.mjs +++ b/polyfill/lib/plainyearmonth.mjs @@ -113,6 +113,7 @@ export class PlainYearMonth { } let fields = ES.ToTemporalYearMonthFields(this, fieldNames); fields = ES.CalendarMergeFields(calendar, fields, props); + fields = ES.ToTemporalYearMonthFields(fields, fieldNames); options = ES.NormalizeOptionsObject(options); @@ -348,18 +349,28 @@ export class PlainYearMonth { const calendar = GetSlot(this, CALENDAR); const receiverFieldNames = ES.CalendarFields(calendar, ['monthCode', 'year']); - const fields = ES.ToTemporalYearMonthFields(this, receiverFieldNames); + let fields = ES.ToTemporalYearMonthFields(this, receiverFieldNames); const inputFieldNames = ES.CalendarFields(calendar, ['day']); - const entries = [['day']]; + const inputEntries = [['day']]; // Add extra fields from the calendar at the end inputFieldNames.forEach((fieldName) => { - if (!entries.some(([name]) => name === fieldName)) { - entries.push([fieldName, undefined]); + if (!inputEntries.some(([name]) => name === fieldName)) { + inputEntries.push([fieldName, undefined]); } }); - ObjectAssign(fields, ES.PrepareTemporalFields(item, entries)); - return ES.DateFromFields(calendar, fields, { overflow: 'reject' }); + const inputFields = ES.PrepareTemporalFields(item, inputEntries); + let mergedFields = ES.CalendarMergeFields(calendar, fields, inputFields); + + const mergedFieldNames = [...new Set([...receiverFieldNames, ...inputFieldNames])]; + const mergedEntries = []; + mergedFieldNames.forEach((fieldName) => { + if (!mergedEntries.some(([name]) => name === fieldName)) { + mergedEntries.push([fieldName, undefined]); + } + }); + mergedFields = ES.PrepareTemporalFields(mergedFields, mergedEntries); + return ES.DateFromFields(calendar, mergedFields, { overflow: 'reject' }); } getISOFields() { if (!ES.IsTemporalYearMonth(this)) throw new TypeError('invalid receiver'); diff --git a/polyfill/lib/zoneddatetime.mjs b/polyfill/lib/zoneddatetime.mjs index f89bbf43f3..2396430e3b 100644 --- a/polyfill/lib/zoneddatetime.mjs +++ b/polyfill/lib/zoneddatetime.mjs @@ -226,6 +226,7 @@ export class ZonedDateTime { } let fields = ES.ToTemporalZonedDateTimeFields(this, fieldNames); fields = ES.CalendarMergeFields(calendar, fields, props); + fields = ES.ToTemporalZonedDateTimeFields(fields, fieldNames); let { year, month, diff --git a/spec/plaindate.html b/spec/plaindate.html index a7d40cbf1a..01375ea30d 100644 --- a/spec/plaindate.html +++ b/spec/plaindate.html @@ -386,6 +386,7 @@

Temporal.PlainDate.prototype.with ( _temporalDateLike_ [ , _options_ ] )

diff --git a/spec/plaindatetime.html b/spec/plaindatetime.html index 4086834a04..d00a8b850b 100644 --- a/spec/plaindatetime.html +++ b/spec/plaindatetime.html @@ -388,6 +388,7 @@

Temporal.PlainDateTime.prototype.with ( _temporalDateTimeLike_ [ , _options_ 1. Set _options_ to ? NormalizeOptionsObject(_options_). 1. Let _fields_ be ? PrepareTemporalFields(_dateTime_, _fieldNames_, «»). 1. Set _fields_ to ? CalendarMergeFields(_calendar_, _fields_, _partialDateTime_). + 1. Set _fields_ to ? PrepareTemporalFields(_fields_, _fieldNames_, «»). 1. Let _result_ be ? InterpretTemporalDateTimeFields(_calendar_, _fields_, _options_). 1. Assert: ! ValidateISODateTime(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*. 1. Return ? CreateTemporalDateTime(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]], _calendar_). diff --git a/spec/plainmonthday.html b/spec/plainmonthday.html index 7aed516eec..2e8ac0f945 100644 --- a/spec/plainmonthday.html +++ b/spec/plainmonthday.html @@ -152,6 +152,7 @@

Temporal.PlainMonthDay.prototype.with ( _temporalMonthDayLike_ [ , _options_ 1. Set _options_ to ? NormalizeOptionsObject(_options_). 1. Let _fields_ be ? PrepareTemporalFields(_monthDay_, _fieldNames_, «»). 1. Set _fields_ to ? CalendarMergeFields(_calendar_, _fields_, _partialMonthDay_). + 1. Set _fields_ to ? PrepareTemporalFields(_fields_, _fieldNames_, «»). 1. Return ? MonthDayFromFields(_calendar_, _fields_, _options_). @@ -243,6 +244,8 @@

Temporal.PlainMonthDay.prototype.toPlainDate ( _item_ )

1. Let _inputFieldNames_ be ? CalendarFields(_calendar_, « *"year"* »). 1. Let _inputFields_ be ? PrepareTemporalFields(_item_, _inputFieldNames_, «»). 1. Let _mergedFields_ be ? CalendarMergeFields(_calendar_, _fields_, _inputFields_). + 1. Let _mergedFieldNames_ be the List containing all the elements of _receiverFieldNames_ followed by all the elements of _inputFieldNames_, with duplicate elements removed. + 1. Set _mergedFields_ to ? PrepareTemporalFields(_mergedFields_, _mergedFieldNames_, «»). 1. Let _options_ be ! OrdinaryObjectCreate(%Object.prototype%). 1. Perform ! CreateDataPropertyOrThrow(_options_, *"overflow"*, *"reject"*). 1. Return ? DateFromFields(_calendar_, _mergedFields_, _options_). diff --git a/spec/plainyearmonth.html b/spec/plainyearmonth.html index a7e6450027..d141153eee 100644 --- a/spec/plainyearmonth.html +++ b/spec/plainyearmonth.html @@ -234,6 +234,7 @@

Temporal.PlainYearMonth.prototype.with ( _temporalYearMonthLike_ [ , _option 1. Set _options_ to ? NormalizeOptionsObject(_options_). 1. Let _fields_ be ? PrepareTemporalFields(_yearMonth_, _fieldNames_, «»). 1. Set _fields_ to ? CalendarMergeFields(_calendar_, _fields_, _partialYearMonth_). + 1. Set _fields_ to ? PrepareTemporalFields(_fields_, _fieldNames_, «»). 1. Return ? YearMonthFromFields(_calendar_, _fields_, _options_). @@ -455,6 +456,8 @@

Temporal.PlainYearMonth.prototype.toPlainDate ( _item_ )

1. Let _inputFieldNames_ be ? CalendarFields(_calendar_, « *"day"* »). 1. Let _inputFields_ be ? PrepareTemporalFields(_item_, _inputFieldNames_, «»). 1. Let _mergedFields_ be ? CalendarMergeFields(_calendar_, _fields_, _inputFields_). + 1. Let _mergedFieldNames_ be the List containing all the elements of _receiverFieldNames_ followed by all the elements of _inputFieldNames_, with duplicate elements removed. + 1. Set _mergedFields_ to ? PrepareTemporalFields(_mergedFields_, _mergedFieldNames_, «»). 1. Let _options_ be ! OrdinaryObjectCreate(%Object.prototype%). 1. Perform ! CreateDataPropertyOrThrow(_options_, *"overflow"*, *"reject"*). 1. Return ? DateFromFields(_calendar_, _mergedFields_, _options_). diff --git a/spec/zoneddatetime.html b/spec/zoneddatetime.html index 8b026c94f9..4ad55bece3 100644 --- a/spec/zoneddatetime.html +++ b/spec/zoneddatetime.html @@ -575,6 +575,7 @@

Temporal.ZonedDateTime.prototype.with ( _temporalZonedDateTimeLike_ [ , _opt 1. Append *"timeZone"* to _fieldNames_. 1. Let _fields_ be ? PrepareTemporalFields(_zonedDateTime_, _fieldNames_, « *"timeZone"* »). 1. Set _fields_ to ? CalendarMergeFields(_calendar_, _fields_, _partialZonedDateTime_). + 1. Set _fields_ to ? PrepareTemporalFields(_fields_, _fieldNames_, « *"timeZone"* »). 1. Let _offsetString_ be ? Get(_partialZonedDateTime_, *"offset"*). 1. If _offsetString_ is not *undefined*, then 1. Perform ? Set(_fields_, *"offset"*, _offsetString_).