Skip to content

Commit

Permalink
Editorial: Remove dead code from ZonedDateTime.prototype.toLocaleString
Browse files Browse the repository at this point in the history
This removes some steps that can throw and therefore look observable, but
they were effectively dead code; the value stored in the [[TimeZone]]
internal slot is guaranteed to be a valid available time zone identifier.

h/t Anba

Closes: #3057
  • Loading branch information
ptomato authored and Ms2ger committed Dec 11, 2024
1 parent 30d17d3 commit 065cf94
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 15 deletions.
8 changes: 2 additions & 6 deletions polyfill/lib/zoneddatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,10 @@ export class ZonedDateTime {
// The rest of the defaults will be filled in by formatting the Instant
}

const timeZoneIdentifier = GetSlot(this, TIME_ZONE);
if (ES.IsOffsetTimeZoneIdentifier(timeZoneIdentifier)) {
optionsCopy.timeZone = GetSlot(this, TIME_ZONE);
if (ES.IsOffsetTimeZoneIdentifier(optionsCopy.timeZone)) {
// Note: https://github.com/tc39/ecma402/issues/683 will remove this
throw new RangeErrorCtor('toLocaleString does not currently support offset time zones');
} else {
const record = ES.GetAvailableNamedTimeZoneIdentifier(timeZoneIdentifier);
if (!record) throw new RangeErrorCtor(`toLocaleString formats built-in time zones, not ${timeZoneIdentifier}`);
optionsCopy.timeZone = record.identifier;
}

const formatter = new DateTimeFormat(locales, optionsCopy);
Expand Down
10 changes: 1 addition & 9 deletions spec/intl.html
Original file line number Diff line number Diff line change
Expand Up @@ -1782,15 +1782,7 @@ <h1>Temporal.ZonedDateTime.prototype.toLocaleString ( [ _locales_ [ , _options_
<emu-alg>
1. Let _zonedDateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_zonedDateTime_, [[InitializedTemporalZonedDateTime]]).
1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]].
1. Let _timeZoneParseResult_ be ? ParseTimeZoneIdentifier(_timeZone_).
1. If _timeZoneParseResult_.[[OffsetMinutes]] is ~empty~, then
1. Let _timeZoneIdentifierRecord_ be GetAvailableNamedTimeZoneIdentifier(_timeZone_).
1. If _timeZoneIdentifierRecord_ is ~empty~, throw a *RangeError* exception.
1. Set _timeZone_ to _timeZoneIdentifierRecord_.[[Identifier]].
1. Else,
1. Set _timeZone_ to FormatOffsetTimeZoneIdentifier(_timeZoneParseResult_.[[OffsetMinutes]]).
1. Let _dateTimeFormat_ be ? CreateDateTimeFormat(%Intl.DateTimeFormat%, _locales_, _options_, ~any~, ~all~, _timeZone_).
1. Let _dateTimeFormat_ be ? CreateDateTimeFormat(%Intl.DateTimeFormat%, _locales_, _options_, ~any~, ~all~, _zonedDateTime_.[[TimeZone]]).
1. If _zonedDateTime_.[[Calendar]] is not *"iso8601"* and CalendarEquals(_zonedDateTime_.[[Calendar]], _dateTimeFormat_.[[Calendar]]) is *false*, then
1. Throw a *RangeError* exception.
1. Let _instant_ be ! CreateTemporalInstant(_zonedDateTime_.[[EpochNanoseconds]]).
Expand Down

0 comments on commit 065cf94

Please sign in to comment.