From 1a23f2c9f2c044ea0053b064e30bb44a5e200cf0 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Mon, 7 Oct 2024 11:26:34 -0700 Subject: [PATCH] Editorial: Return ISO Date-Time Record from SystemDateTime This avoids creation of an unobservable Temporal.PlainDateTime object, and is also simpler to read. See: #2949 --- polyfill/lib/now.mjs | 15 +++++++++++---- spec/temporal.html | 16 ++++++++-------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/polyfill/lib/now.mjs b/polyfill/lib/now.mjs index 1c5177fa6..e36c56838 100644 --- a/polyfill/lib/now.mjs +++ b/polyfill/lib/now.mjs @@ -2,7 +2,10 @@ import { ObjectDefineProperty, SymbolToStringTag } from './primordials.mjs'; import * as ES from './ecmascript.mjs'; import { GetIntrinsic } from './intrinsicclass.mjs'; -import { GetSlot, ISO_DATE_TIME } from './slots.mjs'; + +function SystemDateTime(timeZone) { + return ES.GetISODateTimeFor(timeZone, ES.SystemUTCEpochNanoSeconds()); +} const instant = () => { const Instant = GetIntrinsic('%Temporal.Instant%'); @@ -10,7 +13,7 @@ const instant = () => { }; const plainDateTimeISO = (temporalTimeZoneLike = ES.DefaultTimeZone()) => { const timeZone = ES.ToTemporalTimeZoneIdentifier(temporalTimeZoneLike); - const isoDateTime = ES.GetISODateTimeFor(timeZone, ES.SystemUTCEpochNanoSeconds()); + const isoDateTime = SystemDateTime(timeZone); return ES.CreateTemporalDateTime(isoDateTime, 'iso8601'); }; const zonedDateTimeISO = (temporalTimeZoneLike = ES.DefaultTimeZone()) => { @@ -18,10 +21,14 @@ const zonedDateTimeISO = (temporalTimeZoneLike = ES.DefaultTimeZone()) => { return ES.CreateTemporalZonedDateTime(ES.SystemUTCEpochNanoSeconds(), timeZone, 'iso8601'); }; const plainDateISO = (temporalTimeZoneLike = ES.DefaultTimeZone()) => { - return ES.CreateTemporalDate(GetSlot(plainDateTimeISO(temporalTimeZoneLike), ISO_DATE_TIME).isoDate, 'iso8601'); + const timeZone = ES.ToTemporalTimeZoneIdentifier(temporalTimeZoneLike); + const isoDateTime = SystemDateTime(timeZone); + return ES.CreateTemporalDate(isoDateTime.isoDate, 'iso8601'); }; const plainTimeISO = (temporalTimeZoneLike = ES.DefaultTimeZone()) => { - return ES.CreateTemporalTime(GetSlot(plainDateTimeISO(temporalTimeZoneLike), ISO_DATE_TIME).time); + const timeZone = ES.ToTemporalTimeZoneIdentifier(temporalTimeZoneLike); + const isoDateTime = SystemDateTime(timeZone); + return ES.CreateTemporalTime(isoDateTime.time); }; const timeZoneId = () => { return ES.DefaultTimeZone(); diff --git a/spec/temporal.html b/spec/temporal.html index 6abd348f6..737c19c23 100644 --- a/spec/temporal.html +++ b/spec/temporal.html @@ -122,7 +122,8 @@

Temporal.Now.instant ( )

Temporal.Now.plainDateTimeISO ( [ _temporalTimeZoneLike_ ] )

This function performs the following steps when called:

- 1. Return ? SystemDateTime(_temporalTimeZoneLike_). + 1. Let _isoDateTime_ be ? SystemDateTime(_temporalTimeZoneLike_). + 1. Return ! CreateTemporalDateTime(_isoDateTime_, *"iso8601"*). @@ -138,8 +139,8 @@

Temporal.Now.zonedDateTimeISO ( [ _temporalTimeZoneLike_ ] )

Temporal.Now.plainDateISO ( [ _temporalTimeZoneLike_ ] )

This function performs the following steps when called:

- 1. Let _dateTime_ be ? SystemDateTime(_temporalTimeZoneLike_). - 1. Return ! CreateTemporalDate(_dateTime_.[[ISODateTime]].[[ISODate]], *"iso8601"*). + 1. Let _isoDateTime_ be ? SystemDateTime(_temporalTimeZoneLike_). + 1. Return ! CreateTemporalDate(_isoDateTime_.[[ISODate]], *"iso8601"*). @@ -147,8 +148,8 @@

Temporal.Now.plainDateISO ( [ _temporalTimeZoneLike_ ] )

Temporal.Now.plainTimeISO ( [ _temporalTimeZoneLike_ ] )

This function performs the following steps when called:

- 1. Let _dateTime_ be ? SystemDateTime(_temporalTimeZoneLike_). - 1. Return ! CreateTemporalTime(_dateTime_.[[ISODateTime]].[[Time]]). + 1. Let _isoDateTime_ be ? SystemDateTime(_temporalTimeZoneLike_). + 1. Return ! CreateTemporalTime(_isoDateTime_.[[Time]]). @@ -230,7 +231,7 @@

SystemInstant ( ): a Temporal.Instant

SystemDateTime ( _temporalTimeZoneLike_: an ECMAScript language value, - ): either a normal completion containing a Temporal.PlainDateTime or a throw completion + ): either a normal completion containing an ISO Date-Time Record or a throw completion

description
@@ -242,8 +243,7 @@

1. Else, 1. Let _timeZone_ be ? ToTemporalTimeZoneIdentifier(_temporalTimeZoneLike_). 1. Let _epochNs_ be SystemUTCEpochNanoseconds(). - 1. Let _isoDateTime_ be GetISODateTimeFor(_timeZone_, _epochNs_). - 1. Return ! CreateTemporalDateTime(_isoDateTime_, *"iso8601"*). + 1. Return GetISODateTimeFor(_timeZone_, _epochNs_).