Skip to content

Commit 514e7ad

Browse files
committed
Normative: Temporal stage 4
1 parent cf526eb commit 514e7ad

File tree

6 files changed

+610
-591
lines changed

6 files changed

+610
-591
lines changed

spec/datetimeformat.html

Lines changed: 456 additions & 90 deletions
Large diffs are not rendered by default.

spec/durationformat.html

Lines changed: 17 additions & 208 deletions
Original file line numberDiff line numberDiff line change
@@ -308,15 +308,15 @@ <h1>Intl.DurationFormat.prototype.resolvedOptions ( )</h1>
308308
</emu-clause>
309309

310310
<emu-clause id="sec-Intl.DurationFormat.prototype.format">
311-
<h1>Intl.DurationFormat.prototype.format ( _duration_ )</h1>
311+
<h1>Intl.DurationFormat.prototype.format ( _durationLike_ )</h1>
312312

313-
<p>When the `format` method is called with an argument _duration_, the following steps are taken:</p>
313+
<p>When the `format` method is called with an argument _durationLike_, the following steps are taken:</p>
314314

315315
<emu-alg>
316316
1. Let _df_ be the *this* value.
317317
1. Perform ? RequireInternalSlot(_df_, [[InitializedDurationFormat]]).
318-
1. Let _record_ be ? ToDurationRecord(_duration_).
319-
1. Let _parts_ be PartitionDurationFormatPattern(_df_, _record_).
318+
1. Let _duration_ be ? ToTemporalDuration(_durationLike_).
319+
1. Let _parts_ be PartitionDurationFormatPattern(_df_, _duration_).
320320
1. Let _result_ be the empty String.
321321
1. For each Record { [[Type]], [[Value]], [[Unit]] } _part_ in _parts_, do
322322
1. Set _result_ to the string-concatenation of _result_ and _part_.[[Value]].
@@ -325,15 +325,15 @@ <h1>Intl.DurationFormat.prototype.format ( _duration_ )</h1>
325325
</emu-clause>
326326

327327
<emu-clause id="sec-Intl.DurationFormat.prototype.formatToParts">
328-
<h1>Intl.DurationFormat.prototype.formatToParts ( _duration_ )</h1>
328+
<h1>Intl.DurationFormat.prototype.formatToParts ( _durationLike_ )</h1>
329329

330-
<p>When the `formatToParts` method is called with an argument _duration_, the following steps are taken:</p>
330+
<p>When the `formatToParts` method is called with an argument _durationLike_, the following steps are taken:</p>
331331

332332
<emu-alg>
333333
1. Let _df_ be the *this* value.
334334
1. Perform ? RequireInternalSlot(_df_, [[InitializedDurationFormat]]).
335-
1. Let _record_ be ? ToDurationRecord(_duration_).
336-
1. Let _parts_ be PartitionDurationFormatPattern(_df_, _record_).
335+
1. Let _duration_ be ? ToTemporalDuration(_durationLike_).
336+
1. Let _parts_ be PartitionDurationFormatPattern(_df_, _duration_).
337337
1. Let _result_ be ! ArrayCreate(0).
338338
1. Let _n_ be 0.
339339
1. For each Record { [[Type]], [[Value]], [[Unit]] } _part_ in _parts_, do
@@ -385,197 +385,6 @@ <h1>Properties of Intl.DurationFormat Instances</h1>
385385
<emu-clause id="sec-intl-durationformat-abstracts">
386386
<h1>Abstract Operations for DurationFormat Objects</h1>
387387

