Skip to content

Commit

Permalink
Fast-path conversion of Temporal.PlainDate to Temporal.PlainDateTime
Browse files Browse the repository at this point in the history
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
  • Loading branch information
ptomato committed Apr 16, 2021
1 parent 35fdc35 commit 88a862c
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 2 additions & 0 deletions spec/plaindatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,8 @@ <h1>ToTemporalDateTime ( _item_ [ , _options_ ] )</h1>
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_, «»).
Expand Down

0 comments on commit 88a862c

Please sign in to comment.