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 @@