-
Notifications
You must be signed in to change notification settings - Fork 147
/
abstractops.html
1829 lines (1683 loc) · 79.7 KB
/
abstractops.html
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
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<meta charset="utf8">
<emu-clause id="sec-temporal-abstract-ops">
<h1>Abstract operations</h1>
<!-- Based on ECMA-262 IterableToList -->
<emu-clause id="sec-iterabletolistoftype" aoid="IterableToListOfType">
<h1>IterableToListOfType ( _items_, _elementTypes_ )</h1>
<p>
The abstract operation IterableToListOfType takes arguments _items_ and _elementTypes_ (a List of names of ECMAScript Language Types).
It is used to create a List value whose elements are provided by the values of the iterable _items_.
_elementTypes_ contains the names of ECMAScript Language Types that are allowed for element values of the List that is created.
It performs the following steps when called:
</p>
<emu-alg>
1. Let _iteratorRecord_ be ? GetIterator(_items_, ~sync~).
1. Let _values_ be a new empty List.
1. Let _next_ be *true*.
1. Repeat, while _next_ is not *false*,
1. Set _next_ to ? IteratorStep(_iteratorRecord_).
1. If _next_ is not *false*, then
1. Let _nextValue_ be ? IteratorValue(_next_).
1. If Type(_nextValue_) is not an element of _elementTypes_, then
1. Let _completion_ be ThrowCompletion(a newly created *TypeError* object).
1. Return ? IteratorClose(_iteratorRecord_, _completion_).
1. Append _nextValue_ to the end of the List _values_.
1. Return _values_.
</emu-alg>
</emu-clause>
<!-- Copied from ECMA-402 GetOptionsObject -->
<emu-clause id="sec-getoptionsobject" aoid="GetOptionsObject">
<h1>GetOptionsObject ( _options_ )</h1>
<p>
The abstract operation GetOptionsObject returns an Object suitable for use with GetOption, either _options_ itself or a default empty Object.
It throws a TypeError if _options_ is not undefined and not an Object.
</p>
<emu-alg>
1. If _options_ is *undefined*, then
1. Return OrdinaryObjectCreate(*null*).
1. If Type(_options_) is Object, then
1. Return _options_.
1. Throw a *TypeError* exception.
</emu-alg>
</emu-clause>
<!-- Copied from ECMA-402 GetOption -->
<emu-clause id="sec-getoption" type="abstract operation">
<h1>
GetOption (
_options_: an Object,
_property_: a property key,
_type_: *"boolean"*, *"number"*, or *"string"*,
_values_: *undefined* or a List of ECMAScript language values,
_default_: ~required~ or an ECMAScript language value,
)
</h1>
<dl class="header">
<dt>description</dt>
<dd>It extracts the value of the specified property of _options_, converts it to the required _type_, checks whether it is allowed by _values_ if _values_ is not *undefined*, and substitutes _default_ if the value is *undefined*.</dd>
</dl>
<emu-alg>
1. Let _value_ be ? Get(_options_, _property_).
1. If _value_ is *undefined*, then
1. If _default_ is ~required~, throw a *RangeError* exception.
1. Return _default_.
1. If _type_ is *"boolean"*, then
1. Set _value_ to ToBoolean(_value_).
1. Else if _type_ is *"number"*, then
1. Set _value_ to ? ToNumber(_value_).
1. If _value_ is *NaN*, throw a *RangeError* exception.
1. Else,
1. Assert: _type_ is *"string"*.
1. Set _value_ to ? ToString(_value_).
1. If _values_ is not *undefined* and _values_ does not contain an element equal to _value_, throw a *RangeError* exception.
1. Return _value_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-totemporaloverflow" aoid="ToTemporalOverflow">
<h1>ToTemporalOverflow ( _options_ )</h1>
<emu-alg>
1. If _options_ is *undefined*, return *"constrain"*.
1. Return ? GetOption(_options_, *"overflow"*, *"string"*, « *"constrain"*, *"reject"* », *"constrain"*).
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-totemporaldisambiguation" aoid="ToTemporalDisambiguation">
<h1>ToTemporalDisambiguation ( _options_ )</h1>
<emu-alg>
1. If _options_ is *undefined*, return *"compatible"*.
1. Return ? GetOption(_options_, *"disambiguation"*, *"string"*, « *"compatible"*, *"earlier"*, *"later"*, *"reject"* », *"compatible"*).
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-totemporalroundingmode" aoid="ToTemporalRoundingMode">
<h1>ToTemporalRoundingMode ( _normalizedOptions_, _fallback_ )</h1>
<p>
The abstract operation ToTemporalRoundingMode extracts the value of the property named *"roundingMode"* from _normalizedOptions_ and makes sure it is a valid value for the option.
The value _fallback_ is returned if the property is not present.
</p>
<emu-note type="editor">
<p>
The rounding modes accepted by this abstract operation (and therefore in the Temporal API) are intended to be the same as whatever is eventually standardized in the <a href="https://github.com/tc39/proposal-intl-numberformat-v3">Intl.NumberFormat V3</a> proposal.
</p>
</emu-note>
<emu-alg>
1. Return ? GetOption(_normalizedOptions_, *"roundingMode"*, *"string"*, « *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, *"halfEven"* », _fallback_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-negatetemporalroundingmode" aoid="NegateTemporalRoundingMode">
<h1>NegateTemporalRoundingMode ( _roundingMode_ )</h1>
<p>
The abstract operation NegateTemporalRoundingMode returns the correct rounding mode to use when rounding the negative of a value that was originally given with _roundingMode_.
</p>
<emu-note type="editor">
<p>
The rounding modes accepted by this abstract operation (and therefore in the Temporal API) are intended to be the same as whatever is eventually standardized in the <a href="https://github.com/tc39/proposal-intl-numberformat-v3">Intl.NumberFormat V3</a> proposal.
</p>
</emu-note>
<emu-alg>
1. If _roundingMode_ is *"ceil"*, return *"floor"*.
1. If _roundingMode_ is *"floor"*, return *"ceil"*.
1. If _roundingMode_ is *"halfCeil"*, return *"halfFloor"*.
1. If _roundingMode_ is *"halfFloor"*, return *"halfCeil"*.
1. Return _roundingMode_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-totemporaloffset" aoid="ToTemporalOffset">
<h1>ToTemporalOffset ( _options_, _fallback_ )</h1>
<p>
The abstract operation ToTemporalOffset extracts the value of the property named *"offset"* from _options_ and makes sure it is a valid value for the option.
The value _fallback_ is returned if the property is not present.
</p>
<emu-alg>
1. If _options_ is *undefined*, return _fallback_.
1. Return ? GetOption(_options_, *"offset"*, *"string"*, « *"prefer"*, *"use"*, *"ignore"*, *"reject"* », _fallback_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-tocalendarnameoption" type="abstract operation">
<h1>
ToCalendarNameOption (
_normalizedOptions_: an Object,
): either a normal completion containing a String, or an abrupt completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>It extracts the value of the property named *"calendarName"* from _normalizedOptions_ and makes sure it is a valid value for the option.</dd>
</dl>
<emu-note>
This property is used in `toString` methods in Temporal to control whether a calendar annotation should be output.
</emu-note>
<emu-alg>
1. Return ? GetOption(_normalizedOptions_, *"calendarName"*, *"string"*, « *"auto"*, *"always"*, *"never"*, *"critical"* », *"auto"*).
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-totimezonenameoption" type="abstract operation">
<h1>
ToTimeZoneNameOption (
_normalizedOptions_: an Object,
): either a normal completion containing a String, or an abrupt completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>It extracts the value of the property named *"timeZoneName"* from _normalizedOptions_ and makes sure it is a valid value for the option.</dd>
</dl>
<emu-note>
This property is used in `Temporal.ZonedDateTime.prototype.toString()`.
It is different from the `timeZone` property passed to `Temporal.ZonedDateTime.from()` and from the `timeZone` property in the options passed to `Temporal.Instant.prototype.toString()`.
</emu-note>
<emu-alg>
1. Return ? GetOption(_normalizedOptions_, *"timeZoneName"*, *"string"*, « *"auto"*, *"never"*, *"critical"* », *"auto"*).
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-toshowoffsetoption" aoid="ToShowOffsetOption">
<h1>ToShowOffsetOption ( _normalizedOptions_ )</h1>
<p>
The abstract operation ToShowOffsetOption extracts the value of the property named *"offset"* from _normalizedOptions_ and makes sure it is a valid value for the option.
</p>
<emu-note>
This property is used in `Temporal.ZonedDateTime.prototype.toString()`.
It is different from the `offset` property passed to `Temporal.ZonedDateTime.from()`.
</emu-note>
<emu-alg>
1. Return ? GetOption(_normalizedOptions_, *"offset"*, *"string"*, « *"auto"*, *"never"* », *"auto"*).
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-totemporalroundingincrement" type="abstract operation">
<h1>
ToTemporalRoundingIncrement (
_normalizedOptions_: an Object,
): either a normal completion containing a positive integer, or an abrupt completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>
It extracts the value of the property named *"roundingIncrement"* from _normalizedOptions_, makes sure it represents a finite number greater than or equal to 1, and returns that value truncated to an integer.
</dd>
</dl>
<emu-alg>
1. Let _increment_ be ? GetOption(_normalizedOptions_, *"roundingIncrement"*, *"number"*, *undefined*, *1*<sub>𝔽</sub>).
1. If _increment_ is not finite, throw a *RangeError* exception.
1. If _increment_ < *1*<sub>𝔽</sub>, throw a *RangeError* exception.
1. Return truncate(ℝ(_increment_)).
</emu-alg>
</emu-clause>
<emu-clause id="sec-validatetemporalroundingincrement" type="abstract operation">
<h1>
ValidateTemporalRoundingIncrement (
_increment_: a positive integer,
_dividend_: a positive integer,
_inclusive_: a Boolean,
): either a normal completion containing ~unused~, or an abrupt completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>
It verifies that _increment_ evenly divides _dividend_, otherwise throwing a *RangeError*.
_dividend_ must be divided into more than one part unless _inclusive_ is *true*.
</dd>
</dl>
<emu-alg>
1. If _inclusive_ is *true*, then
1. Let _maximum_ be _dividend_.
1. Else,
1. Assert: _dividend_ > 1.
1. Let _maximum_ be _dividend_ - 1.
1. If _increment_ > _maximum_, throw a *RangeError* exception.
1. If _dividend_ modulo _increment_ ≠ 0, then
1. Throw a *RangeError* exception.
1. Return ~unused~.
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-tofractionalseconddigits" type="abstract operation">
<h1>
ToFractionalSecondDigits (
_normalizedOptions_: an Object,
): either a normal completion containing either an integer or *"auto"*, or an abrupt completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>It extracts the value of the property named *"fractionalSecondDigits"* from _normalizedOptions_ and makes sure it is a valid value for the option.</dd>
</dl>
<emu-alg>
1. Let _digitsValue_ be ? Get(_normalizedOptions_, *"fractionalSecondDigits"*).
1. If _digitsValue_ is *undefined*, return *"auto"*.
1. If _digitsValue_ is not a Number, then
1. If ? ToString(_digitsValue_) is not *"auto"*, throw a *RangeError* exception.
1. Return *"auto"*.
1. If _digitsValue_ is *NaN*, *+∞*<sub>𝔽</sub>, or *-∞*<sub>𝔽</sub>, throw a *RangeError* exception.
1. Let _digitCount_ be floor(ℝ(_digitsValue_)).
1. If _digitCount_ < 0 or _digitCount_ > 9, throw a *RangeError* exception.
1. Return _digitCount_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-tosecondsstringprecisionrecord" type="abstract operation">
<h1>
ToSecondsStringPrecisionRecord (
_smallestUnit_: one of *"minute"*, *"second"*, *"millisecond"*, *"microsecond"*, *"nanosecond"*, or *undefined*,
_fractionalDigitCount_: either *"auto"* or an integer in the inclusive range 0 to 9,
): a Record with fields [[Precision]] (one of *"minute"*, *"auto"*, or an integer in the inclusive range 0 to 9), [[Unit]] (one of *"minute"*, *"second"*, *"millisecond"*, *"microsecond"*, or *"nanosecond"*), and [[Increment]] (one of 1, 10, or 100)
</h1>
<dl class="header">
<dt>description</dt>
<dd>
The returned Record represents details for serializing minutes and seconds to a string subject to the specified _smallestUnit_ or (when _smallestUnit_ is *undefined*) _fractionalDigitCount_ digits after the decimal point in the seconds.
Its [[Precision]] field is either that count of digits, the string *"auto"* signifying that there should be no insignificant trailing zeroes, or the string *"minute"* signifying that seconds should not be included at all.
Its [[Unit]] field is the most precise unit that can contribute to the string, and its [[Increment]] field indicates the rounding increment that should be applied to that unit.
</dd>
</dl>
<emu-alg>
1. If _smallestUnit_ is *"minute"*, then
1. Return the Record {
[[Precision]]: *"minute"*,
[[Unit]]: *"minute"*,
[[Increment]]: 1
}.
1. If _smallestUnit_ is *"second"*, then
1. Return the Record {
[[Precision]]: 0,
[[Unit]]: *"second"*,
[[Increment]]: 1
}.
1. If _smallestUnit_ is *"millisecond"*, then
1. Return the Record {
[[Precision]]: 3,
[[Unit]]: *"millisecond"*,
[[Increment]]: 1
}.
1. If _smallestUnit_ is *"microsecond"*, then
1. Return the Record {
[[Precision]]: 6,
[[Unit]]: *"microsecond"*,
[[Increment]]: 1
}.
1. If _smallestUnit_ is *"nanosecond"*, then
1. Return the Record {
[[Precision]]: 9,
[[Unit]]: *"nanosecond"*,
[[Increment]]: 1
}.
1. Assert: _smallestUnit_ is *undefined*.
1. If _fractionalDigitCount_ is *"auto"*, then
1. Return the Record {
[[Precision]]: *"auto"*,
[[Unit]]: *"nanosecond"*,
[[Increment]]: 1
}.
1. If _fractionalDigitCount_ is 0, then
1. Return the Record {
[[Precision]]: 0,
[[Unit]]: *"second"*,
[[Increment]]: 1
}.
1. If _fractionalDigitCount_ is 1, 2, or 3, then
1. Return the Record {
[[Precision]]: _fractionalDigitCount_,
[[Unit]]: *"millisecond"*,
[[Increment]]: 10<sup>3 - _fractionalDigitCount_</sup>
}.
1. If _fractionalDigitCount_ is 4, 5, or 6, then
1. Return the Record {
[[Precision]]: _fractionalDigitCount_,
[[Unit]]: *"microsecond"*,
[[Increment]]: 10<sup>6 - _fractionalDigitCount_</sup>
}.
1. Assert: _fractionalDigitCount_ is 7, 8, or 9.
1. Return the Record {
[[Precision]]: _fractionalDigitCount_,
[[Unit]]: *"nanosecond"*,
[[Increment]]: 10<sup>9 - _fractionalDigitCount_</sup>
}.
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-gettemporalunit" type="abstract operation">
<h1>
GetTemporalUnit (
_normalizedOptions_: an Object,
_key_: a property key,
_unitGroup_: ~date~, ~time~, or ~datetime~,
_default_: ~required~ or an ECMAScript language value,
optional _extraValues_: a List of ECMAScript language values,
): either a normal completion containing an ECMAScript language value, or an abrupt completion
</h1>
<dl class="header">
<dt>description</dt>
<dd>It attempts to read from the specified property of _normalizedOptions_ a Temporal unit that is <emu-not-ref>covered</emu-not-ref> by the union of _unitGroup_ and _extraValues_, substituting _default_ if the property value is *undefined*.</dd>
</dl>
<p>
Both singular and plural unit names are accepted, but only the singular form is used internally.
</p>
<emu-alg>
1. Let _singularNames_ be a new empty List.
1. For each row of <emu-xref href="#table-temporal-units"></emu-xref>, except the header row, in table order, do
1. Let _unit_ be the value in the Singular column of the row.
1. If the Category column of the row is ~date~ and _unitGroup_ is ~date~ or ~datetime~, append _unit_ to _singularNames_.
1. Else if the Category column of the row is ~time~ and _unitGroup_ is ~time~ or ~datetime~, append _unit_ to _singularNames_.
1. If _extraValues_ is present, then
1. Set _singularNames_ to the list-concatenation of _singularNames_ and _extraValues_.
1. If _default_ is ~required~, then
1. Let _defaultValue_ be *undefined*.
1. Else,
1. Let _defaultValue_ be _default_.
1. If _defaultValue_ is not *undefined* and _singularNames_ does not contain _defaultValue_, then
1. Append _defaultValue_ to _singularNames_.
1. Let _allowedValues_ be a copy of _singularNames_.
1. For each element _singularName_ of _singularNames_, do
1. If _singularName_ is listed in the Singular column of <emu-xref href="#table-temporal-units"></emu-xref>, then
1. Let _pluralName_ be the value in the Plural column of the corresponding row.
1. Append _pluralName_ to _allowedValues_.
1. NOTE: For each singular Temporal unit name that is contained within _allowedValues_, the corresponding plural name is also contained within it.
1. Let _value_ be ? GetOption(_normalizedOptions_, _key_, *"string"*, _allowedValues_, _defaultValue_).
1. If _value_ is *undefined* and _default_ is ~required~, throw a *RangeError* exception.
1. If _value_ is listed in the Plural column of <emu-xref href="#table-temporal-units"></emu-xref>, then
1. Set _value_ to the value in the Singular column of the corresponding row.
1. Return _value_.
</emu-alg>
<emu-table id="table-temporal-units">
<emu-caption>Temporal units by descending magnitude</emu-caption>
<table class="real-table">
<thead>
<tr>
<th>Singular</th>
<th>Plural</th>
<th>Category</th>
</tr>
</thead>
<tbody>
<tr>
<td>*"year"*</td>
<td>*"years"*</td>
<td>~date~</td>
</tr>
<tr>
<td>*"month"*</td>
<td>*"months"*</td>
<td>~date~</td>
</tr>
<tr>
<td>*"week"*</td>
<td>*"weeks"*</td>
<td>~date~</td>
</tr>
<tr>
<td>*"day"*</td>
<td>*"days"*</td>
<td>~date~</td>
</tr>
<tr>
<td>*"hour"*</td>
<td>*"hours"*</td>
<td>~time~</td>
</tr>
<tr>
<td>*"minute"*</td>
<td>*"minutes"*</td>
<td>~time~</td>
</tr>
<tr>
<td>*"second"*</td>
<td>*"seconds"*</td>
<td>~time~</td>
</tr>
<tr>
<td>*"millisecond"*</td>
<td>*"milliseconds"*</td>
<td>~time~</td>
</tr>
<tr>
<td>*"microsecond"*</td>
<td>*"microseconds"*</td>
<td>~time~</td>
</tr>
<tr>
<td>*"nanosecond"*</td>
<td>*"nanoseconds"*</td>
<td>~time~</td>
</tr>
</tbody>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-temporal-torelativetemporalobject" aoid="ToRelativeTemporalObject">
<h1>ToRelativeTemporalObject ( _options_ )</h1>
<p>
The abstract operation ToRelativeTemporalObject examines the value of the `relativeTo` property of its _options_ argument.
If this is not present, it returns *undefined*.
Otherwise, it attempts to return a Temporal.ZonedDateTime instance or Temporal.PlainDate instance, in order of preference, by converting the value.
If neither of those are possible, the operation throws a *RangeError*.
</p>
<emu-alg>
1. Assert: Type(_options_) is Object.
1. Let _value_ be ? Get(_options_, *"relativeTo"*).
1. If _value_ is *undefined*, then
1. Return _value_.
1. Let _offsetBehaviour_ be ~option~.
1. Let _matchBehaviour_ be ~match exactly~.
1. If Type(_value_) is Object, then
1. If _value_ has either an [[InitializedTemporalDate]] or [[InitializedTemporalZonedDateTime]] internal slot, then
1. Return _value_.
1. If _value_ has an [[InitializedTemporalDateTime]] internal slot, then
1. Return ! CreateTemporalDate(_value_.[[ISOYear]], _value_.[[ISOMonth]], _value_.[[ISODay]], _value_.[[Calendar]]).
1. Let _calendar_ be ? GetTemporalCalendarWithISODefault(_value_).
1. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"day"*, *"hour"*, *"microsecond"*, *"millisecond"*, *"minute"*, *"month"*, *"monthCode"*, *"nanosecond"*, *"second"*, *"year"* »).
1. Append *"timeZone"* to _fieldNames_.
1. Append *"offset"* to _fieldNames_.
1. Let _fields_ be ? PrepareTemporalFields(_value_, _fieldNames_, «»).
1. Let _dateOptions_ be OrdinaryObjectCreate(*null*).
1. Perform ! CreateDataPropertyOrThrow(_dateOptions_, *"overflow"*, *"constrain"*).
1. Let _result_ be ? InterpretTemporalDateTimeFields(_calendar_, _fields_, _dateOptions_).
1. Let _offsetString_ be ! Get(_fields_, *"offset"*).
1. Let _timeZone_ be ! Get(_fields_, *"timeZone"*).
1. If _timeZone_ is not *undefined*, then
1. Set _timeZone_ to ? ToTemporalTimeZone(_timeZone_).
1. If _offsetString_ is *undefined*, then
1. Set _offsetBehaviour_ to ~wall~.
1. Else,
1. Let _string_ be ? ToString(_value_).
1. Let _result_ be ? ParseTemporalRelativeToString(_string_).
1. Let _calendar_ be ? ToTemporalCalendarWithISODefault(_result_.[[Calendar]]).
1. Let _offsetString_ be _result_.[[TimeZone]].[[OffsetString]].
1. Let _timeZoneName_ be _result_.[[TimeZone]].[[Name]].
1. If _timeZoneName_ is *undefined*, then
1. Let _timeZone_ be *undefined*.
1. Else,
1. If IsTimeZoneOffsetString(_timeZoneName_) is *false*, then
1. If IsAvailableTimeZoneName(_timeZoneName_) is *false*, throw a *RangeError* exception.
1. Set _timeZoneName_ to ! CanonicalizeTimeZoneName(_timeZoneName_).
1. Let _timeZone_ be ! CreateTemporalTimeZone(_timeZoneName_).
1. If _result_.[[TimeZone]].[[Z]] is *true*, then
1. Set _offsetBehaviour_ to ~exact~.
1. Else if _offsetString_ is *undefined*, then
1. Set _offsetBehaviour_ to ~wall~.
1. Set _matchBehaviour_ to ~match minutes~.
1. If _timeZone_ is *undefined*, then
1. Return ? CreateTemporalDate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _calendar_).
1. If _offsetBehaviour_ is ~option~, then
1. If IsTimeZoneOffsetString(_offsetString_) is *false*, throw a *RangeError* exception.
1. Let _offsetNs_ be ParseTimeZoneOffsetString(_offsetString_).
1. Else,
1. Let _offsetNs_ be 0.
1. Let _epochNanoseconds_ be ? InterpretISODateTimeOffset(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]], _offsetBehaviour_, _offsetNs_, _timeZone_, *"compatible"*, *"reject"*, _matchBehaviour_).
1. Return ! CreateTemporalZonedDateTime(_epochNanoseconds_, _timeZone_, _calendar_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-largeroftwotemporalunits" aoid="LargerOfTwoTemporalUnits">
<h1>LargerOfTwoTemporalUnits ( _u1_, _u2_ )</h1>
<p>
The abstract operation LargerOfTwoTemporalUnits, given two strings representing Temporal units, returns the string representing the larger of the two units.
</p>
<emu-alg>
1. Assert: Both _u1_ and _u2_ are listed in the Singular column of <emu-xref href="#table-temporal-units"></emu-xref>.
1. For each row of <emu-xref href="#table-temporal-units"></emu-xref>, except the header row, in table order, do
1. Let _unit_ be the value in the Singular column of the row.
1. If SameValue(_u1_, _unit_) is *true*, return _unit_.
1. If SameValue(_u2_, _unit_) is *true*, return _unit_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-maximumtemporaldurationroundingincrement" aoid="MaximumTemporalDurationRoundingIncrement">
<h1>MaximumTemporalDurationRoundingIncrement ( _unit_ )</h1>
<emu-alg>
1. If _unit_ is *"year"*, *"month"*, *"week"*, or *"day"*, then
1. Return *undefined*.
1. If _unit_ is *"hour"*, then
1. Return 24.
1. If _unit_ is *"minute"* or *"second"*, then
1. Return 60.
1. Assert: _unit_ is one of *"millisecond"*, *"microsecond"*, or *"nanosecond"*.
1. Return 1000.
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-rejectobjectwithcalendarortimezone" aoid="RejectObjectWithCalendarOrTimeZone">
<h1>RejectObjectWithCalendarOrTimeZone ( _object_ )</h1>
<p>
The abstract operation RejectObjectWithCalendarOrTimeZone throws an exception if its argument _object_ is an instance of one of the Temporal types that carries a calendar or time zone, or is an object that has a `calendar` or `timeZone` property.
</p>
<emu-alg>
1. Assert: Type(_object_) is Object.
1. If _object_ has an [[InitializedTemporalDate]], [[InitializedTemporalDateTime]], [[InitializedTemporalMonthDay]], [[InitializedTemporalTime]], [[InitializedTemporalYearMonth]], or [[InitializedTemporalZonedDateTime]] internal slot, then
1. Throw a *TypeError* exception.
1. Let _calendarProperty_ be ? Get(_object_, *"calendar"*).
1. If _calendarProperty_ is not *undefined*, then
1. Throw a *TypeError* exception.
1. Let _timeZoneProperty_ be ? Get(_object_, *"timeZone"*).
1. If _timeZoneProperty_ is not *undefined*, then
1. Throw a *TypeError* exception.
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-formatsecondsstringpart" aoid="FormatSecondsStringPart">
<h1>FormatSecondsStringPart ( _second_, _millisecond_, _microsecond_, _nanosecond_, _precision_ )</h1>
<emu-alg>
1. Assert: _second_, _millisecond_, _microsecond_, and _nanosecond_ are integers.
1. If _precision_ is *"minute"*, return *""*.
1. Let _secondsString_ be the string-concatenation of the code unit 0x003A (COLON) and ToZeroPaddedDecimalString(_second_, 2).
1. Let _fraction_ be _millisecond_ × 10<sup>6</sup> + _microsecond_ × 10<sup>3</sup> + _nanosecond_.
1. If _precision_ is *"auto"*, then
1. If _fraction_ is 0, return _secondsString_.
1. Set _fraction_ to ToZeroPaddedDecimalString(_fraction_, 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. Else,
1. If _precision_ is 0, return _secondsString_.
1. Set _fraction_ to ToZeroPaddedDecimalString(_fraction_, 9).
1. Set _fraction_ to the substring of _fraction_ from 0 to _precision_.
1. Return the string-concatenation of _secondsString_, the code unit 0x002E (FULL STOP), and _fraction_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-temporal-getunsignedroundingmode" type="abstract operation">
<h1>
GetUnsignedRoundingMode (
_roundingMode_: *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, or *"halfEven"*,
_isNegative_: *true* or *false*,
): ~zero~, ~infinity~, ~half-zero~, ~half-infinity~, or ~half-even~
</h1>
<dl class="header">
<dt>description</dt>
<dd>
The return value is the rounding mode that should be applied to the absolute value of a number to produce the same result as if _roundingMode_ were applied to the signed value of the number (negative if _isNegative_ is *true*, or positive otherwise).
</dd>
</dl>
<emu-alg>
1. If _isNegative_ is *true*, return the specification type in the third column of <emu-xref href="#table-temporal-unsigned-rounding-modes"></emu-xref> where the first column is _roundingMode_ and the second column is "negative".
1. Else, return the specification type in the third column of <emu-xref href="#table-temporal-unsigned-rounding-modes"></emu-xref> where the first column is _roundingMode_ and the second column is "positive".
</emu-alg>
<emu-note type="editor">
<p>This operation is intended to be the same one as in the <a href="https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/diff.html#sec-getunsignedroundingmode">Intl.NumberFormat v3</a> proposal.</p>
</emu-note>
<emu-table id="table-temporal-unsigned-rounding-modes">
<emu-caption>Conversion from rounding mode to unsigned rounding mode</emu-caption>
<table class="real-table">
<thead>
<tr>
<th>Identifier</th>
<th>Sign</th>
<th>Unsigned Rounding Mode</th>
</tr>
</thead>
<tr>
<td rowspan="2">*"ceil"*</td>
<td>positive</td>
<td>~infinity~</td>
</tr>
<tr>
<td>negative</td>
<td>~zero~</td>
</tr>
<tr>
<td rowspan="2">*"floor"*</td>
<td>positive</td>
<td>~zero~</td>
</tr>
<tr>
<td>negative</td>
<td>~infinity~</td>
</tr>
<tr>
<td rowspan="2">*"expand"*</td>
<td>positive</td>
<td>~infinity~</td>
</tr>
<tr>
<td>negative</td>
<td>~infinity~</td>
</tr>
<tr>
<td rowspan="2">*"trunc"*</td>
<td>positive</td>
<td>~zero~</td>
</tr>
<tr>
<td>negative</td>
<td>~zero~</td>
</tr>
<tr>
<td rowspan="2">*"halfCeil"*</td>
<td>positive</td>
<td>~half-infinity~</td>
</tr>
<tr>
<td>negative</td>
<td>~half-zero~</td>
</tr>
<tr>
<td rowspan="2">*"halfFloor"*</td>
<td>positive</td>
<td>~half-zero~</td>
</tr>
<tr>
<td>negative</td>
<td>~half-infinity~</td>
</tr>
<tr>
<td rowspan="2">*"halfExpand"*</td>
<td>positive</td>
<td>~half-infinity~</td>
</tr>
<tr>
<td>negative</td>
<td>~half-infinity~</td>
</tr>
<tr>
<td rowspan="2">*"halfTrunc"*</td>
<td>positive</td>
<td>~half-zero~</td>
</tr>
<tr>
<td>negative</td>
<td>~half-zero~</td>
</tr>
<tr>
<td rowspan="2">*"halfEven"*</td>
<td>positive</td>
<td>~half-even~</td>
</tr>
<tr>
<td>negative</td>
<td>~half-even~</td>
</tr>
</table>
</emu-table>
</emu-clause>
<emu-clause id="sec-temporal-applyunsignedroundingmode" type="abstract operation">
<h1>
ApplyUnsignedRoundingMode (
_x_: a mathematical value,
_r1_: a mathematical value,
_r2_: a mathematical value,
_unsignedRoundingMode_: ~zero~, ~infinity~, ~half-zero~, ~half-infinity~, ~half-even~, or *undefined*,
): a mathematical value
</h1>
<dl class="header">
<dt>description</dt>
<dd>
It considers _x_, bracketed below by _r1_ and above by _r2_, and returns either _r1_ or _r2_ according to _unsignedRoundingMode_.
</dd>
</dl>
<emu-alg>
1. If _x_ is equal to _r1_, return _r1_.
1. Assert: _r1_ < _x_ < _r2_.
1. Assert: _unsignedRoundingMode_ is not *undefined*.
1. If _unsignedRoundingMode_ is ~zero~, return _r1_.
1. If _unsignedRoundingMode_ is ~infinity~, return _r2_.
1. Let _d1_ be <emu-eqn>_x_ – _r1_</emu-eqn>.
1. Let _d2_ be <emu-eqn>_r2_ – _x_</emu-eqn>.
1. If _d1_ < _d2_, return _r1_.
1. If _d2_ < _d1_, return _r2_.
1. Assert: _d1_ is equal to _d2_.
1. If _unsignedRoundingMode_ is ~half-zero~, return _r1_.
1. If _unsignedRoundingMode_ is ~half-infinity~, return _r2_.
1. Assert: _unsignedRoundingMode_ is ~half-even~.
1. Let _cardinality_ be <emu-eqn>(_r1_ / (_r2_ – _r1_)) modulo 2</emu-eqn>.
1. If _cardinality_ is 0, return _r1_.
1. Return _r2_.
</emu-alg>
<emu-note type="editor">
<p>This operation is intended to be the same one as in the <a href="https://tc39.es/proposal-intl-numberformat-v3/out/numberformat/diff.html#sec-applyunsignedroundingmode">Intl.NumberFormat v3</a> proposal.</p>
</emu-note>
</emu-clause>
<emu-clause id="sec-temporal-roundnumbertoincrement" type="abstract operation">
<h1>
RoundNumberToIncrement (
_x_: a mathematical value,
_increment_: an integer,
_roundingMode_: *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, or *"halfEven"*,
): an integer
</h1>
<dl class="header">
<dt>description</dt>
<dd>It rounds _x_ to the nearest multiple of _increment_, up or down according to _roundingMode_.</dd>
</dl>
<emu-alg>
1. Let _quotient_ be _x_ / _increment_.
1. If _quotient_ < 0, then
1. Let _isNegative_ be *true*.
1. Set _quotient_ to -_quotient_.
1. Else,
1. Let _isNegative_ be *false*.
1. Let _unsignedRoundingMode_ be GetUnsignedRoundingMode(_roundingMode_, _isNegative_).
1. Let _r1_ be the largest integer such that _r1_ ≤ _quotient_.
1. Let _r2_ be the smallest integer such that _r2_ > _quotient_.
1. Let _rounded_ be ApplyUnsignedRoundingMode(_quotient_, _r1_, _r2_, _unsignedRoundingMode_).
1. If _isNegative_ is *true*, set _rounded_ to -_rounded_.
1. Return _rounded_ × _increment_.
</emu-alg>
<emu-note type="editor">
<p>
The rounding modes accepted by this abstract operation are intended to be the same as whatever is eventually standardized in the <a href="https://github.com/tc39/proposal-intl-numberformat-v3">Intl.NumberFormat V3</a> proposal.
</p>
</emu-note>
</emu-clause>
<emu-clause id="sec-temporal-roundnumbertoincrementasifpositive" type="abstract operation">
<h1>
RoundNumberToIncrementAsIfPositive (
_x_: a mathematical value,
_increment_: an integer,
_roundingMode_: *"ceil"*, *"floor"*, *"expand"*, *"trunc"*, *"halfCeil"*, *"halfFloor"*, *"halfExpand"*, *"halfTrunc"*, or *"halfEven"*,
): an integer
</h1>
<dl class="header">
<dt>description</dt>
<dd>
It rounds _x_ to the nearest multiple of _increment_, up or down according to _roundingMode_, but always as if _x_ were positive.
For example, *"floor"* and *"trunc"* behave identically.
This is used when rounding exact times, where "rounding down" conceptually always means towards the beginning of time, even if the time is expressed as a negative amount of time relative to an epoch.
</dd>
</dl>
<emu-alg>
1. Let _quotient_ be _x_ / _increment_.
1. Let _unsignedRoundingMode_ be GetUnsignedRoundingMode(_roundingMode_, *false*).
1. Let _r1_ be the largest integer such that _r1_ ≤ _quotient_.
1. Let _r2_ be the smallest integer such that _r2_ > _quotient_.
1. Let _rounded_ be ApplyUnsignedRoundingMode(_quotient_, _r1_, _r2_, _unsignedRoundingMode_).
1. Return _rounded_ × _increment_.
</emu-alg>
<emu-note type="editor">
<p>
The rounding modes accepted by this abstract operation are intended to be the same as whatever is eventually standardized in the <a href="https://github.com/tc39/proposal-intl-numberformat-v3">Intl.NumberFormat V3</a> proposal.
</p>
</emu-note>
</emu-clause>
<emu-clause id="sec-temporal-iso8601grammar">
<h1>ISO 8601 grammar</h1>
<p>
Several operations in this section are intended to parse ISO 8601 strings representing a date, a time, a duration, or a combined date and time.
For the purposes of these operations, a valid ISO 8601 string is defined as a string that can be generated by one of the goal elements of the following grammar.
</p>
<p>
This grammar is adapted from the ABNF grammar of ISO 8601 that is given in appendix A of <a href="https://tools.ietf.org/html/rfc3339#appendix-A">RFC 3339</a>, augmented with the grammar of annotations in section 3.1 of <a href="https://datatracker.ietf.org/doc/html/draft-ietf-sedate-datetime-extended#section-3.1">Date and Time on the Internet: Timestamps with additional information</a>
</p>
<p>
The grammar deviates from the standard given in ISO 8601 in the following ways:
</p>
<ul>
<li>Only the calendar date format is supported, not the weekdate or ordinal date format.</li>
<li>Two-digit years are disallowed.</li>
<li><a href="https://tc39.es/ecma262/#sec-expanded-years">Expanded Years</a> of 6 digits are allowed.</li>
<li>Fractional parts may have 1 through 9 decimal places.</li>
<li>In time representations, only seconds are allowed to have a fractional part.</li>
<li>In duration representations, only hours, minutes, and seconds are allowed to have a fractional part.</li>
<li>Any number of conforming <a href="https://datatracker.ietf.org/doc/html/draft-ietf-sedate-datetime-extended#section-3.1">suffixes in square brackets</a> are allowed.</li>
<li>
Time zone and <a href="https://tools.ietf.org/html/bcp47#section-2.1">BCP 47 calendar</a> suffixes are the only recognized ones.
Others are ignored, unless they are marked with a *!*, in which case they are rejected.
</li>
<li>A space may be used to separate the date and time in a combined date / time representation, but not in a duration.</li>
<li>Alphabetic designators may be in lower or upper case.</li>
<li>Period or comma may be used as the decimal separator.</li>
<li>A time zone offset of *"-00:00"* is allowed, and means the same thing as *"+00:00"*.</li>
<li>
In a combined representation, combinations of date, time, and time zone offset with Basic (no `-` or `:` separators) and Extended (with `-` or `:` separators) formatting are allowed.
(The date, time, and time zone offset must each be fully in Basic format or Extended format.)
</li>
<li>
When parsing a date representation for a Temporal.PlainMonthDay, the year may be omitted.
The year may optionally be replaced by *"--"* as in RFC 3339.
</li>
<li>When parsing a date representation without a day for a Temporal.PlainYearMonth, the expression is allowed to be in Basic format.</li>
<li>A duration specifier of *"W"* (weeks) can be combined with any of the other specifiers.</li>
<li>Anything else described by the standard as requiring mutual agreement between communicating parties, is disallowed.</li>
</ul>
<emu-grammar type="definition">
Alpha : one of
`A` `B` `C` `D` `E` `F` `G` `H` `I` `J` `K` `L` `M`
`N` `O` `P` `Q` `R` `S` `T` `U` `V` `W` `X` `Y` `Z`
`a` `b` `c` `d` `e` `f` `g` `h` `i` `j` `k` `l` `m`
`n` `o` `p` `q` `r` `s` `t` `u` `v` `w` `x` `y` `z`
LowercaseAlpha : one of
`a` `b` `c` `d` `e` `f` `g` `h` `i` `j` `k` `l` `m`
`n` `o` `p` `q` `r` `s` `t` `u` `v` `w` `x` `y` `z`
ASCIISign : one of
`+` `-`
Sign :
ASCIISign
U+2212
UnpaddedHour :
DecimalDigit
`1` DecimalDigit
`20`
`21`
`22`
`23`
Hour :
`0` DecimalDigit
`1` DecimalDigit
`20`
`21`
`22`
`23`
MinuteSecond :
`0` DecimalDigit
`1` DecimalDigit
`2` DecimalDigit
`3` DecimalDigit
`4` DecimalDigit
`5` DecimalDigit
DecimalSeparator : one of
`.` `,`
DaysDesignator : one of
`D` `d`
HoursDesignator : one of
`H` `h`
MinutesDesignator : one of
`M` `m`
MonthsDesignator : one of
`M` `m`
DurationDesignator : one of
`P` `p`
SecondsDesignator : one of
`S` `s`
DateTimeSeparator :
<SP>
`T`
`t`
TimeDesignator : one of
`T` `t`
WeeksDesignator : one of
`W` `w`
YearsDesignator : one of
`Y` `y`
UTCDesignator : one of
`Z` `z`
AnnotationCriticalFlag :
`!`
DateFourDigitYear :
DecimalDigit DecimalDigit DecimalDigit DecimalDigit
DateExtendedYear :
Sign DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit
DateYear :
DateFourDigitYear
DateExtendedYear
DateMonth :
`0` NonZeroDigit
`10`
`11`
`12`
DateMonthWithThirtyOneDays : one of
`01` `03` `05` `07` `08` `10` `12`
DateDay :
`0` NonZeroDigit
`1` DecimalDigit
`2` DecimalDigit
`30`
`31`
DateSpecYearMonth :
DateYear `-`? DateMonth
TwoDashes :
`--`
DateSpecMonthDay :
TwoDashes? DateMonth `-`? DateDay
ValidMonthDay :
DateMonth `-`? `0` NonZeroDigit
DateMonth `-`? `1` DecimalDigit
DateMonth `-`? `2` DecimalDigit
DateMonth `-`? `30` but not one of `0230` or `02-30`
DateMonthWithThirtyOneDays `-`? `31`
Date :
DateYear `-` DateMonth `-` DateDay
DateYear DateMonth DateDay
TimeHour :
Hour
TimeMinute :
MinuteSecond
TimeSecond :
MinuteSecond
`60`
FractionalPart :
DecimalDigit DecimalDigit? DecimalDigit? DecimalDigit? DecimalDigit? DecimalDigit? DecimalDigit? DecimalDigit? DecimalDigit?
Fraction :
DecimalSeparator FractionalPart
TimeFraction :
Fraction
TimeZoneUTCOffset :
UTCOffset