forked from tc39/proposal-intl-duration-format
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspec.emu
831 lines (782 loc) · 41 KB
/
spec.emu
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
<!doctype html>
<meta charset="utf8">
<pre class="metadata">
title: Intl.DurationFormat
stage: 3
location: https://tc39.es/proposal-intl-duration-format/
contributors: Ujjwal Sharma, Younies Mahmoud
</pre>
<emu-biblio href="./biblio.json"></emu-biblio>
<emu-clause id="durationformat-objects">
<h1>DurationFormat Objects</h1>
<emu-clause id="sec-intl-durationformat-abstracts">
<h1>Abstract Operations for DurationFormat Objects</h1>
<emu-clause id="sec-duration-records">
<h1>Duration Records</h1>
<p>A <dfn variants="Duration Records">Duration Record</dfn> is a Record value used to represent a Duration.</p>
<p>Duration Records have the fields in <emu-xref href="#table-duration-record-fields"></emu-xref></p>
<emu-table id="table-duration-record-fields" caption="Duration Record Fields">
<table class="real-table">
<tr>
<th>Field</th>
<th>Meaning</th>
</tr>
<tr>
<td>[[Years]]</td>
<td>
The number of years in the duration.
</td>
</tr>
<tr>
<td>[[Months]]</td>
<td>
The number of months in the duration.
</td>
</tr>
<tr>
<td>[[Weeks]]</td>
<td>
The number of weeks in the duration.
</td>
</tr>
<tr>
<td>[[Days]]</td>
<td>
The number of days in the duration.
</td>
</tr>
<tr>
<td>[[Hours]]</td>
<td>
The number of hours in the duration.
</td>
</tr>
<tr>
<td>[[Minutes]]</td>
<td>
The number of minutes in the duration.
</td>
</tr>
<tr>
<td>[[Seconds]]</td>
<td>
The number of seconds in the duration.
</td>
</tr>
<tr>
<td>[[Milliseconds]]</td>
<td>
The number of milliseconds in the duration.
</td>
</tr>
<tr>
<td>[[Microseconds]]</td>
<td>
The number of microseconds in the duration.
</td>
</tr>
<tr>
<td>[[Nanoseconds]]</td>
<td>
The number of nanoseconds in the duration.
</td>
</tr>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-tointegerwithoutrounding" type="abstract operation">
<h1>
ToIntegerIfIntegral (
_argument_: an ECMAScript language value,
): either a normal completion containing an integer, or an abrupt completion
</h1>
<dl class="header">
<dt>description</dt>
<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>
</dl>
<emu-alg>
1. Let _number_ be ? ToNumber(_argument_).
1. If IsIntegralNumber(_number_) is *false*, throw a *RangeError* exception.
1. Return ℝ(_number_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-todurationrecord" type="abstract operation">
<h1>
ToDurationRecord (
_input_: an ECMAScript language value
): either a normal completion containing a Duration Record, or an abrupt completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>It converts a given object that represents a Duration into a Duration Record.</dd>
</dl>
<emu-alg>
1. If Type(_input_) is not Object, then
1. If Type(_input_) is String, throw a *RangeError* exception.
1. Throw a *TypeError* exception.
1. Let _result_ be a new Duration Record with each field set to 0.
1. Let _days_ be ? Get(_input_, *"days"*).
1. If _days_ is not *undefined*, set _result_.[[Days]] to ? ToIntegerIfIntegral(_days_).
1. Let _hours_ be ? Get(_input_, *"hours"*).
1. If _hours_ is not *undefined*, set _result_.[[Hours]] to ? ToIntegerIfIntegral(_hours_).
1. Let _microseconds_ be ? Get(_input_, *"microseconds"*).
1. If _microseconds_ is not *undefined*, set _result_.[[Microseconds]] to ? ToIntegerIfIntegral(_microseconds_).
1. Let _milliseconds_ be ? Get(_input_, *"milliseconds"*).
1. If _milliseconds_ is not *undefined*, set _result_.[[Milliseconds]] to ? ToIntegerIfIntegral(_milliseconds_).
1. Let _minutes_ be ? Get(_input_, *"minutes"*).
1. If _minutes_ is not *undefined*, set _result_.[[Minutes]] to ? ToIntegerIfIntegral(_minutes_).
1. Let _months_ be ? Get(_input_, *"months"*).
1. If _months_ is not *undefined*, set _result_.[[Months]] to ? ToIntegerIfIntegral(_months_).
1. Let _nanoseconds_ be ? Get(_input_, *"nanoseconds"*).
1. If _nanoseconds_ is not *undefined*, set _result_.[[Nanoseconds]] to ? ToIntegerIfIntegral(_nanoseconds_).
1. Let _seconds_ be ? Get(_input_, *"seconds"*).
1. If _seconds_ is not *undefined*, set _result_.[[Seconds]] to ? ToIntegerIfIntegral(_seconds_).
1. Let _weeks_ be ? Get(_input_, *"weeks"*).
1. If _weeks_ is not *undefined*, set _result_.[[Weeks]] to ? ToIntegerIfIntegral(_weeks_).
1. Let _years_ be ? Get(_input_, *"years"*).
1. If _years_ is not *undefined*, set _result_.[[Years]] to ? ToIntegerIfIntegral(_years_).
1. If _years_, _months_, _weeks_, _days_, _hours_, _minutes_, _seconds_, _milliseconds_, _microseconds_, and _nanoseconds_ are all *undefined*, throw a *TypeError* exception.
1. If IsValidDurationRecord(_result_) is *false*, throw a *RangeError* exception.
1. Return _result_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-durationrecordsign" type="abstract operation">
<h1>
DurationRecordSign (
_record_: a Duration Record
): an integer
</h1>
<dl class="header">
<dt>description</dt>
<dd>It returns 1 if the most significant non-zero field in _record_ is positive, and -1 if the most significant non-zero field is negative. If all the fields are zero, it returns 0.</dd>
</dl>
<emu-alg>
1. For each row of <emu-xref href="#table-duration-record-fields"></emu-xref>, except the header row, in table order, do
1. Let _v_ be the value of _record_'s field whose name is the Field value of the current row.
1. If _v_ < 0, return -1.
1. If _v_ > 0, return 1.
1. Return 0.
</emu-alg>
</emu-clause>
<emu-clause id="sec-isvaliddurationrecord" type="abstract operation">
<h1>
IsValidDurationRecord (
_record_: a Duration Record
): a Boolean
</h1>
<dl class="header">
<dt>description</dt>
<dd>It returns *true* if _record_ represents a valid duration, and *false* otherwise.</dd>
</dl>
<emu-alg>
1. Let _sign_ be DurationRecordSign(_record_).
1. For each row of <emu-xref href="#table-duration-record-fields"></emu-xref>, except the header row, in table order, do
1. Let _v_ be the value of _record_'s field whose name is the Field value of the current row.
1. Assert: 𝔽(_v_) is finite.
1. If _v_ < 0 and _sign_ > 0, return *false*.
1. If _v_ > 0 and _sign_ < 0, return *false*.
1. Return *true*.
</emu-alg>
</emu-clause>
<emu-clause id="sec-getdurationunitoptions" type="abstract operation">
<h1>
GetDurationUnitOptions (
_unit_: a String,
_options_: an ECMAScript language value,
_baseStyle_: a String,
_stylesList_: a List of String,
_digitalBase_: a String,
_prevStyle_: a String,
): either a normal completion containing a Record with [[Style]] and [[Display]] fields, or an abrupt completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>It extracts the relevant options for any given _unit_ from an options bag and returns them as a Record.</dd>
</dl>
<emu-alg>
1. Let _style_ be ? GetOption(_options_, _unit_, ~string~, _stylesList_, *undefined*).
1. Let _displayDefault_ be *"always"*.
1. If _style_ is *undefined*, then
1. If _baseStyle_ is *"digital"*, then
1. If _unit_ is not one of *"hours"*, *"minutes"*, or *"seconds"*, then
1. Set _displayDefault_ to *"auto"*.
1. Set _style_ to _digitalBase_.
1. Else,
1. If _prevStyle_ is *"numeric"* or *"2-digit"*, then
1. If _unit_ is not one of *"minutes"* or *"seconds"*, then
1. Set _displayDefault_ to *"auto"*.
1. Set _style_ to *"numeric"*.
1. Else,
1. Set _displayDefault_ to *"auto"*.
1. Set _style_ to _baseStyle_.
1. Let _displayField_ be the string-concatenation of _unit_ and *"Display"*.
1. Let _display_ be ? GetOption(_options_, _displayField_, ~string~, « *"auto"*, *"always"* », _displayDefault_).
1. If _prevStyle_ is *"numeric"* or *"2-digit"*, then
1. If _style_ is not *"numeric"* or *"2-digit"*, then
1. Throw a *RangeError* exception.
1. Else if _unit_ is *"minutes"* or *"seconds"*, then
1. Set _style_ to *"2-digit"*.
1. If _style_ is *"numeric"* and _display_ is *"always"* and _unit_ is one of *"milliseconds"*, *"microseconds"*, or *"nanoseconds"*, then
1. Throw a *RangeError* exception.
1. Return the Record {
[[Style]]: _style_,
[[Display]]: _display_
}.
</emu-alg>
</emu-clause>
<emu-clause id="sec-partitiondurationformatpattern" type="abstract operation">
<h1>
PartitionDurationFormatPattern (
_durationFormat_: a DurationFormat,
_duration_: a Duration Record,
): a List
</h1>
<dl class="header">
<dt>description</dt>
<dd>It creates and returns a List with all the corresponding parts according to the effective locale and the formatting options of _durationFormat_.</dd>
</dl>
<emu-alg>
1. Let _result_ be a new empty List.
1. Let _done_ be *false*.
1. Let _needSeparator_ be *false*.
1. Let _dataLocale_ be _durationFormat_.[[DataLocale]].
1. Let _dataLocaleData_ be %DurationFormat%.[[LocaleData]].[[<_dataLocale_>]].
1. Let _numberingSystem_ be _durationFormat_.[[NumberingSystem]].
1. Let _separator_ be _dataLocaleData_.[[digitalFormat]].[[<_numberingSystem_>]].
1. While _done_ is *false*, repeat for each row in <emu-xref href="#table-partition-duration-format-pattern"></emu-xref> in table order, except the header row:
1. Let _value_ be the value of _duration_'s field whose name is the Value Field value of the current row.
1. Let _style_ be the value of _durationFormat_'s internal slot whose name is the Style Slot value of the current row.
1. Let _display_ be the value of _durationFormat_'s internal slot whose name is the Display Slot value of the current row.
1. Let _unit_ be the Unit value of the current row.
1. Let _numberFormatUnit_ be the NumberFormat Unit value of the current row.
1. Let _nfOpts_ be OrdinaryObjectCreate(*null*).
1. If _unit_ is *"seconds"*, *"milliseconds"*, or *"microseconds"*, then
1. If _unit_ is *"seconds"*, then
1. Let _nextStyle_ be _durationFormat_.[[MillisecondsStyle]].
1. Else if _unit_ is *"milliseconds"*, then
1. Let _nextStyle_ be _durationFormat_.[[MicrosecondsStyle]].
1. Else,
1. Let _nextStyle_ be _durationFormat_.[[NanosecondsStyle]].
1. If _nextStyle_ is *"numeric"*, then
1. If _unit_ is *"seconds"*, then
1. Set _value_ to _value_ + _duration_.[[Milliseconds]] / 10<sup>3</sup> + _duration_.[[Microseconds]] / 10<sup>6</sup> + _duration_.[[Nanoseconds]] / 10<sup>9</sup>.
1. Else if _unit_ is *"milliseconds"*, then
1. Set _value_ to _value_ + _duration_.[[Microseconds]] / 10<sup>3</sup> + _duration_.[[Nanoseconds]] / 10<sup>6</sup>.
1. Else,
1. Set _value_ to _value_ + _duration_.[[Nanoseconds]] / 10<sup>3</sup>.
1. If _durationFormat_.[[FractionalDigits]] is *undefined*, then
1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"maximumFractionDigits"*, *9*<sub>𝔽</sub>).
1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"minimumFractionDigits"*, *+0*<sub>𝔽</sub>).
1. Else,
1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"maximumFractionDigits"*, 𝔽(_durationFormat_.[[FractionalDigits]])).
1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"minimumFractionDigits"*, 𝔽(_durationFormat_.[[FractionalDigits]])).
1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"roundingMode"*, *"trunc"*).
1. Set _done_ to *true*.
1. Let _displayRequired_ be *"false"*.
1. Let _hoursStyle_ be _durationFormat_.[[HoursStyle]].
1. If _unit_ is *"minutes"*, then
1. If _hoursStyle_ is *"numeric"* or *"2-digit"*, then
1. Let _hoursDisplay_ be _durationFormat_.[[HoursDisplay]].
1. Let _hoursValue_ be _durationFormat_.[[HoursValue]].
1. If _hoursDisplay_ is *"always"* or _hoursValue_ is not 0, then
1. Let _secondsDisplay_ be _durationFormat_.[[SecondsDisplay]].
1. Let _secondsValue_ be _durationFormat_.[[SecondsValue]].
1. If _secondsDisplay_ is *"always"* or _secondsValue_ is not 0, then
1. Set _displayRequired_ to *"true"*.
1. If _value_ is not 0 or _display_ is not *"auto"* or _displayRequired_ is *"true"*, then
1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"numberingSystem"*, _durationFormat_.[[NumberingSystem]]).
1. If _style_ is *"2-digit"*, then
1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"minimumIntegerDigits"*, *2*<sub>𝔽</sub>).
1. If _style_ is neither *"2-digit"* nor *"numeric"*, then
1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"style"*, *"unit"*).
1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"unit"*, _numberFormatUnit_).
1. Perform ! CreateDataPropertyOrThrow(_nfOpts_, *"unitDisplay"*, _style_).
1. Let _nf_ be ! Construct(%NumberFormat%, « _durationFormat_.[[Locale]], _nfOpts_ »).
1. If _needSeparator_ is *false*, then
1. Let _list_ be a new empty List.
1. Else,
1. Let _list_ be the last element of _result_.
1. Append the Record { [[Type]]: *"literal"*, [[Value]]: _separator_, [[Unit]]: ~empty~ } to _list_.
1. Let _parts_ be ! PartitionNumberPattern(_nf_, _value_).
1. For each Record { [[Type]], [[Value]] } _part_ of _parts_, do
1. Append the Record { [[Type]]: _part_.[[Type]], [[Value]]: _part_.[[Value]], [[Unit]]: _numberFormatUnit_ } to _list_.
1. If _needSeparator_ is *false*, then
1. If _style_ is *"2-digit"* or *"numeric"*, then
1. Set _needSeparator_ to *true*.
1. Append _list_ to _result_.
1. Else,
1. Set _needSeparator_ to *false*.
1. Let _lfOpts_ be OrdinaryObjectCreate(*null*).
1. Perform ! CreateDataPropertyOrThrow(_lfOpts_, *"type"*, *"unit"*).
1. Let _listStyle_ be _durationFormat_.[[Style]].
1. If _listStyle_ is *"digital"*, then
1. Set _listStyle_ to *"short"*.
1. Perform ! CreateDataPropertyOrThrow(_lfOpts_, *"style"*, _listStyle_).
1. Let _lf_ be ! Construct(%ListFormat%, « _durationFormat_.[[Locale]], _lfOpts_ »).
1. Let _strings_ be a new empty List.
1. For each element _parts_ of _result_, do
1. Let _string_ be the empty String.
1. For each Record { [[Type]], [[Value]], [[Unit]] } _part_ in _parts_, do
1. Set _string_ to the string-concatenation of _string_ and _part_.[[Value]].
1. Append _string_ to _strings_.
1. Let _formatted_ be CreatePartsFromList(_lf_, _strings_).
1. Let _resultIndex_ be 0.
1. Let _resultLength_ be the number of elements in _result_.
1. Let _flattened_ be a new empty List.
1. For each Record { [[Type]], [[Value]] } _listPart_ in _formatted_, do
1. If _listPart_.[[Type]] is *"element"*, then
1. Assert: _resultIndex_ < _resultLength_.
1. Let _parts_ be _result_[_resultIndex_].
1. For each Record { [[Type]], [[Value]], [[Unit]] } _part_ in _parts_, do
1. Append _part_ to _flattened_.
1. Set _resultIndex_ to _resultIndex_ + 1.
1. Else,
1. Assert: _listPart_.[[Type]] is *"literal"*.
1. Append the Record { [[Type]]: *"literal"*, [[Value]]: _listPart_.[[Value]], [[Unit]]: ~empty~ } to _flattened_.
1. Return _flattened_.
</emu-alg>
<emu-table id="table-partition-duration-format-pattern">
<emu-caption>DurationFormat instance internal slots and properties relevant to PartitionDurationFormatPattern</emu-caption>
<table class="real-table">
<thead>
<tr>
<th>Value Field</th>
<th>Style Slot</th>
<th>Display Slot</th>
<th>Unit</th>
<th>NumberFormat Unit</th>
</tr>
</thead>
<tr>
<td>[[Years]]</td>
<td>[[YearsStyle]]</td>
<td>[[YearsDisplay]]</td>
<td>*"years"*</td>
<td>*"year"*</td>
</tr>
<tr>
<td>[[Months]]</td>
<td>[[MonthsStyle]]</td>
<td>[[MonthsDisplay]]</td>
<td>*"months"*</td>
<td>*"month"*</td>
</tr>
<tr>
<td>[[Weeks]]</td>
<td>[[WeeksStyle]]</td>
<td>[[WeeksDisplay]]</td>
<td>*"weeks"*</td>
<td>*"week"*</td>
</tr>
<tr>
<td>[[Days]]</td>
<td>[[DaysStyle]]</td>
<td>[[DaysDisplay]]</td>
<td>*"days"*</td>
<td>*"day"*</td>
</tr>
<tr>
<td>[[Hours]]</td>
<td>[[HoursStyle]]</td>
<td>[[HoursDisplay]]</td>
<td>*"hours"*</td>
<td>*"hour"*</td>
</tr>
<tr>
<td>[[Minutes]]</td>
<td>[[MinutesStyle]]</td>
<td>[[MinutesDisplay]]</td>
<td>*"minutes"*</td>
<td>*"minute"*</td>
</tr>
<tr>
<td>[[Seconds]]</td>
<td>[[SecondsStyle]]</td>
<td>[[SecondsDisplay]]</td>
<td>*"seconds"*</td>
<td>*"second"*</td>
</tr>
<tr>
<td>[[Milliseconds]]</td>
<td>[[MillisecondsStyle]]</td>
<td>[[MillisecondsDisplay]]</td>
<td>*"milliseconds"*</td>
<td>*"millisecond"*</td>
</tr>
<tr>
<td>[[Microseconds]]</td>
<td>[[MicrosecondsStyle]]</td>
<td>[[MicrosecondsDisplay]]</td>
<td>*"microseconds"*</td>
<td>*"microsecond"*</td>
</tr>
<tr>
<td>[[Nanoseconds]]</td>
<td>[[NanosecondsStyle]]</td>
<td>[[NanosecondsDisplay]]</td>
<td>*"nanoseconds"*</td>
<td>*"nanosecond"*</td>
</tr>
</table>
</emu-table>
</emu-clause>
</emu-clause>
<emu-clause id="sec-intl-durationformat-constructor">
<h1>The Intl.DurationFormat Constructor</h1>
<p>The DurationFormat constructor is the <dfn>%DurationFormat%</dfn> intrinsic object and a standard built-in property of the Intl object. Behaviour common to all service constructor properties of the Intl object is specified in <emu-xref href="#sec-internal-slots"></emu-xref>.</p>
<emu-clause id="sec-Intl.DurationFormat">
<h1>Intl.DurationFormat ( [ _locales_ [ , _options_ ] ] )</h1>
<p>When the `Intl.DurationFormat` function is called with optional arguments _locales_ and _options_, the following steps are taken:</p>
<emu-alg>
1. If NewTarget is *undefined*, throw a *TypeError* exception.
1. Let _durationFormat_ be ? OrdinaryCreateFromConstructor(NewTarget, *"%DurationFormatPrototype%"*, « [[InitializedDurationFormat]], [[Locale]], [[DataLocale]], [[NumberingSystem]], [[Style]], [[YearsStyle]], [[YearsDisplay]], [[MonthsStyle]], [[MonthsDisplay]] , [[WeeksStyle]], [[WeeksDisplay]] , [[DaysStyle]], [[DaysDisplay]] , [[HoursStyle]], [[HoursDisplay]] , [[MinutesStyle]], [[MinutesDisplay]] , [[SecondsStyle]], [[SecondsDisplay]] , [[MillisecondsStyle]], [[MillisecondsDisplay]] , [[MicrosecondsStyle]], [[MicrosecondsDisplay]] , [[NanosecondsStyle]], [[NanosecondsDisplay]], [[FractionalDigits]] »).
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
1. Let _options_ be ? GetOptionsObject(_options_).
1. Let _matcher_ be ? GetOption(_options_, *"localeMatcher"*, ~string~, « *"lookup"*, *"best fit"* », *"best fit"*).
1. Let _numberingSystem_ be ? GetOption(_options_, *"numberingSystem"*, ~string~, *undefined*, *undefined*).
1. If _numberingSystem_ is not *undefined*, then
1. If _numberingSystem_ does not match the Unicode Locale Identifier `type` nonterminal, throw a *RangeError* exception.
1. Let _opt_ be the Record { [[localeMatcher]]: _matcher_, [[nu]]: _numberingSystem_ }.
1. Let _r_ be ResolveLocale(%DurationFormat%.[[AvailableLocales]], _requestedLocales_, _opt_, %DurationFormat%.[[RelevantExtensionKeys]], %DurationFormat%.[[LocaleData]]).
1. Let _locale_ be r.[[locale]].
1. Set _durationFormat_.[[Locale]] to _locale_.
1. Set _durationFormat_.[[NumberingSystem]] to _r_.[[nu]].
1. Let _style_ be ? GetOption(_options_, *"style"*, ~string~, « *"long"*, *"short"*, *"narrow"*, *"digital"* », *"short"*).
1. Set _durationFormat_.[[Style]] to _style_.
1. Set _durationFormat_.[[DataLocale]] to _r_.[[dataLocale]].
1. Let _prevStyle_ be the empty String.
1. For each row of <emu-xref href="#table-durationformat"></emu-xref>, except the header row, in table order, do
1. Let _styleSlot_ be the Style Slot value of the current row.
1. Let _displaySlot_ be the Display Slot value of the current row.
1. Let _unit_ be the Unit value.
1. Let _valueList_ be the Values value.
1. Let _digitalBase_ be the Digital Default value.
1. Let _unitOptions_ be ? GetDurationUnitOptions(_unit_, _options_, _style_, _valueList_, _digitalBase_, _prevStyle_).
1. Set the value of the _styleSlot_ slot of _durationFormat_ to _unitOptions_.[[Style]].
1. Set the value of the _displaySlot_ slot of _durationFormat_ to _unitOptions_.[[Display]].
1. If _unit_ is one of *"hours"*, *"minutes"*, *"seconds"*, *"milliseconds"*, or *"microseconds"*, then
1. Set _prevStyle_ to _unitOptions_.[[Style]].
1. Set _durationFormat_.[[FractionalDigits]] to ? GetNumberOption(_options_, *"fractionalDigits"*, 0, 9, *undefined*).
1. Return _durationFormat_.
</emu-alg>
<emu-table id="table-durationformat">
<emu-caption>Internal slots and property names of DurationFormat instances relevant to Intl.DurationFormat constructor</emu-caption>
<table class="real-table">
<thead>
<tr>
<th>Style Slot</th>
<th>Display Slot</th>
<th>Unit</th>
<th>Values</th>
<th>Digital Default</th>
</tr>
</thead>
<tr>
<td>[[YearsStyle]]</td>
<td>[[YearsDisplay]]</td>
<td>*"years"*</td>
<td>« *"long"*, *"short"*, *"narrow"* »</td>
<td>*"short"*</td>
</tr>
<tr>
<td>[[MonthsStyle]]</td>
<td>[[MonthsDisplay]]</td>
<td>*"months"*</td>
<td>« *"long"*, *"short"*, *"narrow"* »</td>
<td>*"short"*</td>
</tr>
<tr>
<td>[[WeeksStyle]]</td>
<td>[[WeeksDisplay]]</td>
<td>*"weeks"*</td>
<td>« *"long"*, *"short"*, *"narrow"* »</td>
<td>*"short"*</td>
</tr>
<tr>
<td>[[DaysStyle]]</td>
<td>[[DaysDisplay]]</td>
<td>*"days"*</td>
<td>« *"long"*, *"short"*, *"narrow"* »</td>
<td>*"short"*</td>
</tr>
<tr>
<td>[[HoursStyle]]</td>
<td>[[HoursDisplay]]</td>
<td>*"hours"*</td>
<td>« *"long"*, *"short"*, *"narrow"*, <br/>*"numeric"*, *"2-digit"* »</td>
<td>*"numeric"*</td>
</tr>
<tr>
<td>[[MinutesStyle]]</td>
<td>[[MinutesDisplay]]</td>
<td>*"minutes"*</td>
<td>« *"long"*, *"short"*, *"narrow"*, <br/>*"numeric"*, *"2-digit"* »</td>
<td>*"numeric"*</td>
</tr>
<tr>
<td>[[SecondsStyle]]</td>
<td>[[SecondsDisplay]]</td>
<td>*"seconds"*</td>
<td>« *"long"*, *"short"*, *"narrow"*, <br/>*"numeric"*, *"2-digit"* »</td>
<td>*"numeric"*</td>
</tr>
<tr>
<td>[[MillisecondsStyle]]</td>
<td>[[MillisecondsDisplay]]</td>
<td>*"milliseconds"*</td>
<td>« *"long"*, *"short"*, *"narrow"*, <br/>*"numeric"* »</td>
<td>*"numeric"*</td>
</tr>
<tr>
<td>[[MicrosecondsStyle]]</td>
<td>[[MicrosecondsDisplay]]</td>
<td>*"microseconds"*</td>
<td>« *"long"*, *"short"*, *"narrow"*, <br/>*"numeric"* »</td>
<td>*"numeric"*</td>
</tr>
<tr>
<td>[[NanosecondsStyle]]</td>
<td>[[NanosecondsDisplay]]</td>
<td>*"nanoseconds"*</td>
<td>« *"long"*, *"short"*, *"narrow"*, <br/>*"numeric"* »</td>
<td>*"numeric"*</td>
</tr>
</table>
</emu-table>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-intl-durationformat-constructor">
<h1>Properties of the Intl.DurationFormat Constructor</h1>
<p>The Intl.DurationFormat constructor has the following properties:</p>
<emu-clause id="sec-Intl.DurationFormat.prototype">
<h1>Intl.DurationFormat.prototype</h1>
<p>The value of `Intl.DurationFormat.prototype` is %DurationFormatPrototype%.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.</p>
</emu-clause>
<emu-clause id="sec-Intl.DurationFormat.supportedLocalesOf">
<h1>Intl.DurationFormat.supportedLocalesOf ( _locales_ [ , _options_ ] )</h1>
<p>When the `supportedLocalesOf` method is called with arguments _locales_ and _options_, the following steps are taken:</p>
<emu-alg>
1. Let _availableLocales_ be %DurationFormat%.[[AvailableLocales]].
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
1. Return ? SupportedLocales(_availableLocales_, _requestedLocales_, _options_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-Intl.DurationFormat-internal-slots">
<h1>Internal slots</h1>
<p>The value of the [[AvailableLocales]] internal slot is implementation defined within the constraints described in <emu-xref href="#sec-internal-slots"></emu-xref>.</p>
<p>The value of the [[RelevantExtensionKeys]] internal slot is « *"nu"* ».</p>
<p>The value of the [[LocaleData]] internal slot is implementation defined within the constraints described in <emu-xref href="#sec-internal-slots"></emu-xref> and the following additional constraints for all locale values _locale_:</p>
<ul>
<li>[[LocaleData]].[[<_locale_>]].[[nu]] must be a List as specified in <emu-xref href="#sec-intl.numberformat-internal-slots"></emu-xref>.</li>
<li>[[LocaleData]].[[<_locale_>]].[[digitalFormat]] must be a Record with keys corresponding to each numbering system available for the given locale and String values containing the appropriate time unit separator for that combination of locale and numbering system.</li>
</ul>
<emu-note>It is recommended that implementations use the locale data provided by the Common Locale Data Repository (available at <a href="http://cldr.unicode.org/">http://cldr.unicode.org/</a>).</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-intl-durationformat-prototype-object">
<h1>Properties of the Intl.DurationFormat Prototype Object</h1>
<p>The Intl.DurationFormat prototype object is itself an ordinary object. <dfn>%DurationFormatPrototype%</dfn> is not an Intl.DurationFormat instance and does not have an [[InitializedDurationFormat]] internal slot or any of the other internal slots of Intl.DurationFormat instance objects.</p>
<emu-clause id="sec-Intl.DurationFormat.prototype.constructor">
<h1>Intl.DurationFormat.prototype.constructor</h1>
<p>The initial value of `Intl.DurationFormat.prototype.constructor` is the intrinsic object %DurationFormat%.</p>
</emu-clause>
<emu-clause id="sec-Intl.DurationFormat.prototype-@@tostringtag">
<h1>Intl.DurationFormat.prototype [ @@toStringTag ]</h1>
<p>The initial value of the @@toStringTag property is the string value *"Intl.DurationFormat"*.</p>
<p>This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.</p>
</emu-clause>
<emu-clause id="sec-Intl.DurationFormat.prototype.format">
<h1>Intl.DurationFormat.prototype.format ( _duration_ )</h1>
<p>When the `format` method is called with an argument _duration_, the following steps are taken:</p>
<emu-alg>
1. Let _df_ be *this* value.
1. Perform ? RequireInternalSlot(_df_, [[InitializedDurationFormat]]).
1. Let _record_ be ? ToDurationRecord(_duration_).
1. Let _parts_ be PartitionDurationFormatPattern(_df_, _record_).
1. Let _result_ be the empty String.
1. For each Record { [[Type]], [[Value]], [[Unit]] } _part_ in _parts_, do
1. Set _result_ to the string-concatenation of _result_ and _part_.[[Value]].
1. Return _result_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-Intl.DurationFormat.prototype.formatToParts">
<h1>Intl.DurationFormat.prototype.formatToParts ( _duration_ )</h1>
<p>When the `formatToParts` method is called with an argument _duration_, the following steps are taken:</p>
<emu-alg>
1. Let _df_ be *this* value.
1. Perform ? RequireInternalSlot(_df_, [[InitializedDurationFormat]]).
1. Let _record_ be ? ToDurationRecord(_duration_).
1. Let _parts_ be PartitionDurationFormatPattern(_df_, _record_).
1. Let _result_ be ! ArrayCreate(0).
1. Let _n_ be 0.
1. For each Record { [[Type]], [[Value]], [[Unit]] } _part_ in _parts_, do
1. Let _obj_ be OrdinaryObjectCreate(%ObjectPrototype%).
1. Perform ! CreateDataPropertyOrThrow(_obj_, *"type"*, _part_.[[Type]]).
1. Perform ! CreateDataPropertyOrThrow(_obj_, *"value"*, _part_.[[Value]]).
1. If _part_.[[Unit]] is not ~empty~, perform ! CreateDataPropertyOrThrow(_obj_, *"unit"*, _part_.[[Unit]]).
1. Perform ! CreateDataPropertyOrThrow(_result_, ! ToString(_n_), _obj_).
1. Set _n_ to _n_ + 1.
1. Return _result_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-Intl.DurationFormat.prototype.resolvedOptions">
<h1>Intl.DurationFormat.prototype.resolvedOptions ( )</h1>
<p>This function provides access to the locale and options computed during initialization of the object.</p>
<emu-alg>
1. Let _df_ be the *this* value.
1. Perform ? RequireInternalSlot(_df_, [[InitializedDurationFormat]]).
1. Let _options_ be OrdinaryObjectCreate(%ObjectPrototype%).
1. For each row of <emu-xref href="#table-durationformat-resolvedoptions-properties"></emu-xref>, except the header row, in table order, do
1. Let _p_ be the Property value of the current row.
1. Let _v_ be the value of _df_'s internal slot whose name is the Internal Slot value of the current row.
1. If _p_ is *"fractionalDigits"*, then
1. If _v_ is not *undefined*, set _v_ to 𝔽(_v_).
1. Else,
1. Assert: _v_ is not *undefined*.
1. Perform ! CreateDataPropertyOrThrow(_options_, _p_, _v_).
1. Return _options_.
</emu-alg>
<emu-table id="table-durationformat-resolvedoptions-properties">
<emu-caption>Resolved Options of DurationFormat Instances</emu-caption>
<table class="real-table">
<thead>
<tr>
<th>Internal Slot</th>
<th>Property</th>
</tr>
</thead>
<tr>
<td>[[Locale]]</td>
<td>*"locale"*</td>
</tr>
<tr>
<td>[[Style]]</td>
<td>*"style"*</td>
</tr>
<tr>
<td>[[YearsStyle]]</td>
<td>*"years"*</td>
</tr>
<tr>
<td>[[YearsDisplay]]</td>
<td>*"yearsDisplay"*</td>
</tr>
<tr>
<td>[[MonthsStyle]]</td>
<td>*"months"*</td>
</tr>
<tr>
<td>[[MonthsDisplay]]</td>
<td>*"monthsDisplay"*</td>
</tr>
<tr>
<td>[[WeeksStyle]]</td>
<td>*"weeks"*</td>
</tr>
<tr>
<td>[[WeeksDisplay]]</td>
<td>*"weeksDisplay"*</td>
</tr>
<tr>
<td>[[DaysStyle]]</td>
<td>*"days"*</td>
</tr>
<tr>
<td>[[DaysDisplay]]</td>
<td>*"daysDisplay"*</td>
</tr>
<tr>
<td>[[HoursStyle]]</td>
<td>*"hours"*</td>
</tr>
<tr>
<td>[[HoursDisplay]]</td>
<td>*"hoursDisplay"*</td>
</tr>
<tr>
<td>[[MinutesStyle]]</td>
<td>*"minutes"*</td>
</tr>
<tr>
<td>[[MinutesDisplay]]</td>
<td>*"minutesDisplay"*</td>
</tr>
<tr>
<td>[[SecondsStyle]]</td>
<td>*"seconds"*</td>
</tr>
<tr>
<td>[[SecondsDisplay]]</td>
<td>*"secondsDisplay"*</td>
</tr>
<tr>
<td>[[MillisecondsStyle]]</td>
<td>*"milliseconds"*</td>
</tr>
<tr>
<td>[[MillisecondsDisplay]]</td>
<td>*"millisecondsDisplay"*</td>
</tr>
<tr>
<td>[[MicrosecondsStyle]]</td>
<td>*"microseconds"*</td>
</tr>
<tr>
<td>[[MicrosecondsDisplay]]</td>
<td>*"microsecondsDisplay"*</td>
</tr>
<tr>
<td>[[NanosecondsStyle]]</td>
<td>*"nanoseconds"*</td>
</tr>
<tr>
<td>[[NanosecondsDisplay]]</td>
<td>*"nanosecondsDisplay"*</td>
</tr>
<tr>
<td>[[FractionalDigits]]</td>
<td>*"fractionalDigits"*</td>
</tr>
<tr>
<td>[[NumberingSystem]]</td>
<td>*"numberingSystem"*</td>
</tr>
</table>
</emu-table>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-intl-durationformat-instances">
<h1>Properties of Intl.DurationFormat Instances</h1>
<p>Intl.DurationFormat instances inherit properties from %DurationFormatPrototype%.</p>
<p>Intl.DurationFormat instances have an [[InitializedDurationFormat]] internal slot.</p>
<p>Intl.DurationFormat instances also have several internal slots that are computed by the constructor:</p>
<ul>
<li>[[Locale]] is a String value with the language tag of the locale whose localization is used for formatting.</li>
<li>[[DataLocale]] is a String value with the language tag of the nearest locale for which the implementation has data to perform the formatting operation. It will be a parent locale of [[Locale]].</li>
<li>[[NumberingSystem]] is a String value with the *"type"* given in Unicode Technical Standard 35 for the numbering system used for formatting.</li>
<li>[[Style]] is one of the String values *"long"*, *"short"*, *"narrow"*, or *"digital"* identifying the duration formatting style used.</li>
<li>[[YearsStyle]] is one of the String values *"long"*, *"short"*, or *"narrow"* identifying the formatting style used for the years field.</li>
<li>[[YearsDisplay]] is one of the String values *"auto"* or *"always"* identifying when to display the years field.</li>
<li>[[MonthsStyle]] is one of the String values *"long"*, *"short"*, or *"narrow"* identifying the formatting style used for the months field.</li>
<li>[[MonthsDisplay]] is one of the String values *"auto"* or *"always"* identifying when to display the months field.</li>
<li>[[WeeksStyle]] is one of the String values *"long"*, *"short"*, or *"narrow"* identifying the formatting style used for the weeks field.</li>
<li>[[WeeksDisplay]] is one of the String values *"auto"* or *"always"* identifying when to display the weeks field.</li>
<li>[[DaysStyle]] is one of the String values *"long"*, *"short"*, or *"narrow"* identifying the formatting style used for the days field.</li>
<li>[[DaysDisplay]] is one of the String values *"auto"* or *"always"* identifying when to display the days field.</li>
<li>[[HoursStyle]] is one of the String values *"long"*, *"short"*, *"narrow"*, *"2-digit"*, or *"numeric"* identifying the formatting style used for the hours field.</li>
<li>[[HoursDisplay]] is one of the String values *"auto"* or *"always"* identifying when to display the hours field.</li>
<li>[[MinutesStyle]] is one of the String values *"long"*, *"short"*, *"narrow"*, *"2-digit"*, or *"numeric"* identifying the formatting style used for the minutes field.</li>
<li>[[MinutesDisplay]] is one of the String values *"auto"* or *"always"* identifying when to display the minutes field.</li>
<li>[[SecondsStyle]] is one of the String values *"long"*, *"short"*, *"narrow"*, *"2-digit"*, or *"numeric"* identifying the formatting style used for the seconds field.</li>
<li>[[SecondsDisplay]] is one of the String values *"auto"* or *"always"* identifying when to display the seconds field.</li>
<li>[[MillisecondsStyle]] is one of the String values *"long"*, *"short"*, *"narrow"*, or *"numeric"* identifying the formatting style used for the milliseconds field.</li>
<li>[[MillisecondsDisplay]] is one of the String values *"auto"* or *"always"* identifying when to display the milliseconds field.</li>
<li>[[MicrosecondsStyle]] is one of the String values *"long"*, *"short"*, *"narrow"*, or *"numeric"* identifying the formatting style used for the microseconds field.</li>
<li>[[MicrosecondsDisplay]] is one of the String values *"auto"* or *"always"* identifying when to display the microseconds field.</li>
<li>[[NanosecondsStyle]] is one of the String values *"long"*, *"short"*, *"narrow"*, or *"numeric"* identifying the formatting style used for the nanoseconds field.</li>
<li>[[NanosecondsDisplay]] is one of the String values *"auto"* or *"always"* identifying when to display the nanoseconds field.</li>
<li>[[FractionalDigits]] is a non-negative integer, identifying the number of fractional digits to be used with numeric styles, or is *undefined*.</li>
</ul>
</emu-clause>
</emu-clause>