Skip to content

Commit

Permalink
Editorial: Use ISO Date-Time Record in TemporalDateTimeToString, and …
Browse files Browse the repository at this point in the history
…rename

Instead of passing each component individually, pass an ISO Date-Time
Record. The name is no longer really appropriate, since we are not passing
a Temporal object, so rename it to ISODateTimeToString.

See: #2949
  • Loading branch information
ptomato authored and Ms2ger committed Oct 8, 2024
1 parent 45f82f9 commit 991d882
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 31 deletions.
10 changes: 5 additions & 5 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1603,7 +1603,7 @@ export function InterpretISODateTimeOffset(
// zone and date/time.
if (offsetOpt === 'reject') {
const offsetStr = FormatUTCOffsetNanoseconds(offsetNs);
const dtStr = TemporalDateTimeToString(dt, 'iso8601', 'auto');
const dtStr = ISODateTimeToString(dt, 'iso8601', 'auto');
throw new RangeErrorCtor(`Offset ${offsetStr} is invalid for ${dtStr} in ${timeZone}`);
}
// fall through: offsetOpt === 'prefer', but the offset doesn't match
Expand Down Expand Up @@ -1738,7 +1738,7 @@ export function CreateTemporalDateTimeSlots(result, isoYear, isoMonth, isoDay, h
SetSlot(result, CALENDAR, calendar);

if (typeof __debug__ !== 'undefined' && __debug__) {
let repr = TemporalDateTimeToString(iso, calendar, 'auto');
let repr = ISODateTimeToString(iso, calendar, 'auto');
ObjectDefineProperty(result, '_repr_', {
value: `Temporal.PlainDateTime <${repr}>`,
writable: false,
Expand Down Expand Up @@ -2183,7 +2183,7 @@ export function TemporalInstantToString(instant, timeZone, precision) {
if (outputTimeZone === undefined) outputTimeZone = 'UTC';
const epochNs = GetSlot(instant, EPOCHNANOSECONDS);
const iso = GetISODateTimeFor(outputTimeZone, epochNs);
const dateTimeString = TemporalDateTimeToString(iso, 'iso8601', precision, 'never');
const dateTimeString = ISODateTimeToString(iso, 'iso8601', precision, 'never');
let timeZoneString = 'Z';
if (timeZone !== undefined) {
const offsetNs = GetOffsetNanosecondsFor(outputTimeZone, epochNs);
Expand Down Expand Up @@ -2257,7 +2257,7 @@ export function TimeRecordToString({ hour, minute, second, millisecond, microsec
return FormatTimeString(hour, minute, second, subSecondNanoseconds, precision);
}

export function TemporalDateTimeToString(isoDateTime, calendar, precision, showCalendar = 'auto') {
export function ISODateTimeToString(isoDateTime, calendar, precision, showCalendar = 'auto') {
let { year, month, day, hour, minute, second, millisecond, microsecond, nanosecond } = isoDateTime;
const yearString = ISOYearString(year);
const monthString = ISODateTimePartString(month);
Expand Down Expand Up @@ -2314,7 +2314,7 @@ export function TemporalZonedDateTimeToString(
const tz = GetSlot(zdt, TIME_ZONE);
const offsetNs = GetOffsetNanosecondsFor(tz, epochNs);
const iso = GetISODateTimeFor(tz, epochNs);
let dateTimeString = TemporalDateTimeToString(iso, 'iso8601', precision, 'never');
let dateTimeString = ISODateTimeToString(iso, 'iso8601', precision, 'never');
if (showOffset !== 'never') {
dateTimeString += FormatDateTimeUTCOffsetRounded(offsetNs);
}
Expand Down
2 changes: 1 addition & 1 deletion polyfill/lib/instant.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Instant {

if (typeof __debug__ !== 'undefined' && __debug__) {
const iso = ES.GetISOPartsFromEpoch(ns);
const repr = ES.TemporalDateTimeToString(iso, 'iso8601', 'auto', 'never') + 'Z';
const repr = ES.ISODateTimeToString(iso, 'iso8601', 'auto', 'never') + 'Z';
ObjectDefineProperty(this, '_repr_', {
value: `${this[SymbolToStringTag]} <${repr}>`,
writable: false,
Expand Down
4 changes: 2 additions & 2 deletions polyfill/lib/plaindatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ export class PlainDateTime {
const { precision, unit, increment } = ES.ToSecondsStringPrecisionRecord(smallestUnit, digits);
const result = ES.RoundISODateTime(ES.PlainDateTimeToISODateTimeRecord(this), increment, unit, roundingMode);
ES.RejectDateTimeRange(result);
return ES.TemporalDateTimeToString(result, GetSlot(this, CALENDAR), precision, showCalendar);
return ES.ISODateTimeToString(result, GetSlot(this, CALENDAR), precision, showCalendar);
}
toJSON() {
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
Expand All @@ -371,7 +371,7 @@ export class PlainDateTime {
microsecond: GetSlot(this, ISO_MICROSECOND),
nanosecond: GetSlot(this, ISO_NANOSECOND)
};
return ES.TemporalDateTimeToString(isoDateTime, GetSlot(this, CALENDAR), 'auto');
return ES.ISODateTimeToString(isoDateTime, GetSlot(this, CALENDAR), 'auto');
}
toLocaleString(locales = undefined, options = undefined) {
if (!ES.IsTemporalDateTime(this)) throw new TypeErrorCtor('invalid receiver');
Expand Down
2 changes: 1 addition & 1 deletion spec/instant.html
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ <h1>
1. If _outputTimeZone_ is *undefined*, set _outputTimeZone_ to *"UTC"*.
1. Let _epochNs_ be _instant_.[[EpochNanoseconds]].
1. Let _isoDateTime_ be GetISODateTimeFor(_outputTimeZone_, _epochNs_).
1. Let _dateTimeString_ be TemporalDateTimeToString(_isoDateTime_.[[Year]], _isoDateTime_.[[Month]], _isoDateTime_.[[Day]], _isoDateTime_.[[Hour]], _isoDateTime_.[[Minute]], _isoDateTime_.[[Second]], _isoDateTime_.[[Millisecond]], _isoDateTime_.[[Microsecond]], _isoDateTime_.[[Nanosecond]], *"iso8601"*, _precision_, ~never~).
1. Let _dateTimeString_ be ISODateTimeToString(_isoDateTime_, *"iso8601"*, _precision_, ~never~).
1. If _timeZone_ is *undefined*, then
1. Let _timeZoneString_ be *"Z"*.
1. Else,
Expand Down
35 changes: 14 additions & 21 deletions spec/plaindatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ <h1>Temporal.PlainDateTime.prototype.toString ( [ _options_ ] )</h1>
1. Let _isoDateTime_ be PlainDateTimeToISODateTimeRecord(_dateTime_).
1. Let _result_ be RoundISODateTime(_isoDateTime_, _precision_.[[Increment]], _precision_.[[Unit]], _roundingMode_).
1. If ISODateTimeWithinLimits(_result_) is *false*, throw a *RangeError* exception.
1. Return TemporalDateTimeToString(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]], _dateTime_.[[Calendar]], _precision_.[[Precision]], _showCalendar_).
1. Return ISODateTimeToString(_result_, _dateTime_.[[Calendar]], _precision_.[[Precision]], _showCalendar_).
</emu-alg>
</emu-clause>

Expand All @@ -576,7 +576,8 @@ <h1>Temporal.PlainDateTime.prototype.toLocaleString ( [ _locales_ [ , _options_
<emu-alg>
1. Let _dateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_dateTime_, [[InitializedTemporalDateTime]]).
1. Return TemporalDateTimeToString(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _dateTime_.[[Calendar]], ~auto~, ~auto~).
1. Let _isoDateTime_ be PlainDateTimeToISODateTimeRecord(_dateTime_).
1. Return ISODateTimeToString(_isoDateTime_, _dateTime_.[[Calendar]], ~auto~, ~auto~).
</emu-alg>
</emu-clause>

Expand All @@ -586,7 +587,8 @@ <h1>Temporal.PlainDateTime.prototype.toJSON ( )</h1>
<emu-alg>
1. Let _dateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_dateTime_, [[InitializedTemporalDateTime]]).
1. Return TemporalDateTimeToString(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _dateTime_.[[Calendar]], ~auto~, ~auto~).
1. Let _isoDateTime_ be PlainDateTimeToISODateTimeRecord(_dateTime_).
1. Return ISODateTimeToString(_isoDateTime_, _dateTime_.[[Calendar]], ~auto~, ~auto~).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -1015,34 +1017,25 @@ <h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-temporaldatetimetostring" type="abstract operation">
<emu-clause id="sec-temporal-isodatetimetostring" type="abstract operation">
<h1>
TemporalDateTimeToString (
_isoYear_: an integer,
_isoMonth_: an integer,
_isoDay_: an integer,
_hour_: an integer in the inclusive interval from 0 to 23,
_minute_: an integer in the inclusive interval from 0 to 59,
_second_: an integer in the inclusive interval from 0 to 59,
_millisecond_: an integer in the inclusive interval from 0 to 999,
_microsecond_: an integer in the inclusive interval from 0 to 999,
_nanosecond_: an integer in the inclusive interval from 0 to 999,
ISODateTimeToString (
_isoDateTime_: an ISO Date-Time Record,
_calendar_: a calendar type,
_precision_: an integer in the inclusive interval from 0 to 9, ~minute~, or ~auto~,
_showCalendar_: ~auto~, ~always~, ~never~, or ~critical~,
): a String
</h1>
<dl class="header">
<dt>description</dt>
<dd>It formats the internal slots of a Temporal.PlainDateTime into an ISO 8601 string, to the precision specified by _precision_.</dd>
<dd>It formats an ISO Date-Time Record into an ISO 8601 string, to the precision specified by _precision_.</dd>
</dl>
<emu-alg>
1. Assert: IsValidISODate(_isoYear_, _isoMonth_, _isoDay_) is *true*.
1. Let _yearString_ be PadISOYear(_isoYear_).
1. Let _monthString_ be ToZeroPaddedDecimalString(_isoMonth_, 2).
1. Let _dayString_ be ToZeroPaddedDecimalString(_isoDay_, 2).
1. Let _subSecondNanoseconds_ be _millisecond_ × 10<sup>6</sup> + _microsecond_ × 10<sup>3</sup> + _nanosecond_.
1. Let _timeString_ be FormatTimeString(_hour_, _minute_, _second_, _subSecondNanoseconds_, _precision_).
1. Let _yearString_ be PadISOYear(_isoDateTime_.[[Year]]).
1. Let _monthString_ be ToZeroPaddedDecimalString(_isoDateTime_.[[Month]], 2).
1. Let _dayString_ be ToZeroPaddedDecimalString(_isoDateTime_.[[Day]], 2).
1. Let _subSecondNanoseconds_ be _isoDateTime_.[[Millisecond]] × 10<sup>6</sup> + _isoDateTime_.[[Microsecond]] × 10<sup>3</sup> + _isoDateTime_.[[Nanosecond]].
1. Let _timeString_ be FormatTimeString(_isoDateTime_.[[Hour]], _isoDateTime_.[[Minute]], _isoDateTime_.[[Second]], _subSecondNanoseconds_, _precision_).
1. Let _calendarString_ be FormatCalendarAnnotation(_calendar_, _showCalendar_).
1. Return the string-concatenation of _yearString_, the code unit 0x002D (HYPHEN-MINUS), _monthString_, the code unit 0x002D (HYPHEN-MINUS), _dayString_, 0x0054 (LATIN CAPITAL LETTER T), _timeString_, and _calendarString_.
</emu-alg>
Expand Down
2 changes: 1 addition & 1 deletion spec/zoneddatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ <h1>
1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]].
1. Let _offsetNanoseconds_ be GetOffsetNanosecondsFor(_timeZone_, _epochNs_).
1. Let _isoDateTime_ be GetISODateTimeFor(_timeZone_, _epochNs_).
1. Let _dateTimeString_ be TemporalDateTimeToString(_isoDateTime_.[[Year]], _isoDateTime_.[[Month]], _isoDateTime_.[[Day]], _isoDateTime_.[[Hour]], _isoDateTime_.[[Minute]], _isoDateTime_.[[Second]], _isoDateTime_.[[Millisecond]], _isoDateTime_.[[Microsecond]], _isoDateTime_.[[Nanosecond]], *"iso8601"*, _precision_, ~never~).
1. Let _dateTimeString_ be ISODateTimeToString(_isoDateTime_, *"iso8601"*, _precision_, ~never~).
1. If _showOffset_ is ~never~, then
1. Let _offsetString_ be the empty String.
1. Else,
Expand Down

0 comments on commit 991d882

Please sign in to comment.