From 88a862c2c198a11c250892120f3fc18a551f2098 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 9 Apr 2021 18:43:00 -0700 Subject: [PATCH] Fast-path conversion of Temporal.PlainDate to Temporal.PlainDateTime If passing a Temporal.PlainDate where a Temporal.PlainDateTime is expected, then create a Temporal.PlainDateTime directly from the PlainDate's [[ISOYear]], [[ISOMonth]], and [[ISODay]] internal slots, and assume midnight as the time, just as if a property bag with year, month/monthCode, and day properties had been passed. Previously, the PlainDate's calendar, year, month, monthCode, and day getters would have been called, and the time properties would have been accessed as well. See: #1428 --- polyfill/lib/ecmascript.mjs | 15 +++++++++++++++ spec/plaindatetime.html | 2 ++ 2 files changed, 17 insertions(+) diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs index d02519dc97..2f4541e15a 100644 --- a/polyfill/lib/ecmascript.mjs +++ b/polyfill/lib/ecmascript.mjs @@ -1186,6 +1186,21 @@ export const ES = ObjectAssign({}, ES2020, { let year, month, day, hour, minute, second, millisecond, microsecond, nanosecond, calendar; if (ES.Type(item) === 'Object') { if (ES.IsTemporalDateTime(item)) return item; + if (ES.IsTemporalDate(item)) { + const TemporalPlainDateTime = GetIntrinsic('%Temporal.PlainDateTime%'); + return new TemporalPlainDateTime( + GetSlot(item, ISO_YEAR), + GetSlot(item, ISO_MONTH), + GetSlot(item, ISO_DAY), + 0, + 0, + 0, + 0, + 0, + 0, + GetSlot(item, CALENDAR) + ); + } calendar = item.calendar; if (calendar === undefined) calendar = ES.GetISO8601Calendar(); diff --git a/spec/plaindatetime.html b/spec/plaindatetime.html index 3697202ee2..d172d41f1b 100644 --- a/spec/plaindatetime.html +++ b/spec/plaindatetime.html @@ -903,6 +903,8 @@

ToTemporalDateTime ( _item_ [ , _options_ ] )

1. If Type(_item_) is Object, then 1. If _item_ has an [[InitializedTemporalDateTime]] internal slot, then 1. Return _item_. + 1. If _item_ has an [[InitializedTemporalDate]] internal slot, then + 1. Return ? CreateTemporalDateTime(_item_.[[ISOYear]], _item_.[[ISOMonth]], _item_.[[ISODay]], 0, 0, 0, 0, 0, 0, _item_.[[Calendar]]). 1. Let _calendar_ be ? GetOptionalTemporalCalendar(_item_). 1. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"day"*, *"hour"*, *"microsecond"*, *"millisecond"*, *"minute"*, *"month"*, *"monthCode"*, *"nanosecond"*, *"second"*, *"year"* »). 1. Let _fields_ be ? PrepareTemporalFields(_item_, _fieldNames_, «»).