Skip to content

Commit

Permalink
Editorial: Return ISO Date-Time Record from SystemDateTime
Browse files Browse the repository at this point in the history
This avoids creation of an unobservable Temporal.PlainDateTime object, and
is also simpler to read.

See: #2949
  • Loading branch information
ptomato authored and Ms2ger committed Oct 8, 2024
1 parent abb2f2c commit 1a23f2c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
15 changes: 11 additions & 4 deletions polyfill/lib/now.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,33 @@ 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%');
return new Instant(ES.SystemUTCEpochNanoSeconds());
};
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()) => {
const timeZone = ES.ToTemporalTimeZoneIdentifier(temporalTimeZoneLike);
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();
Expand Down
16 changes: 8 additions & 8 deletions spec/temporal.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ <h1>Temporal.Now.instant ( )</h1>
<h1>Temporal.Now.plainDateTimeISO ( [ _temporalTimeZoneLike_ ] )</h1>
<p>This function performs the following steps when called:</p>
<emu-alg>
1. Return ? SystemDateTime(_temporalTimeZoneLike_).
1. Let _isoDateTime_ be ? SystemDateTime(_temporalTimeZoneLike_).
1. Return ! CreateTemporalDateTime(_isoDateTime_, *"iso8601"*).
</emu-alg>
</emu-clause>

Expand All @@ -138,17 +139,17 @@ <h1>Temporal.Now.zonedDateTimeISO ( [ _temporalTimeZoneLike_ ] )</h1>
<h1>Temporal.Now.plainDateISO ( [ _temporalTimeZoneLike_ ] )</h1>
<p>This function performs the following steps when called:</p>
<emu-alg>
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"*).
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal.now.plaintimeiso">
<h1>Temporal.Now.plainTimeISO ( [ _temporalTimeZoneLike_ ] )</h1>
<p>This function performs the following steps when called:</p>
<emu-alg>
1. Let _dateTime_ be ? SystemDateTime(_temporalTimeZoneLike_).
1. Return ! CreateTemporalTime(_dateTime_.[[ISODateTime]].[[Time]]).
1. Let _isoDateTime_ be ? SystemDateTime(_temporalTimeZoneLike_).
1. Return ! CreateTemporalTime(_isoDateTime_.[[Time]]).
</emu-alg>
</emu-clause>
</emu-clause>
Expand Down Expand Up @@ -230,7 +231,7 @@ <h1>SystemInstant ( ): a Temporal.Instant</h1>
<h1>
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
</h1>
<dl class="header">
<dt>description</dt>
Expand All @@ -242,8 +243,7 @@ <h1>
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_).
</emu-alg>
</emu-clause>

Expand Down

0 comments on commit 1a23f2c

Please sign in to comment.