You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This editorial commit removes redundant spec text dealing with time
formatting:
* Adds a new AO FormatTimeString, and calls it in TemporalTimeToString,
TemporalDateTimeToString, and TimeString (the legacy date AO in 262).
* Removes FormatSecondsStringPart and replaces it with a new AO
FormatFractionalSeconds, and call it in FormatTimeString and
TemporalDurationToString. The text of this new AO is aligned with
similar text in GetOffsetStringFor in #2607.
* Replaces sub-second formatting text in TemporalDurationToString
with a call to FormatFractionalSeconds.
* Aligns polyfill code to these spec changes.
* Adjusts polyfill code in a few places to better match the spec.
Note that this commit doesn't touch spec text for formatting time zone
offsets because there are several in-flight PRs dealing with offsets
and I wanted to keep this PR merge-conflict-free. But once those
PRs land and the dust settles, then I'll send another editorial PR to
DRY offset string formatting too, by using FormatTimeString to replace
bespoke formatting text for offsets.
_precision_: either an integer in the inclusive range 0 to 9 or *"auto"*
688
+
): a String
689
+
</h1>
690
+
<dlclass="header">
691
+
<dt>description</dt>
692
+
<dd>
693
+
If _precision_ is zero, or if _precision_ is *"auto"* and _subSecondNanoseconds_ is zero, then an empty String will be returned.
694
+
Otherwise, the output will be a decimal point followed by a sequence of fractional seconds digits, truncated to _precision_ digits or (if _precision_ is *"auto"*) to the last non-zero digit.
695
+
</dd>
696
+
</dl>
685
697
<emu-alg>
686
-
1.Assert:_second_, _millisecond_, _microsecond_, and _nanosecond_ are integers.
687
-
1. If _precision_ is *"minute"*, return *""*.
688
-
1. Let _secondsString_ be the string-concatenation of the code unit 0x003A (COLON) and ToZeroPaddedDecimalString(_second_, 2).
689
-
1. Let _fraction_ be _millisecond_× 10<sup>6</sup> + _microsecond_× 10<sup>3</sup> + _nanosecond_.
690
698
1. If _precision_ is *"auto"*, then
691
-
1. If _fraction_ is 0, return _secondsString_.
692
-
1.Set _fraction_ to ToZeroPaddedDecimalString(_fraction_, 9).
693
-
1. Set _fraction_ to the longest possible substring of _fraction_ starting at position 0 and not ending with the code unit 0x0030 (DIGIT ZERO).
699
+
1. If _subSecondNanoseconds_ is 0, return the empty String.
700
+
1.Let _fractionString_ be ToZeroPaddedDecimalString(_subSecondNanoseconds_, 9).
701
+
1. Set _fractionString_ to the longest prefix of _fractionString_ending with a code unit other than 0x0030 (DIGIT ZERO).
694
702
1. Else,
695
-
1. If _precision_ is 0, return _secondsString_.
696
-
1. Set _fraction_ to ToZeroPaddedDecimalString(_fraction_, 9).
697
-
1. Set _fraction_ to the substring of _fraction_ from 0 to _precision_.
698
-
1. Return the string-concatenation of _secondsString_, the code unit 0x002E (FULL STOP), and _fraction_.
703
+
1. If _precision_ is 0, return the empty String.
704
+
1. Let _fractionString_ be ToZeroPaddedDecimalString(_subSecondNanoseconds_, 9).
705
+
1. Set _fractionString_ to the substring of _fractionString_ from 0 to _precision_.
706
+
1. Return the string-concatenation of the code unit 0x002E (FULL STOP) and _fractionString_.
_precision_: an integer in the inclusive range 0 to 9, *"minute"*, or *"auto"*
718
+
): a String
719
+
</h1>
720
+
<dlclass="header">
721
+
<dt>description</dt>
722
+
<dd>
723
+
The output will be formatted like ±HH:MM if _precision_ is *"minute"*.
724
+
Otherwise, the output will be formatted like ±HH:MM:SS if _precision_ is zero, or if _subSecondNanoseconds_ is zero and _precision is *"auto"*.
725
+
Otherwise, the output will be formatted like ±HH:MM:SS.fff where "fff" is a sequence of fractional seconds digits, truncated to _precision_ digits or (if _precision_ is *"auto"*) to the last non-zero digit.
726
+
</dd>
727
+
</dl>
728
+
<emu-alg>
729
+
1. Let _hh_ be ToZeroPaddedDecimalString(_hour_, 2).
730
+
1. Let _mm_ be ToZeroPaddedDecimalString(_minute_, 2).
731
+
1. Let _result_ be the string-concatenation of _hh_, the code unit 0x003A (COLON), and _mm_.
732
+
1. If _precision_ is *"minute"*, return _result_.
733
+
1. Let _ss_ be ToZeroPaddedDecimalString(_second_, 2).
734
+
1. Let _subSecondsPart_ be FormatFractionalSeconds(_subSecondNanoseconds_, _precision_).
735
+
1. Set _result_ to the string-concatenation of _result_, the code unit 0x003A (COLON), _ss_, and _subSecondsPart_.
1.Assert:_isoYear_, _isoMonth_, _isoDay_, _hour_, _minute_, _second_, _millisecond_, _microsecond_, and _nanosecond_ are integers.
996
-
1. Let _year_ be ! PadISOYear(_isoYear_).
997
-
1. Let _month_ be ToZeroPaddedDecimalString(_isoMonth_, 2).
998
-
1. Let _day_ be ToZeroPaddedDecimalString(_isoDay_, 2).
999
-
1. Let _hour_ be ToZeroPaddedDecimalString(_hour_, 2).
1000
-
1. Let _minute_ be ToZeroPaddedDecimalString(_minute_, 2).
1001
-
1. Let _seconds_ be ! FormatSecondsStringPart(_second_, _millisecond_, _microsecond_, _nanosecond_, _precision_).
996
+
1. Let _yearString_ be PadISOYear(_isoYear_).
997
+
1. Let _monthString_ be ToZeroPaddedDecimalString(_isoMonth_, 2).
998
+
1. Let _dayString_ be ToZeroPaddedDecimalString(_isoDay_, 2).
999
+
1. Let _subSecondNanoseconds_ be _millisecond_× 10<sup>6</sup> + _microsecond_× 10<sup>3</sup> + _nanosecond_.
1000
+
1. Let _timeString_ be FormatTimeString(_hour_, _minute_, _second_, _subSecondNanoseconds_, _precision_).
1002
1001
1. Let _calendarString_ be ? MaybeFormatCalendarAnnotation(_calendar_, _showCalendar_).
1003
-
1. Return the string-concatenation of _year_, the code unit 0x002D (HYPHEN-MINUS), _month_, the code unit 0x002D (HYPHEN-MINUS), _day_, 0x0054 (LATIN CAPITAL LETTER T), _hour_, the code unit 0x003A (COLON), _minute_, _seconds_, and _calendarString_.
1002
+
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_.
0 commit comments