Skip to content

Commit

Permalink
Polyfill: Align HandleDateTimeTemporalDateTime with spec
Browse files Browse the repository at this point in the history
The spec does not say to create a PlainDateTime with the DateTimeFormat's
calendar here. This is an observable difference from the spec because now
GetInstantFor may call the original PlainDateTime instance's calendar's
dateAdd method, although after #2519 that should no longer be observable.
  • Loading branch information
ptomato committed Aug 25, 2023
1 parent 6af74ee commit b1c699b
Showing 1 changed file with 1 addition and 25 deletions.
26 changes: 1 addition & 25 deletions polyfill/lib/intl.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -412,38 +412,14 @@ function extractOverrides(temporalObj, main) {
}

if (ES.IsTemporalDateTime(temporalObj)) {
const isoYear = GetSlot(temporalObj, ISO_YEAR);
const isoMonth = GetSlot(temporalObj, ISO_MONTH);
const isoDay = GetSlot(temporalObj, ISO_DAY);
const hour = GetSlot(temporalObj, ISO_HOUR);
const minute = GetSlot(temporalObj, ISO_MINUTE);
const second = GetSlot(temporalObj, ISO_SECOND);
const millisecond = GetSlot(temporalObj, ISO_MILLISECOND);
const microsecond = GetSlot(temporalObj, ISO_MICROSECOND);
const nanosecond = GetSlot(temporalObj, ISO_NANOSECOND);
const calendar = ES.ToTemporalCalendarIdentifier(GetSlot(temporalObj, CALENDAR));
if (calendar !== 'iso8601' && calendar !== main[CAL_ID]) {
throw new RangeError(
`cannot format PlainDateTime with calendar ${calendar} in locale with calendar ${main[CAL_ID]}`
);
}
let datetime = temporalObj;
if (calendar === 'iso8601') {
datetime = new DateTime(
isoYear,
isoMonth,
isoDay,
hour,
minute,
second,
millisecond,
microsecond,
nanosecond,
main[CAL_ID]
);
}
return {
instant: ES.GetInstantFor(main[TZ_CANONICAL], datetime, 'compatible'),
instant: ES.GetInstantFor(main[TZ_CANONICAL], temporalObj, 'compatible'),
formatter: getPropLazy(main, DATETIME)
};
}
Expand Down

0 comments on commit b1c699b

Please sign in to comment.