Skip to content

Commit

Permalink
Normative: Allow ECMAScript code to specify UTC offset time zones
Browse files Browse the repository at this point in the history
Fixes #683
  • Loading branch information
gibson042 authored and ryzokuken committed Sep 27, 2023
1 parent 896ffcc commit af4ec46
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions spec/datetimeformat.html
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,13 @@ <h1>
1. Set _timeZone_ to DefaultTimeZone().
1. Else,
1. Set _timeZone_ to ? ToString(_timeZone_).
1. If the result of IsValidTimeZoneName(_timeZone_) is *false*, then
1. Throw a *RangeError* exception.
1. If IsTimeZoneOffsetString(_timeZone_) is *true*, then
1. Let _offsetNanoseconds_ be ParseTimeZoneOffsetString(_timeZone_).
1. Set _timeZone_ to FormatTimeZoneOffsetString(_offsetNanoseconds_).
1. Else if IsValidTimeZoneName(_timeZone_) is *true*, then
1. Set _timeZone_ to CanonicalizeTimeZoneName(_timeZone_).
1. Else,
1. Throw a *RangeError* exception.
1. Set _dateTimeFormat_.[[TimeZone]] to _timeZone_.
1. Let _formatOptions_ be a new Record.
1. Set _formatOptions_.[[hourCycle]] to _hc_.
Expand Down Expand Up @@ -164,6 +168,31 @@ <h1>
1. Return _dateTimeFormat_.
</emu-alg>
</emu-clause>

<emu-clause id="sec-formattimezoneoffsetstring" aoid="FormatTimeZoneOffsetString">
<h1>FormatTimeZoneOffsetString ( _offsetNanoseconds_ )</h1>
<emu-alg>
1. Assert: _offsetNanoseconds_ is an integer.
1. If _offsetNanoseconds_ &ge; 0, let _sign_ be the code unit 0x002B (PLUS SIGN); otherwise, let _sign_ be the code unit 0x002D (HYPHEN-MINUS).
1. Set _offsetNanoseconds_ to abs(_offsetNanoseconds_).
1. Let _nanoseconds_ be _offsetNanoseconds_ modulo 10<sup>9</sup>.
1. Let _seconds_ be floor(_offsetNanoseconds_ / 10<sup>9</sup>) modulo 60.
1. Let _minutes_ be floor(_offsetNanoseconds_ / (6 &times; 10<sup>10</sup>)) modulo 60.
1. Let _hours_ be floor(_offsetNanoseconds_ / (3.6 &times; 10<sup>12</sup>)).
1. Let _h_ be ToZeroPaddedDecimalString(_hours_, 2).
1. Let _m_ be ToZeroPaddedDecimalString(_minutes_, 2).
1. Let _s_ be ToZeroPaddedDecimalString(_seconds_, 2).
1. If _nanoseconds_ &ne; 0, then
1. Let _fraction_ be ToZeroPaddedDecimalString(_nanoseconds_, 9).
1. Set _fraction_ to the longest possible substring of _fraction_ starting at position 0 and not ending with the code unit 0x0030 (DIGIT ZERO).
1. Let _post_ be the string-concatenation of the code unit 0x003A (COLON), _s_, the code unit 0x002E (FULL STOP), and _fraction_.
1. Else if seconds &ne; 0, then
1. Let _post_ be the string-concatenation of the code unit 0x003A (COLON) and _s_.
1. Else,
1. Let _post_ be the empty String.
1. Return the string-concatenation of _sign_, _h_, the code unit 0x003A (COLON), _m_, and _post_.
</emu-alg>
</emu-clause>
</emu-clause>

<emu-clause id="sec-properties-of-intl-datetimeformat-constructor">
Expand Down

0 comments on commit af4ec46

Please sign in to comment.