388-
<emu-clause id="sec-duration-records">
389-
<h1>Duration Records</h1>
390-
<p>A <dfn variants="Duration Records">Duration Record</dfn> is a Record value used to represent a Duration.</p>
391-
<p>Duration Records have the fields listed in <emu-xref href="#table-duration-record-fields"></emu-xref></p>
392-
<emu-table id="table-duration-record-fields" caption="Duration Record Fields">
393-
<table class="real-table">
394-
<tr>
395-
<th>Field</th>
396-
<th>Meaning</th>
397-
</tr>
398-
<tr>
399-
<td>[[Years]]</td>
400-
<td>
401-
The number of years in the duration.
402-
</td>
403-
</tr>
404-
<tr>
405-
<td>[[Months]]</td>
406-
<td>
407-
The number of months in the duration.
408-
</td>
409-
</tr>
410-
<tr>
411-
<td>[[Weeks]]</td>
412-
<td>
413-
The number of weeks in the duration.
414-
</td>
415-
</tr>
416-
<tr>
417-
<td>[[Days]]</td>
418-
<td>
419-
The number of days in the duration.
420-
</td>
421-
</tr>
422-
<tr>
423-
<td>[[Hours]]</td>
424-
<td>
425-
The number of hours in the duration.
426-
</td>
427-
</tr>
428-
<tr>
429-
<td>[[Minutes]]</td>
430-
<td>
431-
The number of minutes in the duration.
432-
</td>
433-
</tr>
434-
<tr>
435-
<td>[[Seconds]]</td>
436-
<td>
437-
The number of seconds in the duration.
438-
</td>
439-
</tr>
440-
<tr>
441-
<td>[[Milliseconds]]</td>
442-
<td>
443-
The number of milliseconds in the duration.
444-
</td>
445-
</tr>
446-
<tr>
447-
<td>[[Microseconds]]</td>
448-
<td>
449-
The number of microseconds in the duration.
450-
</td>
451-
</tr>
452-
<tr>
453-
<td>[[Nanoseconds]]</td>
454-
<td>
455-
The number of nanoseconds in the duration.
456-
</td>
457-
</tr>
458-
</table>
459-
</emu-table>
460-
</emu-clause>
461-
462-
<emu-clause id="sec-tointegerifintegral" oldids="sec-tointegerwithoutrounding" type="abstract operation">
463-
<h1>
464-
ToIntegerIfIntegral (
465-
_argument_: an ECMAScript language value,
466-
): either a normal completion containing an integer, or a throw completion
467-
</h1>
468-
<dl class="header">
469-
<dt>description</dt>
470-
<dd>It converts _argument_ to an integer representing its Number value, or throws a *RangeError* when that value is not <emu-xref href="#integral-number">integral</emu-xref>.</dd>
471-
</dl>
472-
<emu-alg>
473-
1. Let _number_ be ? ToNumber(_argument_).
474-
1. If _number_ is not an integral Number, throw a *RangeError* exception.
475-
1. Return ℝ(_number_).
476-
</emu-alg>
477-
</emu-clause>
478-
479-
<emu-clause id="sec-todurationrecord" type="abstract operation">
480-
<h1>
481-
ToDurationRecord (
482-
_input_: an ECMAScript language value,
483-
): either a normal completion containing a Duration Record, or a throw completion
484-
</h1>
485-
<dl class="header">
486-
<dt>description</dt>
487-
<dd>It converts a given object that represents a Duration into a Duration Record.</dd>
488-
</dl>
489-
490-
<emu-alg>
491-
1. If _input_ is not an Object, then
492-
1. If _input_ is a String, throw a *RangeError* exception.
493-
1. Throw a *TypeError* exception.
494-
1. Let _result_ be a new Duration Record with each field set to 0.
495-
1. Let _days_ be ? Get(_input_, *"days"*).
496-
1. If _days_ is not *undefined*, set _result_.[[Days]] to ? ToIntegerIfIntegral(_days_).
497-
1. Let _hours_ be ? Get(_input_, *"hours"*).
498-
1. If _hours_ is not *undefined*, set _result_.[[Hours]] to ? ToIntegerIfIntegral(_hours_).
499-
1. Let _microseconds_ be ? Get(_input_, *"microseconds"*).
500-
1. If _microseconds_ is not *undefined*, set _result_.[[Microseconds]] to ? ToIntegerIfIntegral(_microseconds_).
501-
1. Let _milliseconds_ be ? Get(_input_, *"milliseconds"*).
502-
1. If _milliseconds_ is not *undefined*, set _result_.[[Milliseconds]] to ? ToIntegerIfIntegral(_milliseconds_).
503-
1. Let _minutes_ be ? Get(_input_, *"minutes"*).
504-
1. If _minutes_ is not *undefined*, set _result_.[[Minutes]] to ? ToIntegerIfIntegral(_minutes_).
505-
1. Let _months_ be ? Get(_input_, *"months"*).
506-
1. If _months_ is not *undefined*, set _result_.[[Months]] to ? ToIntegerIfIntegral(_months_).
507-
1. Let _nanoseconds_ be ? Get(_input_, *"nanoseconds"*).
508-
1. If _nanoseconds_ is not *undefined*, set _result_.[[Nanoseconds]] to ? ToIntegerIfIntegral(_nanoseconds_).
509-
1. Let _seconds_ be ? Get(_input_, *"seconds"*).
510-
1. If _seconds_ is not *undefined*, set _result_.[[Seconds]] to ? ToIntegerIfIntegral(_seconds_).
511-
1. Let _weeks_ be ? Get(_input_, *"weeks"*).
512-
1. If _weeks_ is not *undefined*, set _result_.[[Weeks]] to ? ToIntegerIfIntegral(_weeks_).
513-
1. Let _years_ be ? Get(_input_, *"years"*).
514-
1. If _years_ is not *undefined*, set _result_.[[Years]] to ? ToIntegerIfIntegral(_years_).
515-
1. If _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, and _nanoseconds_ are all *undefined*, throw a *TypeError* exception.
516-
1. If IsValidDuration( _result_.[[Years]], _result_.[[Months]], _result_.[[Weeks]], _result_.[[Days]], _result_.[[Hours]], _result_.[[Minutes]], _result_.[[Seconds]], _result_.[[Milliseconds]], _result_.[[Microseconds]], _result_.[[Nanoseconds]]) is *false*, then
517-
1. Throw a *RangeError* exception.
518-
1. Return _result_.
519-
</emu-alg>
520-
</emu-clause>
521-
522-
<emu-clause id="sec-durationsign" type="abstract operation">
523-
<h1>
524-
DurationSign (
525-
_duration_: a Duration Record,
526-
): -1, 0, or 1
527-
</h1>
528-
<dl class="header">
529-
<dt>description</dt>
530-
<dd>It returns 1 if the most significant non-zero field in the _duration_ argument is positive, and -1 if the most significant non-zero field is negative. If all of _duration_'s fields are zero, it returns 0.</dd>
531-
</dl>
532-
<emu-alg>
533-
1. For each value _v_ of « _duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]] », do
534-
1. If _v_ &lt; 0, return -1.
535-
1. If _v_ > 0, return 1.
536-
1. Return 0.
537-
</emu-alg>
538-
</emu-clause>
539-
540-
<emu-clause id="sec-isvalidduration" type="abstract operation">
541-
<h1>
542-
IsValidDuration (
543-
_years_: an integer,
544-
_months_: an integer,
545-
_weeks_: an integer,
546-
_days_: an integer,
547-
_hours_: an integer,
548-
_minutes_: an integer,
549-
_seconds_: an integer,
550-
_milliseconds_: an integer,
551-
_microseconds_: an integer,
552-
_nanoseconds_: an integer,
553-
): a Boolean
554-
</h1>
555-
<dl class="header">
556-
<dt>description</dt>
557-
<dd>It returns *true* if its arguments form valid input from which to construct a Duration Record, and *false* otherwise.</dd>
558-
</dl>
559-
<emu-alg>
560-
1. Let _sign_ be 0.
561-
1. For each value _v_ of « _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, _nanoseconds_ », do
562-
1. If 𝔽(_v_) is not finite, return *false*.
563-
1. If _v_ &lt; 0, then
564-
1. If _sign_ > 0, return *false*.
565-
1. Set _sign_ to -1.
566-
1. Else if _v_ > 0, then
567-
1. If _sign_ &lt; 0, return *false*.
568-
1. Set _sign_ to 1.
569-
1. If abs(_years_) ≥ 2<sup>32</sup>, return *false*.
570-
1. If abs(_months_) ≥ 2<sup>32</sup>, return *false*.
571-
1. If abs(_weeks_) ≥ 2<sup>32</sup>, return *false*.
572-
1. Let _normalizedSeconds_ be _days_ × 86,400 + _hours_ × 3600 + _minutes_ × 60 + _seconds_ + ℝ(𝔽(_milliseconds_)) × 10<sup>-3</sup> + ℝ(𝔽(_microseconds_)) × 10<sup>-6</sup> + ℝ(𝔽(_nanoseconds_)) × 10<sup>-9</sup>.
573-
1. NOTE: The above step cannot be implemented directly using floating-point arithmetic. Multiplying by 10<sup>-3</sup>, 10<sup>-6</sup>, and 10<sup>-9</sup> respectively may be imprecise when _milliseconds_, _microseconds_, or _nanoseconds_ is an unsafe integer. This multiplication can be implemented in C++ with an implementation of `std::remquo()` with sufficient bits in the quotient. String manipulation will also give an exact result, since the multiplication is by a power of 10.
574-
1. If abs(_normalizedSeconds_) ≥ 2<sup>53</sup>, return *false*.
575-
1. Return *true*.
576-
</emu-alg>
577-
</emu-clause>
578-
579388
<emu-clause id="sec-getdurationunitoptions" type="abstract operation">
580389
<h1>
581390
GetDurationUnitOptions (
@@ -667,7 +476,7 @@ <h1>
667476
<h1>
668477
ComputeFractionalDigits (
669478
_durationFormat_: a DurationFormat Object,
670-
_duration_: a Duration Record,
479+
_duration_: a Temporal.Duration,
671480
): a mathematical value
672481
</h1>
673482
<dl class="header">
@@ -679,11 +488,11 @@ <h1>
679488
1. Let _result_ be 0.
680489
1. Let _exponent_ be 3.
681490
1. For each row of <emu-xref href="#table-partition-duration-format-pattern"></emu-xref>, except the header row, in table order, do
682-
1. Let _unitOptions_ be the value of _durationFormat_'s internal slot whose name is the Internal Slot value of the current row.
491+
1. Let _unitOptions_ be the value of _durationFormat_'s internal slot whose name is the "Formatter Internal Slot" value of the current row.
683492
1. If _unitOptions_.[[Style]] is *"fractional"*, then
684493
1. Let _unit_ be the Unit value of the current row.
685494
1. Assert: IsFractionalSecondUnitName(_unit_) is *true*.
686-
1. Let _value_ be the value of _duration_'s field whose name is the Value Field value of the current row.
495+
1. Let _value_ be the value of _duration_'s internal slot whose name is the "Duration Internal Slot" value of the current row.
687496
1. Set _result_ to _result_ + (_value_ / 10<sup>_exponent_</sup>).
688497
1. Set _exponent_ to _exponent_ + 3.
689498
1. Return _result_.
@@ -829,7 +638,7 @@ <h1>
829638
<h1>
830639
FormatNumericUnits (
831640
_durationFormat_: a DurationFormat Object,
832-
_duration_: a Duration Record,
641+
_duration_: a Temporal.Duration,
833642
_firstNumericUnit_: a String,
834643
_signDisplayed_: a Boolean,
835644
): a List of Records
@@ -946,7 +755,7 @@ <h1>
946755
<h1>
947756
PartitionDurationFormatPattern (
948757
_durationFormat_: a DurationFormat,
949-
_duration_: a Duration Record,
758+
_duration_: a Temporal.Duration,
950759
): a List
951760
</h1>
952761
<dl class="header">
@@ -959,8 +768,8 @@ <h1>
959768
1. Let _signDisplayed_ be *true*.
960769
1. Let _numericUnitFound_ be *false*.
961770
1. While _numericUnitFound_ is *false*, repeat for each row in <emu-xref href="#table-partition-duration-format-pattern"></emu-xref> in table order, except the header row:
962-
1. Let _value_ be the value of _duration_'s field whose name is the Value Field value of the current row.
963-
1. Let _unitOptions_ be the value of _durationFormat_'s internal slot whose name is the Internal Slot value of the current row.
771+
1. Let _value_ be the value of _duration_'s internal slot whose name is the "Duration Internal Slot" value of the current row.
772+
1. Let _unitOptions_ be the value of _durationFormat_'s internal slot whose name is the "Formatter Internal Slot" value of the current row.
964773
1. Let _style_ be _unitOptions_.[[Style]].
965774
1. Let _display_ be _unitOptions_.[[Display]].
966775
1. Let _unit_ be the Unit value of the current row.
@@ -1006,8 +815,8 @@ <h1>
1006815
<table class="real-table">
1007816
<thead>
1008817
<tr>
1009-
<th>Value Field</th>
1010-
<th>Internal Slot</th>
818+
<th>Duration Internal Slot</th>
819+
<th>Formatter Internal Slot</th>
1011820
<th>Unit</th>
1012821
<th>NumberFormat Unit</th>
1013822
</tr>

0 commit comments

Comments
 (0)