This repository has been archived by the owner on Jan 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 9
/
spec.emu
1288 lines (1175 loc) · 69.6 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
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">
<link rel="stylesheet" href="./spec.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/github.min.css">
<script src="./spec.js"></script>
<pre class="metadata">
title: Add formatRange and formatRangeToParts to DateTimeFormat
status: proposal
stage: 3
location: https://github.com/tc39/proposal-intl-DateTimeFormat-formatRange
copyright: true
contributors: Google, Ecma International
</pre>
<emu-clause id="datetimeformat-objects">
<h1>DateTimeFormat Objects</h1>
<emu-clause id="sec-datetimeformat-abstracts">
<h1>Abstract Operations For DateTimeFormat Objects</h1>
<p>
Several DateTimeFormat algorithms use values from the following table, which provides internal slots, property names and allowable values for the components of date and time formats:
</p>
<emu-table id="table-datetimeformat-components">
<emu-caption>Components of date and time formats</emu-caption>
<table class="real-table">
<thead>
<tr>
<th>Internal Slot</th>
<th>Property</th>
<th>Values</th>
</tr>
</thead>
<tr>
<td>[[Weekday]]</td>
<td>*"weekday"*</td>
<td>*"narrow"*, *"short"*, *"long"*</td>
</tr>
<tr>
<td>[[Era]]</td>
<td>*"era"*</td>
<td>*"narrow"*, *"short"*, *"long"*</td>
</tr>
<tr>
<td>[[Year]]</td>
<td>*"year"*</td>
<td>*"2-digit"*, *"numeric"*</td>
</tr>
<tr>
<td>[[Month]]</td>
<td>*"month"*</td>
<td>*"2-digit"*, *"numeric"*, *"narrow"*, *"short"*, *"long"*</td>
</tr>
<tr>
<td>[[Day]]</td>
<td>*"day"*</td>
<td>*"2-digit"*, *"numeric"*</td>
</tr>
<tr>
<td>[[DayPeriod]]</td>
<td>*"dayPeriod"*</td>
<td>*"narrow"*, *"short"*, *"long"*</td>
</tr>
<tr>
<td>[[Hour]]</td>
<td>*"hour"*</td>
<td>*"2-digit"*, *"numeric"*</td>
</tr>
<tr>
<td>[[Minute]]</td>
<td>*"minute"*</td>
<td>*"2-digit"*, *"numeric"*</td>
</tr>
<tr>
<td>[[Second]]</td>
<td>*"second"*</td>
<td>*"2-digit"*, *"numeric"*</td>
</tr>
<tr>
<td>[[FractionalSecondDigits]]</td>
<td>*"fractionalSecondDigits"*</td>
<td>*1*, *2*, *3*</td>
</tr>
<tr>
<td>[[TimeZoneName]]</td>
<td>*"timeZoneName"*</td>
<td>*"short"*, *"long"*</td>
</tr>
</table>
</emu-table>
<emu-clause id="sec-initializedatetimeformat" aoid="InitializeDateTimeFormat">
<h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1>
<p>
The abstract operation InitializeDateTimeFormat accepts the arguments _dateTimeFormat_ (which must be an object), _locales_, and _options_. It initializes _dateTimeFormat_ as a DateTimeFormat object. This abstract operation functions as follows:
</p>
<p>
The following algorithm refers to the `type` nonterminal from <a href="https://www.unicode.org/reports/tr35/#Unicode_locale_identifier">UTS 35's Unicode Locale Identifier grammar</a>.
</p>
<emu-alg>
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
1. Let _options_ be ? ToDateTimeOptions(_options_, *"any"*, *"date"*).
1. Let _opt_ be a new Record.
1. Let _matcher_ be ? GetOption(_options_, *"localeMatcher"*, *"string"*, « *"lookup"*, *"best fit"* », *"best fit"*).
1. Set _opt_.[[localeMatcher]] to _matcher_.
1. Let _calendar_ be ? GetOption(_options_, *"calendar"*, *"string"*, *undefined*, *undefined*).
1. If _calendar_ is not *undefined*, then
1. If _calendar_ does not match the Unicode Locale Identifier `type` nonterminal, throw a *RangeError* exception.
1. Set _opt_.[[ca]] to _calendar_.
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. Set _opt_.[[nu]] to _numberingSystem_.
1. Let _hour12_ be ? GetOption(_options_, *"hour12"*, *"boolean"*, *undefined*, *undefined*).
1. Let _hourCycle_ be ? GetOption(_options_, *"hourCycle"*, *"string"*, « *"h11"*, *"h12"*, *"h23"*, *"h24"* », *undefined*).
1. If _hour12_ is not *undefined*, then
1. Let _hourCycle_ be *null*.
1. Set _opt_.[[hc]] to _hourCycle_.
1. Let _localeData_ be %DateTimeFormat%.[[LocaleData]].
1. Let _r_ be ResolveLocale(%DateTimeFormat%.[[AvailableLocales]], _requestedLocales_, _opt_, %DateTimeFormat%.[[RelevantExtensionKeys]], _localeData_).
1. Set _dateTimeFormat_.[[Locale]] to _r_.[[locale]].
1. Let _calendar_ be _r_.[[ca]].
1. Set _dateTimeFormat_.[[Calendar]] to _calendar_.
1. Set _dateTimeFormat_.[[HourCycle]] to _r_.[[hc]].
1. Set _dateTimeFormat_.[[NumberingSystem]] to _r_.[[nu]].
1. Let _dataLocale_ be _r_.[[dataLocale]].
1. Let _timeZone_ be ? Get(_options_, *"timeZone"*).
1. If _timeZone_ is *undefined*, then
1. Let _timeZone_ be DefaultTimeZone().
1. Else,
1. Let _timeZone_ be ? ToString(_timeZone_).
1. If the result of IsValidTimeZoneName(_timeZone_) is *false*, then
1. Throw a *RangeError* exception.
1. Let _timeZone_ be CanonicalizeTimeZoneName(_timeZone_).
1. Set _dateTimeFormat_.[[TimeZone]] to _timeZone_.
1. Let _opt_ be a new Record.
1. For each row of <emu-xref href="#table-datetimeformat-components"></emu-xref>, except the header row, in table order, do
1. Let _prop_ be the name given in the Property column of the row.
1. If _prop_ is *"fractionalSecondDigits"*, then
1. Let _value_ be ? GetNumberOption(options, *"fractionalSecondDigits"*, 1, 3, *undefined*).
1. Else,
1. Let _value_ be ? GetOption(_options_, _prop_, *"string"*, « the strings given in the Values column of the row », *undefined*).
1. Set _opt_.[[<_prop_>]] to _value_.
1. Let _dataLocaleData_ be _localeData_.[[<_dataLocale_>]].
1. Let _matcher_ be ? GetOption(_options_, *"formatMatcher"*, *"string"*, « *"basic"*, *"best fit"* », *"best fit"*).
1. Let _dateStyle_ be ? GetOption(_options_, *"dateStyle"*, *"string"*, « *"full"*, *"long"*, *"medium"*, *"short"* », *undefined*).
1. Set _dateTimeFormat_.[[DateStyle]] to _dateStyle_.
1. Let _timeStyle_ be ? GetOption(_options_, *"timeStyle"*, *"string"*, « *"full"*, *"long"*, *"medium"*, *"short"* », *undefined*).
1. Set _dateTimeFormat_.[[TimeStyle]] to _timeStyle_.
1. If _dateStyle_ is not *undefined* or _timeStyle_ is not *undefined*, then
1. For each row in <emu-xref href="#table-datetimeformat-components"></emu-xref>, except the header row, do
1. Let _prop_ be the name given in the Property column of the row.
1. Let _p_ be _opt_.[[<_prop_>]].
1. If _p_ is not *undefined*, then
1. Throw a *TypeError* exception.
1. Let _bestFormat_ be DateTimeStyleFormat(_dateStyle_, _timeStyle_, _dataLocaleData_).
1. Else,
1. Let _formats_ be _dataLocaleData_.[[formats]].[[<_calendar_>]].
1. If _matcher_ is *"basic"*, then
1. Let _bestFormat_ be BasicFormatMatcher(_opt_, _formats_).
1. Else,
1. Let _bestFormat_ be BestFitFormatMatcher(_opt_, _formats_).
1. For each row in <emu-xref href="#table-datetimeformat-components"></emu-xref>, except the header row, in table order, do
1. Let _prop_ be the name given in the Property column of the row.
1. Let _p_ be _bestFormat_.[[<_prop_>]].
1. If _p_ not *undefined*, then
1. Set _dateTimeFormat_'s internal slot whose name is the Internal Slot column of the row to _p_.
1. If _dateTimeFormat_.[[Hour]] is *undefined*, then
1. Set _dateTimeFormat_.[[HourCycle]] to *undefined*.
1. Let _pattern_ be _bestFormat_.[[pattern]].
1. <ins>Let _rangePatterns_ be _bestFormat_.[[rangePatterns]].</ins>
1. Else,
1. Let _hcDefault_ be _dataLocaleData_.[[hourCycle]].
1. Let _hc_ be _dateTimeFormat_.[[HourCycle]].
1. If _hc_ is *null*, then
1. Set _hc_ to _hcDefault_.
1. If _hour12_ is not *undefined*, then
1. If _hour12_ is *true*, then
1. If _hcDefault_ is *"h11"* or *"h23"*, then
1. Set _hc_ to *"h11"*.
1. Else,
1. Set _hc_ to *"h12"*.
1. Else,
1. Assert: _hour12_ is *false*.
1. If _hcDefault_ is *"h11"* or *"h23"*, then
1. Set _hc_ to *"h23"*.
1. Else,
1. Set _hc_ to *"h24"*.
1. Set _dateTimeFormat_.[[HourCycle]] to _hc_.
1. If _dateTimeformat_.[[HourCycle]] is *"h11"* or *"h12"*, then
1. Let _pattern_ be _bestFormat_.[[pattern12]].
1. <ins>Let _rangePatterns_ be _bestFormat_.[[rangePatterns12]].</ins>
1. Else,
1. Let _pattern_ be _bestFormat_.[[pattern]].
1. <ins>Let _rangePatterns_ be _bestFormat_.[[rangePatterns]].</ins>
1. Set _dateTimeFormat_.[[Pattern]] to _pattern_.
1. <ins>Set _dateTimeFormat_.[[RangePatterns]] to _rangePatterns_.</ins>
1. Return _dateTimeFormat_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-todatetimeoptions" aoid="ToDateTimeOptions">
<h1>ToDateTimeOptions ( _options_, _required_, _defaults_ )</h1>
<p>
When the ToDateTimeOptions abstract operation is called with arguments _options_, _required_, and _defaults_, the following steps are taken:
</p>
<emu-alg>
1. If _options_ is *undefined*, let _options_ be *null*; otherwise let _options_ be ? ToObject(_options_).
1. Let _options_ be ObjectCreate(_options_).
1. Let _needDefaults_ be *true*.
1. If _required_ is *"date"* or *"any"*, then
1. For each of the property names *"weekday"*, *"year"*, *"month"*, *"day"*, do
1. Let _prop_ be the property name.
1. Let _value_ be ? Get(_options_, _prop_).
1. If _value_ is not *undefined*, let _needDefaults_ be *false*.
1. If _required_ is *"time"* or *"any"*, then
1. For each of the property names *"dayPeriod"*, *"hour"*, *"minute"*, *"second"*, *"fractionalSecondDigits"*, do
1. Let _prop_ be the property name.
1. Let _value_ be ? Get(_options_, _prop_).
1. If _value_ is not *undefined*, let _needDefaults_ be *false*.
1. Let _dateStyle_ be ? Get(_options_, *"dateStyle"*).
1. Let _timeStyle_ be ? Get(_options_, *"timeStyle"*).
1. If _dateStyle_ is not *undefined* or _timeStyle_ is not *undefined*, let _needDefaults_ be *false*.
1. If _required_ is *"date"* and _timeStyle_ is not *undefined*, then
1. Throw a *TypeError* exception.
1. If _required_ is *"time"* and _dateStyle_ is not *undefined*, then
1. Throw a *TypeError* exception.
1. If _needDefaults_ is *true* and _defaults_ is either *"date"* or *"all"*, then
1. For each of the property names *"year"*, *"month"*, *"day"*, do
1. Perform ? CreateDataPropertyOrThrow(_options_, _prop_, *"numeric"*).
1. If _needDefaults_ is *true* and _defaults_ is either *"time"* or *"all"*, then
1. For each of the property names *"hour"*, *"minute"*, *"second"*, do
1. Perform ? CreateDataPropertyOrThrow(_options_, _prop_, *"numeric"*).
1. Return _options_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-date-time-style-format" aoid="DateTimeStyleFormat">
<h1>DateTimeStyleFormat ( _dateStyle_, _timeStyle_, _dataLocaleData_ )</h1>
<p>The DateTimeStyleFormat abstract operation accepts arguments _dateStyle_ and _timeStyle_, which are each either *undefined*, *"full"*, *"long"*, *"medium"*, or *"short"*, at least one of which is not *undefined*, and _dataLocaleData_, which is a record from %DateTimeFormat%.[[LocaleData]][_locale_] for some locale _locale_. It returns the appropriate format record for date time formatting based on the parameters.</p>
<emu-alg>
1. If _timeStyle_ is not *undefined*, then
1. Assert: _timeStyle_ is one of *"full"*, *"long"*, *"medium"*, or *"short"*.
1. Let _timeFormat_ be _dataLocaleData_.[[TimeFormat]].[[<_timeStyle_>]].
1. If _dateStyle_ is not *undefined*, then
1. Assert: _dateStyle_ is one of *"full"*, *"long"*, *"medium"*, or *"short"*.
1. Let _dateFormat_ be _dataLocaleData_.[[DateFormat]].[[<_dateStyle_>]].
1. If _dateStyle_ is not *undefined* and _timeStyle_ is not *undefined*, then
1. Let _format_ be a new Record.
1. Add to _format_ all fields from _dateFormat_ except [[pattern]] <ins>and [[rangePatterns]]</ins>.
1. Add to _format_ all fields from _timeFormat_ except [[pattern]], <ins>[[rangePatterns]],</ins> [[pattern12]] <ins>and [[rangePatterns12]]</ins>, if present.
1. Let _connector_ be _dataLocaleData_.[[DateTimeFormat]].[[<_dateStyle_>]].
1. Let _pattern_ be the string _connector_ with the substring *"{0}"* replaced with _timeFormat_.[[pattern]] and the substring *"{1}"* replaced with _dateFormat_.[[pattern]].
1. Set _format_.[[pattern]] to _pattern_.
1. If _timeFormat_ has a [[pattern12]] field, then
1. Let _pattern12_ be the string _connector_ with the substring *"{0}"* replaced with _timeFormat_.[[pattern12]] and the substring *"{1}"* replaced with _dateFormat_.[[pattern]].
1. Set _format_.[[pattern12]] to _pattern12_.
1. <ins>Let _dateTimeRangeFormat_ be _dataLocaleData_.[[DateTimeRangeFormat]].[[<_dateStyle_>]].[[<_timeStyle_>]]</ins>
1. <ins>Add to _format_ all fields from _dateTimeRangeFormat_ including [[rangePatterns]] and [[rangePatterns12]], if present.</ins>
1. Return _format_.
1. If _timeStyle_ is not *undefined*, then
1. Return _timeFormat_.
1. Assert: _dateStyle_ is not *undefined*.
1. Return _dateFormat_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-basicformatmatcher" aoid="BasicFormatMatcher">
<h1>BasicFormatMatcher ( _options_, _formats_ )</h1>
<p>
When the BasicFormatMatcher abstract operation is called with two arguments _options_ and _formats_, the following steps are taken:
</p>
<emu-alg>
1. Let _removalPenalty_ be 120.
1. Let _additionPenalty_ be 20.
1. Let _longLessPenalty_ be 8.
1. Let _longMorePenalty_ be 6.
1. Let _shortLessPenalty_ be 6.
1. Let _shortMorePenalty_ be 3.
1. Let _bestScore_ be -*Infinity*.
1. Let _bestFormat_ be *undefined*.
1. Assert: Type(_formats_) is List.
1. For each element _format_ of _formats_ in List order, do
1. Let _score_ be 0.
1. For each property name _property_ shown in <emu-xref href="#table-datetimeformat-components"></emu-xref>, do
1. Let _optionsProp_ be _options_.[[<_property_>]].
1. Let _formatProp_ be _format_.[[<_property_>]].
1. If _optionsProp_ is *undefined* and _formatProp_ is not *undefined*, decrease _score_ by _additionPenalty_.
1. Else if _optionsProp_ is not *undefined* and _formatProp_ is *undefined*, decrease _score_ by _removalPenalty_.
1. Else if _optionsProp_ ≠ _formatProp_, then
1. If _property_ is *"fractionalSecondDigits"*, then
1. Let _values_ be « *1*, *2*, *3* ».
1. Else,
1. Let _values_ be « *"2-digit"*, *"numeric"*, *"narrow"*, *"short"*, *"long"* ».
1. Let _optionsPropIndex_ be the index of _optionsProp_ within _values_.
1. Let _formatPropIndex_ be the index of _formatProp_ within _values_.
1. Let _delta_ be max(min(_formatPropIndex_ - _optionsPropIndex_, 2), -2).
1. If _delta_ = 2, decrease _score_ by _longMorePenalty_.
1. Else if _delta_ = 1, decrease _score_ by _shortMorePenalty_.
1. Else if _delta_ = -1, decrease _score_ by _shortLessPenalty_.
1. Else if _delta_ = -2, decrease _score_ by _longLessPenalty_.
1. If _score_ > _bestScore_, then
1. Let _bestScore_ be _score_.
1. Let _bestFormat_ be _format_.
1. Return _bestFormat_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-bestfitformatmatcher" aoid="BestFitFormatMatcher">
<h1>BestFitFormatMatcher ( _options_, _formats_ )</h1>
<p>
When the BestFitFormatMatcher abstract operation is called with two arguments _options_ and _formats_, it performs implementation dependent steps, which should return a set of component representations that a typical user of the selected locale would perceive as at least as good as the one returned by BasicFormatMatcher.
</p>
</emu-clause>
<emu-clause id="sec-datetime-format-functions">
<h1>DateTime Format Functions</h1>
<p>A DateTime format function is an anonymous built-in function that has a [[DateTimeFormat]] internal slot.</p>
<p>When a DateTime format function _F_ is called with optional argument _date_, the following steps are taken:</p>
<emu-alg>
1. Let _dtf_ be _F_.[[DateTimeFormat]].
1. Assert: Type(_dtf_) is Object and _dtf_ has an [[InitializedDateTimeFormat]] internal slot.
1. If _date_ is not provided or is *undefined*, then
1. Let _x_ be Call(%Date.now%, *undefined*).
1. Else,
1. Let _x_ be ? ToNumber(_date_).
1. Return ? FormatDateTime(_dtf_, _x_).
</emu-alg>
<p>
The *"length"* property of a DateTime format function is 1.
</p>
</emu-clause>
<emu-clause id="sec-formatdatetimepattern" aoid="FormatDateTimePattern">
<h1><ins>FormatDateTimePattern ( _dateTimeFormat_, _patternParts_, _x_, _rangeFormatOptions_ )</ins></h1>
<p>
<ins>The FormatDateTimePattern abstract operation is called with arguments _dateTimeFormat_ (which must be an object initialized as a DateTimeFormat), _patternParts_ (which is a list of Records as returned by PartitionPattern), _x_ (which must be a Number value), and _rangeFormatOptions_ (which is a range pattern Record as used in [[rangePattern]] or *undefined*), interprets _x_ as a time value as specified in ES2021, <emu-xref href="#sec-time-values-and-time-range"></emu-xref>, and creates the corresponding parts according _pattern_ and to the effective locale and the formatting options of _dateTimeFormat_ and _rangeFormatOptions_. The following steps are taken:</ins>
</p>
<emu-alg>
1. Let _x_ be TimeClip(_x_).
1. If _x_ is *NaN*, throw a *RangeError* exception.
1. Let _locale_ be _dateTimeFormat_.[[Locale]].
1. Let _nfOptions_ be ObjectCreate(*null*).
1. Perform ! CreateDataPropertyOrThrow(_nfOptions_, *"useGrouping"*, *false*).
1. Let _nf_ be ? Construct(%NumberFormat%, « _locale_, _nfOptions_ »).
1. Let _nf2Options_ be ObjectCreate(*null*).
1. Perform ! CreateDataPropertyOrThrow(_nf2Options_, *"minimumIntegerDigits"*, 2).
1. Perform ! CreateDataPropertyOrThrow(_nf2Options_, *"useGrouping"*, *false*).
1. Let _nf2_ be ? Construct(%NumberFormat%, « _locale_, _nf2Options_ »).
1. Let _fractionalSecondDigits_ be _dateTimeFormat_.[[FractionalSecondDigits]].
1. If _fractionalSecondDigits_ is not *undefined*, then
1. Let _nf3Options_ be ObjectCreate(*null*).
1. Perform ! CreateDataPropertyOrThrow(_nf3Options_, *"minimumIntegerDigits"*, _fractionalSecondDigits_).
1. Perform ! CreateDataPropertyOrThrow(_nf3Options_, *"useGrouping"*, *false*).
1. Let _nf3_ be ? Construct(%NumberFormat%, « _locale_, _nf3Options_ »).
1. Let _tm_ be ToLocalTime(_x_, _dateTimeFormat_.[[Calendar]], _dateTimeFormat_.[[TimeZone]]).
1. Let _result_ be a new empty List.
1. <del>Let _patternParts_ be PartitionPattern(_dateTimeFormat_.[[Pattern]]).</del>
1. For each element _patternPart_ of _patternParts_, in List order, do
1. Let _p_ be _patternPart_.[[Type]].
1. If _p_ is *"literal"*, then
1. Append a new Record { [[Type]]: *"literal"*, [[Value]]: _patternPart_.[[Value]] } as the last element of the list _result_.
1. Else if _p_ is equal to *"fractionalSecondDigits"*, then
1. Let _v_ be _tm_.[[Millisecond]].
1. Let _v_ be floor(_v_ × 10<sup>( _fractionalSecondDigits_ - 3 )</sup>).
1. Let _fv_ be FormatNumeric(_nf3_, _v_).
1. Append a new Record { [[Type]]: *"fractionalSecond"*, [[Value]]: _fv_ } as the last element of _result_.
1. Else if _p_ matches a Property column of the row in <emu-xref href="#table-datetimeformat-components"></emu-xref>, then
1. <ins>If _rangeFormatOptions_ is not *undefined*, let _f_ be the value of _rangeFormatOptions_'s field whose name matches _p_.</ins>
1. <ins>Else,</ins> let _f_ be the value of _dateTimeFormat_'s internal slot whose name is the Internal Slot column of the matching row.
1. Let _v_ be the value of _tm_'s field whose name is the Internal Slot column of the matching row.
1. If _p_ is *"year"* and _v_ ≤ 0, let _v_ be 1 - _v_.
1. If _p_ is *"month"*, increase _v_ by 1.
1. If _p_ is *"hour"* and _dateTimeFormat_.[[HourCycle]] is *"h11"* or *"h12"*, then
1. Let _v_ be _v_ modulo 12.
1. If _v_ is 0 and _dateTimeFormat_.[[HourCycle]] is *"h12"*, let _v_ be 12.
1. If _p_ is *"hour"* and _dateTimeFormat_.[[HourCycle]] is *"h24"*, then
1. If _v_ is 0, let _v_ be 24.
1. If _f_ is *"numeric"*, then
1. Let _fv_ be FormatNumeric(_nf_, _v_).
1. Else if _f_ is *"2-digit"*, then
1. Let _fv_ be FormatNumeric(_nf2_, _v_).
1. If the *"length"* property of _fv_ is greater than 2, let _fv_ be the substring of _fv_ containing the last two characters.
1. Else if _f_ is *"narrow"*, *"short"*, or *"long"*, then let _fv_ be a String value representing _v_ in the form given by _f_; the String value depends upon the implementation and the effective locale and calendar of _dateTimeFormat_. If _p_ is *"month"* <ins>and _rangeFormatOptions_ is *undefined*</ins>, then the String value may also depend on whether <ins>_dateTimeFormat_.[[Day]] is *undefined*</ins>. <ins>If _p_ is *"month"* and _rangeFormatOptions_ is not *undefined*, then the String value may also depend on whether _rangeFormatOptions_.[[day]] is *undefined*.</ins> If _p_ is *"timeZoneName"*, then the String value may also depend on the value of the [[InDST]] field of _tm_. If _p_ is *"era"* <ins>and _rangeFormatOptions_ is *undefined*</ins>, then the String value may also depend on whether <ins>_dateTimeFormat_.[[Era]] is *undefined*</ins>. <ins>If _p_ is *"era"* and _rangeFormatOptions_ is not *undefined*, then the String value may also depend on whether _rangeFormatOptions_.[[era]] is *undefined*.</ins> If the implementation does not have a localized representation of _f_, then use _f_ itself.
1. Append a new Record { [[Type]]: _p_, [[Value]]: _fv_ } as the last element of the list _result_.
1. Else if _p_ is equal to *"ampm"*, then
1. Let _v_ be _tm_.[[Hour]].
1. If _v_ is greater than 11, then
1. Let _fv_ be an implementation and locale dependent String value representing *"post meridiem"*.
1. Else,
1. Let _fv_ be an implementation and locale dependent String value representing *"ante meridiem"*.
1. Append a new Record { [[Type]]: *"dayPeriod"*, [[Value]]: _fv_ } as the last element of the list _result_.
1. Else if _p_ is equal to *"relatedYear"*, then
1. Let _v_ be _tm_.[[RelatedYear]].
1. Let _fv_ be FormatNumeric(_nf_, _v_).
1. Append a new Record { [[Type]]: *"relatedYear"*, [[Value]]: _fv_ } as the last element of the list _result_.
1. Else if _p_ is equal to *"yearName"*, then
1. Let _v_ be _tm_.[[YearName]].
1. Append a new Record { [[Type]]: *"yearName"*, [[Value]]: _v_ } as the last element of the list _result_.
1. Else,
1. Let _unknown_ be an implementation-, locale-, and numbering system-dependent String based on _x_ and _p_.
1. Append a new Record { [[Type]]: *"unknown"*, [[Value]]: _unknown_ } as the last element of _result_.
1. Return _result_.
</emu-alg>
<emu-note>
It is recommended that implementations use the locale and calendar dependent strings provided by the Common Locale Data Repository (available at <a href="http://cldr.unicode.org">http://cldr.unicode.org</a>), and use CLDR *"abbreviated"* strings for DateTimeFormat *"short"* strings, and CLDR *"wide"* strings for DateTimeFormat *"long"* strings.
</emu-note>
<emu-note>
It is recommended that implementations use the time zone information of the IANA Time Zone Database.
</emu-note>
</emu-clause>
<emu-clause id="sec-partitiondatetimepattern" aoid="PartitionDateTimePattern">
<h1>PartitionDateTimePattern ( _dateTimeFormat_, _x_ )</h1>
<p>
The PartitionDateTimePattern abstract operation is called with arguments _dateTimeFormat_ (which must be an object initialized as a DateTimeFormat) and _x_ (which must be a Number value), interprets _x_ as a time value as specified in ES2021, <emu-xref href="#sec-time-values-and-time-range"></emu-xref>, and creates the corresponding parts according to the effective locale and the formatting options of _dateTimeFormat_. The following steps are taken:
</p>
<emu-alg>
1. Let _patternParts_ be PartitionPattern(_dateTimeFormat_.[[Pattern]]).
1. <ins>Let _result_ be ? FormatDateTimePattern(_dateTimeFormat_, _patternParts_, _x_, *undefined*).</ins>
1. Return _result_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-formatdatetime" aoid="FormatDateTime">
<h1>FormatDateTime ( _dateTimeFormat_, _x_ )</h1>
<p>
The FormatDateTime abstract operation is called with arguments _dateTimeFormat_ (which must be an object initialized as a DateTimeFormat) and _x_ (which must be a Number value), and performs the following steps:
</p>
<emu-alg>
1. Let _parts_ be ? PartitionDateTimePattern(_dateTimeFormat_, _x_).
1. Let _result_ be the empty String.
1. For each Record _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-formatdatetimetoparts" aoid="FormatDateTimeToParts">
<h1>FormatDateTimeToParts ( _dateTimeFormat_, _x_ )</h1>
<p>
The FormatDateTimeToParts abstract operation is called with arguments _dateTimeFormat_ (which must be an object initialized as a DateTimeFormat) and _x_ (which must be a Number value), and performs the following steps:
</p>
<emu-alg>
1. Let _parts_ be ? PartitionDateTimePattern(_dateTimeFormat_, _x_).
1. Let _result_ be ArrayCreate(0).
1. Let _n_ be 0.
1. For each Record _part_ in _parts_, do
1. Let _O_ be ObjectCreate(%Object.prototype%).
1. Perform ! CreateDataPropertyOrThrow(_O_, *"type"*, _part_.[[Type]]).
1. Perform ! CreateDataPropertyOrThrow(_O_, *"value"*, _part_.[[Value]]).
1. Perform ! CreateDataProperty(_result_, ! ToString(_n_), _O_).
1. Increment _n_ by 1.
1. Return _result_.
</emu-alg>
</emu-clause>
<emu-clause id="sec-partitiondatetimerangepattern" aoid="PartitionDateTimeRangePattern">
<ins class="block">
<h1>PartitionDateTimeRangePattern ( _dateTimeFormat_, _x_, _y_ )</h1>
<p>
The PartitionDateTimeRangePattern abstract operation is called with arguments _dateTimeFormat_ (which must be an object initialized as a DateTimeFormat), _x_ (which must be a Number value) and _y_ (which must be a Number value), interprets _x_ and _y_ as time values as specified in ES2021, <emu-xref href="#sec-time-values-and-time-range"></emu-xref>, and creates the corresponding parts according to the effective locale and the formatting options of _dateTimeFormat_. The following steps are taken:
</p>
<emu-alg>
1. Let _x_ be TimeClip(_x_).
1. If _x_ is *NaN*, throw a *RangeError* exception.
1. Let _y_ be TimeClip(_y_).
1. If _y_ is *NaN*, throw a *RangeError* exception.
1. If _x_ is greater than _y_, throw a *RangeError* exception.
1. Let _tm1_ be ToLocalTime(_x_, _dateTimeFormat_.[[Calendar]], _dateTimeFormat_.[[TimeZone]]).
1. Let _tm2_ be ToLocalTime(_y_, _dateTimeFormat_.[[Calendar]], _dateTimeFormat_.[[TimeZone]]).
1. Let _rangePatterns_ be _dateTimeFormat_.[[RangePatterns]].
1. Let _rangePattern_ be *undefined*.
1. Let _dateFieldsPracticallyEqual_ be *true*.
1. Let _patternContainsLargerDateField_ be *false*.
1. While _dateFieldsPracticallyEqual_ is *true* and _patternContainsLargerDateField_ is *false*, repeat for each row of <emu-xref href="#table-datetimeformat-rangepatternfields"></emu-xref> in order, except the header row
1. Let _fieldName_ be the name given in the Range Pattern Field column of the row.
1. If _fieldName_ is equal to [[AmPm]], then
1. Let _rp_ be _rangePatterns_.[[AmPm]].
1. If _rangePattern_ is not *undefined* and _rp_ is *undefined*, then
1. Set _patternContainsLargerDateField_ to *true*.
1. Else,
1. Let _v1_ be _tm1_.[[Hour]].
1. Let _v2_ be _tm2_.[[Hour]].
1. If _v1_ is greater than 11 and _v2_ less or equal than 11, or _v1_ is less or equal than 11 and _v2_ is greater than 11, then
1. Set _dateFieldsPracticallyEqual_ to *false*.
1. Let _rangePattern_ be _rp_.
1. If _fieldName_ is equal to [[FractionalSecondDigits]], then
1. Let _rp_ be _rangePatterns_.[[FractionalSecondDigits]].
1. If _rangePattern_ is not *undefined* and _rp_ is *undefined*, then
1. Set _patternContainsLargerDateField_ to *true*.
1. Else,
1. Let _fractionalSecondDigits_ be _dateTimeFormat_.[[FractionalSecondDigits]].
1. If _fractionalSecondDigits_ is *undefined*, then
1. Set _fractionalSecondDigits_ to 3.
1. Let _v1_ be _tm1_.[[Millisecond]].
1. Let _v2_ be _tm2_.[[Millisecond]].
1. Let _v1_ be floor(_v1_ × 10<sup>( _fractionalSecondDigits_ - 3 )</sup>).
1. Let _v2_ be floor(_v2_ × 10<sup>( _fractionalSecondDigits_ - 3 )</sup>).
1. If _v1_ is not equal to _v2_, then
1. Set _dateFieldsPracticallyEqual_ to *false*.
1. Let _rangePattern_ be _rp_.
1. Else,
1. Let _rp_ be _rangePatterns_.[[<_fieldName_>]].
1. If _rangePattern_ is not *undefined* and _rp_ is *undefined*, then
1. Set _patternContainsLargerDateField_ to *true*.
1. Else,
1. Let _v1_ be _tm1_.[[<_fieldName_>]].
1. Let _v2_ be _tm2_.[[<_fieldName_>]].
1. If _v1_ is not equal to _v2_, then
1. Set _dateFieldsPracticallyEqual_ to *false*.
1. Let _rangePattern_ be _rp_.
1. If _dateFieldsPracticallyEqual_ is *true*, then
1. Let _pattern_ be _dateTimeFormat_.[[Pattern]].
1. Let _patternParts_ be PartitionPattern(_pattern_).
1. Let _result_ be ? FormatDateTimePattern(_dateTimeFormat_, _patternParts_, _x_, *undefined*).
1. For each _r_ in _result_ do
1. Set _r_.[[Source]] to *"shared"*.
1. Return _result_.
1. Let _result_ be a new empty List.
1. If _rangePattern_ is *undefined*, then
1. Let _rangePattern_ be _rangePatterns_.[[Default]].
1. For each _rangePatternPart_ in _rangePattern_.[[PatternParts]], do
1. Let _pattern_ be _rangePatternPart_.[[Pattern]].
1. Let _source_ be _rangePatternPart_.[[Source]]
1. If _source_ is *"startRange"* or *"shared"*, then
1. Let _z_ be _x_.
1. Else,
1. Let _z_ be _y_.
1. Let _patternParts_ be PartitionPattern(_pattern_).
1. Let _partResult_ be ? FormatDateTimePattern(_dateTimeFormat_, _patternParts_, _z_, _rangePattern_).
1. For each _r_ in _partResult_, do
1. Set _r_.[[Source]] to _source_.
1. Add all elements in _partResult_ to _result_ in order.
1. Return _result_.
</emu-alg>
</ins>
</emu-clause>
<emu-clause id="sec-formatdatetimerange" aoid="FormatDateTimeRange">
<ins class="block">
<h1>FormatDateTimeRange( _dateTimeFormat_, _x_, _y_ )</h1>
<p>
The FormatDateTimeRange abstract operation is called with arguments _dateTimeFormat_ (which must be an object initialized as a DateTimeFormat), _x_ (which must be a Number value) and _y_ (which must be a Number value), and performs the following steps:
</p>
<emu-alg>
1. Let _parts_ be ? PartitionDateTimeRangePattern(_dateTimeFormat_, _x_, _y_).
1. Let _result_ be the empty String.
1. For each Record _part_ in _parts_, do
1. Set _result_ to a String value produced by concatenating _result_ and _part_.[[Value]].
1. Return _result_.
</emu-alg>
</ins>
</emu-clause>
<emu-clause id="sec-formatdatetimerangetoparts" aoid="FormatDateTimeRangeToParts">
<ins class="block">
<h1>FormatDateTimeRangeToParts ( _dateTimeFormat_, _x_, _y_ )</h1>
<p>
The FormatDateTimeRangeToParts abstract operation is called with arguments _dateTimeFormat_ (which must be an object initialized as a DateTimeFormat), _x_ (which must be a Number value) and _y_ (which must be a Number value), and performs the following steps:
</p>
<emu-alg>
1. Let _parts_ be ? PartitionDateTimeRangePattern(_dateTimeFormat_, _x_, _y_).
1. Let _result_ be ArrayCreate(0).
1. Let _n_ be 0.
1. For each Record _part_ in _parts_, do
1. Let _O_ be ObjectCreate(%ObjectPrototype%).
1. Perform ! CreateDataPropertyOrThrow(_O_, *"type"*, _part_.[[Type]]).
1. Perform ! CreateDataPropertyOrThrow(_O_, *"value"*, _part_.[[Value]]).
1. Perform ! CreateDataPropertyOrThrow(_O_, *"source"*, _part_.[[Source]]).
1. Perform ! CreateDataProperty(_result_, ! ToString(_n_), _O_).
1. Increment _n_ by 1.
1. Return _result_.
</emu-alg>
</ins>
</emu-clause>
<emu-clause id="sec-tolocaltime" aoid="ToLocalTime">
<h1>ToLocalTime ( _t_, _calendar_, _timeZone_ )</h1>
<p>
When the ToLocalTime abstract operation is called with arguments _t_, _calendar_, and _timeZone_, the following steps are taken:
</p>
<emu-alg>
1. Assert: Type(_t_) is Number.
1. If _calendar_ is *"gregory"*, then
1. Let _timeZoneOffset_ be the value calculated according to <emu-xref href="#sec-local-time-zone-adjustment">LocalTZA(_t_, *true*)</emu-xref> where the local time zone is replaced with timezone _timeZone_.
1. Let _tz_ be the time value _t_ + _timeZoneOffset_.
1. Return a record with fields calculated from _tz_ according to <emu-xref href="#table-datetimeformat-tolocaltime-record"></emu-xref>.
1. Else,
1. Return a record with the fields of Column 1 of <emu-xref href="#table-datetimeformat-tolocaltime-record"></emu-xref> calculated from _t_ for the given _calendar_ and _timeZone_. The calculations should use best available information about the specified _calendar_ and _timeZone_, including current and historical information about time zone offsets from UTC and daylight saving time rules.
</emu-alg>
<emu-table id="table-datetimeformat-tolocaltime-record">
<emu-caption>Record returned by ToLocalTime</emu-caption>
<table class="real-table">
<thead>
<tr>
<th>Field</th>
<th>Value Calculation for Gregorian Calendar</th>
</tr>
</thead>
<tr>
<td>[[Weekday]]</td>
<td>`WeekDay(tz)` specified in ES2021's <emu-xref href="#sec-week-day">Week Day</emu-xref></td>
</tr>
<tr>
<td>[[Era]]</td>
<td>Let `year` be `YearFromTime(tz)` specified in ES2021's <emu-xref href="#sec-year-number">Year Number</emu-xref>. If `year` is less than 0, return 'BC', else, return 'AD'.</td>
</tr>
<tr>
<td>[[Year]]</td>
<td>`YearFromTime(tz)` specified in ES2021's <emu-xref href="#sec-year-number">Year Number</emu-xref></td>
</tr>
<tr>
<td>[[RelatedYear]]</td>
<td>*undefined*</td>
</tr>
<tr>
<td>[[YearName]]</td>
<td>*undefined*</td>
</tr>
<tr>
<td>[[Month]]</td>
<td>`MonthFromTime(tz)` specified in ES2021's <emu-xref href="#sec-month-number">Month Number</emu-xref></td>
</tr>
<tr>
<td>[[Day]]</td>
<td>`DateFromTime(tz)` specified in ES2021's <emu-xref href="#sec-date-number">Date Number</emu-xref></td>
</tr>
<tr>
<td>[[Hour]]</td>
<td>`HourFromTime(tz)` specified in ES2021's <emu-xref href="#sec-hours-minutes-second-and-milliseconds">Hours, Minutes, Second, and Milliseconds</emu-xref></td>
</tr>
<tr>
<td>[[Minute]]</td>
<td>`MinFromTime(tz)` specified in ES2021's <emu-xref href="#sec-hours-minutes-second-and-milliseconds">Hours, Minutes, Second, and Milliseconds</emu-xref></td>
</tr>
<tr>
<td>[[Second]]</td>
<td>`SecFromTime(tz)` specified in ES2021's <emu-xref href="#sec-hours-minutes-second-and-milliseconds">Hours, Minutes, Second, and Milliseconds</emu-xref></td>
</tr>
<tr>
<td>[[Millisecond]]</td>
<td>`msFromTime(tz)` specified in ES2021's <emu-xref href="#sec-hours-minutes-second-and-milliseconds">Hours, Minutes, Second, and Milliseconds</emu-xref></td>
</tr>
<tr>
<td>[[InDST]]</td>
<td>Calculate *true* or *false* using the best available information about the specified _calendar_ and _timeZone_, including current and historical information about time zone offsets from UTC and daylight saving time rules.</td>
</tr>
</table>
</emu-table>
<emu-note>
It is recommended that implementations use the time zone information of the IANA Time Zone Database.
</emu-note>
</emu-clause>
<emu-clause id="sec-unwrapdatetimeformat" aoid="UnwrapDateTimeFormat">
<h1>UnwrapDateTimeFormat ( _dtf_ )</h1>
<p>
The UnwrapDateTimeFormat abstract operation gets the underlying DateTimeFormat operation
for various methods which implement ECMA-402 v1 semantics for supporting initializing
existing Intl objects.
</p>
<emu-alg>
1. Assert: Type(_dtf_) is Object.
</emu-alg>
<emu-normative-optional>
<!-- Note: 2. is intentional -->
<emu-alg>
2. If _dtf_ does not have an [[InitializedDateTimeFormat]] internal slot and ? InstanceofOperator(_dtf_, %DateTimeFormat%) is *true*, then
1. Let _dtf_ be ? Get(_dtf_, %Intl%.[[FallbackSymbol]]).
</emu-alg>
</emu-normative-optional>
<!-- Note: 3. is intentional -->
<emu-alg>
3. Perform ? RequireInternalSlot(_dtf_, [[InitializedDateTimeFormat]]).
1. Return _dtf_.
</emu-alg>
<emu-note>See </emu-xref> for the motivation of the normative optional text.</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-intl-datetimeformat-constructor">
<h1>The Intl.DateTimeFormat Constructor</h1>
<p>
The Intl.DateTimeFormat constructor is the <dfn>%DateTimeFormat%</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>.
</p>
<emu-clause id="sec-intl.datetimeformat">
<h1>Intl.DateTimeFormat ( [ _locales_ [ , _options_ ] ] )</h1>
<p>
When the `Intl.DateTimeFormat` function is called with optional arguments _locales_ and _options_, the following steps are taken:
</p>
<emu-alg>
1. If NewTarget is *undefined*, let _newTarget_ be the active function object, else let _newTarget_ be NewTarget.
1. Let _dateTimeFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, *"%DateTimeFormat.prototype%"*, « [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[DayPeriod]], [[Hour]], [[Minute]], [[Second]], [[FractionalSecondDigits]], [[TimeZoneName]], [[HourCycle]], [[Pattern]], [[BoundFormat]] »).
1. Perform ? InitializeDateTimeFormat(_dateTimeFormat_, _locales_, _options_).
</emu-alg>
<emu-normative-optional>
<!-- Note: 4. is intentional -->
<emu-alg>
4. Let _this_ be the *this* value.
1. If NewTarget is *undefined* and Type(_this_) is Object and ? InstanceofOperator(_this_, %DateTimeFormat%) is *true*, then
1. Perform ? DefinePropertyOrThrow(_this_, %Intl%.[[FallbackSymbol]], PropertyDescriptor{ [[Value]]: _dateTimeFormat_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }).
1. Return _this_.
</emu-alg>
</emu-normative-optional>
<!-- Note: 6. is intentional -->
<emu-alg>
6. Return _dateTimeFormat_.
</emu-alg>
<emu-note>See </emu-xref> for the motivation of the normative optional text.</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-intl-datetimeformat-constructor">
<h1>Properties of the Intl.DateTimeFormat Constructor</h1>
<p>
The Intl.DateTimeFormat constructor has the following properties:
</p>
<emu-clause id="sec-intl.datetimeformat.prototype">
<h1>Intl.DateTimeFormat.prototype</h1>
<p>
The value of `Intl.DateTimeFormat.prototype` is %DateTimeFormat.prototype%.
</p>
<p>
This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }.
</p>
</emu-clause>
<emu-clause id="sec-intl.datetimeformat.supportedlocalesof">
<h1>Intl.DateTimeFormat.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 %DateTimeFormat%.[[AvailableLocales]].
1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_).
1. Return ? SupportedLocales(_availableLocales_, _requestedLocales_, _options_).
</emu-alg>
<p>
The value of the *"length"* property of the *supportedLocalesOf* method is 1.
</p>
</emu-clause>
<emu-clause id="sec-intl.datetimeformat-internal-slots">
<h1>Internal slots</h1>
<p>
The value of the [[AvailableLocales]] internal slot is implementation defined within the constraints described in </emu-xref>.
</p>
<p>
The value of the [[RelevantExtensionKeys]] internal slot is « *"ca"*, *"hc"*, *"nu"* ».
</p>
<emu-note>
Unicode Technical Standard 35 describes four locale extension keys that are relevant to date and time formatting: *"ca"* for calendar, *"hc"* for hour cycle, *"nu"* for numbering system (of formatted numbers), and *"tz"* for time zone. DateTimeFormat, however, requires that the time zone is specified through the *"timeZone"* property in the options objects.
</emu-note>
<p>
The value of the [[LocaleData]] internal slot is implementation defined within the constraints described in </emu-xref> and the following additional constraints, for all locale values _locale_:
</p>
<ul>
<li>
[[LocaleData]].[[<_locale_>]].[[nu]] must be a List that does not include the values *"native"*, *"traditio"*, or *"finance"*.
</li>
<li>
[[LocaleData]].[[<_locale_>]].[[hc]] must be « *null*, *"h11"*, *"h12"*, *"h23"*, *"h24"* ».
</li>
<li>
[[LocaleData]].[[<_locale_>]].[[hourCycle]] must be a String value equal to *"h11"*, *"h12"*, *"h23"*, or *"h24"*.
</li>
<li>
[[LocaleData]].[[<_locale_>]] must have a [[formats]] field. This formats field must have a [[<_calendar_>]] field for all calendar values _calendar_. The value of this field must be a list of records, each of which has a subset of the fields shown in <emu-xref href="#table-datetimeformat-components"></emu-xref>, where each field must have one of the values specified for the field in <emu-xref href="#table-datetimeformat-components"></emu-xref>. Multiple records in a list may use the same subset of the fields as long as they have different values for the fields. The following subsets must be available for each locale:
<ul>
<li>weekday, year, month, day, hour, minute, second, fractionalSecondDigits</li>
<li>weekday, year, month, day, hour, minute, second</li>
<li>weekday, year, month, day</li>
<li>year, month, day</li>
<li>year, month</li>
<li>month, day</li>
<li>hour, minute, second, fractionalSecondDigits</li>
<li>hour, minute, second</li>
<li>hour, minute</li>
<li>dayPeriod, hour</li>
<li>dayPeriod, hour, minute, second</li>
<li>dayPeriod, hour, minute</li>
</ul>
Each of the records must also have <ins>the following fields:</ins>
<ol>
<li>A [[pattern]] field, whose value is a String value that contains for each of the date and time format component fields of the record a substring starting with *"{"*, followed by the name of the field, followed by *"}"*.</li>
<li>If the record has an hour field, it must also have a [[pattern12]] field, whose value is a String value that, in addition to the substrings of the [[pattern]] field, contains a substring *"{ampm}"*.</li>
<li>If the record has a [[year]] field, the [[pattern]] and [[pattern12]] values may contain the substrings *"{yearName}"* and *"{relatedYear}"*</li>
<li>
<ins>A [[rangePatterns]] field with a Record value<ins>
<ul>
<li><ins>The [[rangePatterns]] record may have any of the fields in <emu-xref href="#table-datetimeformat-rangepatternfields"></emu-xref>, where each field represents a range pattern and it's value is a Record.</ins>
<ul>
<li><ins>The name of the field indicates the largest calendar element that must be different between the start and end dates in order to use this range pattern. For example, if the field name is Month, it contains the range pattern that should be used to format a date range where the Era and Year values are the same, but Month value is different.</ins></li>
<li><ins>The record will contain the following fields:</ins></li>
<ul>
<li><ins>A subset of the fields shown in the Property column of <emu-xref href="#table-datetimeformat-components"></emu-xref>, where each field must have one of the values specified for that field in the Values column of <emu-xref href="#table-datetimeformat-components"></emu-xref>. Only the fields required to format a date with any of the PatternParts will be added.</ins></li>
<li><ins>A [[PatternParts]] field whose value is a list of Records each representing a part of the range pattern. Each record contains a [[Pattern]] field and a [[Source]] field. The [[Pattern]] field's value is a String of the same format as the regular date pattern String. The [[Source]] field must contain one of the following values *"shared"*, *"startRange"* or *"endRange"* which indicates which of the range's dates should be formatted using the value of the Pattern field.</li></ins>
</ul>
</ul>
</li>
<li><ins>The [[rangePatterns]] record must have a [[Default]] field which contains the default range pattern used when the specific range pattern is not available. It's value is a list of records with the same structure as the other fields in the [[rangePatterns]] record.</ins></li>
</ul>
</li>
<li><ins>If the record has an hour field, it must also have a [[rangePatterns12]] field. It's value is similar to the Record in [[rangePatterns]], but it uses a String similar to [[pattern12]] for each part of the range pattern.</ins></li>
<li><ins>If the record has a [[year]] field, the [[rangePatterns]] and [[rangePatterns12]] may contain range patterns where the [[Pattern]] values may contain the substrings *"{yearName}"* and *"{relatedYear}"*</ins></li>
</ol>
</li>
<li>
[[LocaleData]][<_locale_>] must have a [[styles]] field. The styles field must have a [[<_calendar_>]] field for all calendar values _calendar_. The field must contain [[DateFormat]], [[TimeFormat]], [[DateTimeFormat]] <ins>and [[DateTimeRangeFormat]]</ins> fields, the value of these fields are Records, where each of which has [[full]], [[long]], [[medium]] and [[short]] fields. For [[DateFormat]] and [[TimeFormat]], the value of these fields must be a record, which has a subset of the fields shown in Table 1, where each field must have one of the values specified for the field in Table 1. Each of the records must also have <ins>the following fields:</ins>
<ol>
<li>A [[pattern]] field, whose value is a String value that contains for each of the date and time format component fields of the record a substring starting with *"{"*, followed by the name of the field, followed by *"}"*.</li>
<li>If the record has an hour field, it must also have a [[pattern12]] field, whose value is a String value that, in addition to the substrings of the pattern field, contains a substring *"{ampm}"*.</li>
<li><ins>A [[rangePatterns]] field that contains a record similar to the one described in the [[formats]] field.</ins></li>
<li><ins>If the record has an hour field, it must also have a [[rangePatterns12]] field. It's value is similar to the record in [[rangePatterns]] but it uses a string similar to [[pattern12]] for each range pattern.</ins></li>
</ol>
For [[DateTimeFormat]], the field value must be a string pattern which contains the strings *"{0}"* and *"{1}"*. <ins>For [[DateTimeRangeFormat]] the value of these fields must be a nested record which also has a [[full]], [[long]], [[medium]] and [[short]] fields. The [[full]], [[long]], [[medium]] and [[short]] fields in the enclosing record refer to the date style of the range pattern, while the fields in the nested record refers to the time style of the range pattern. The value of these fields in the nested record is a record with a [[rangePatterns]] field and a [[rangePatterns12]] which are similar to the [[rangePatterns]] and [rangePatterns12]] fields in [[DateFormat]] and [[TimeFormat]].</ins>
</li>
</ul>
<emu-note>
For example, an implementation might include the following record as part of its English locale data: <del>{[[hour]]: *"numeric"*, [[minute]]: *"2-digit"*, [[second]]: *"2-digit"*, [[pattern]]: *"{hour}:{minute}:{second}"*, [[pattern12]]: *"{hour}:{minute}:{second} {ampm}"*}.</del>
<ins class="block">
<ul>
<li>[[hour]]: *"numeric"*</li>
<li>[[minute]]: *"numeric"*</li>
<li>[[pattern]]: *"{hour}:{minute}"*</li>
<li>[[pattern12]]: *"{hour}:{minute} {ampm}"*</li>
<li>[[rangePatterns]]: </li>
<ul>
<li>[[Hour]]:<ul>
<li>[[hour]]: *"numeric"*</li>
<li>[[minute]]: *"numeric"*</li>
<li>[[PatternParts]]:</li>
<ul>
<li>{[[Source]]: *"startRange"*, [[Pattern]]: *"{hour}:{minute}"*}</li>
<li>{[[Source]]: *"shared"*, [[Pattern]]: *" – "*}</li>
<li>{[[Source]]: *"endRange"*, [[Pattern]]: *"{hour}:{minute}"*}</li>
</ul>
</ul></li>
<li>[[Minute]]:<ul>
<li>[[hour]]: *"numeric"*</li>
<li>[[minute]]: *"numeric"*</li>
<li>[[PatternParts]]:</li>
<ul>
<li>{[[Source]]: *"startRange"*, [[Pattern]]: *"{hour}:{minute}"*}</li>
<li>{[[Source]]: *"shared"*, [[Pattern]]: *" – "*}</li>
<li>{[[Source]]: *"endRange"*, [[Pattern]]: *"{hour}:{minute}"*}</li>
</ul>
</ul></li>
<li>[[Default]]:<ul>
<li>[[year]]: *"2-digit"*</li>
<li>[[month]]: *"numeric"*</li>
<li>[[day]]: *"numeric"*</li>
<li>[[hour]]: *"numeric"*</li>
<li>[[minute]]: *"numeric"*</li>
<li>[[PatternParts]]:</li>
<ul>
<li>{[[Source]]: *"startRange"*, [[Pattern]]: *"{day}/{month}/{year}, {hour}:{minute}"*}</li>
<li>{[[Source]]: *"shared"*, [[Pattern]]: *" – "*}</li>
<li>{[[Source]]: *"endRange"*, [[Pattern]]: *"{day}/{month}/{year}, {hour}:{minute}"*}</li>
</ul>
</ul></li>
</ul>
<li>[[rangePatterns12]]:
<ul>
<li>[[Hour]]:<ul>
<li>[[hour]]: *"numeric"*</li>
<li>[[minute]]: *"numeric"*</li>
<li>[[PatternParts]]:</li>
<ul>
<li>{[[Source]]: *"startRange"*, [[Pattern]]: *"{hour}:{minute}"*}</li>
<li>{[[Source]]: *"shared"*, [[Pattern]]: *" – "*}</li>
<li>{[[Source]]: *"endRange"*, [[Pattern]]: *"{hour}:{minute}"*}</li>
<li>{[[Source]]: *"shared"*, [[Pattern]]: *" {ampm}"*}</li>
</ul>
</ul></li>
<li>[[Minute]]:<ul>
<li>[[hour]]: *"numeric"*</li>
<li>[[minute]]: *"numeric"*</li>
<li>[[PatternParts]]:</li>
<ul>
<li>{[[Source]]: *"startRange"*, [[Pattern]]: *"{hour}:{minute}"*}</li>
<li>{[[Source]]: *"shared"*, [[Pattern]]: *" – "*}</li>
<li>{[[Source]]: *"endRange"*, [[Pattern]]: *"{hour}:{minute}"*}</li>
<li>{[[Source]]: *"shared"*, [[Pattern]]: *" {ampm}"*}</li>
</ul>
</ul></li>
<li>[[Default]]:<ul>
<li>[[year]]: *"2-digit"*</li>
<li>[[month]]: *"numeric"*</li>
<li>[[day]]: *"numeric"*</li>
<li>[[hour]]: *"numeric"*</li>
<li>[[minute]]: *"numeric"*</li>
<li>[[PatternParts]]:</li>
<ul>
<li>{[[Source]]: *"startRange"*, [[Pattern]]: *"{day}/{month}/{year}, {hour}:{minute} {ampm}"*}</li>
<li>{[[Source]]: *"shared"*, [[Pattern]]: *" – "*}</li>
<li>{[[Source]]: *"endRange"*, [[Pattern]]: *"{day}/{month}/{year}, {hour}:{minute} {ampm}"*}</li>
</ul>
</ul></li>
</ul></li>
</ul>
</ins>
</emu-note>
<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-table id="table-datetimeformat-rangepatternfields">
<emu-caption><ins>Range pattern fields</ins></emu-caption>
<ins>
<table class="real-table">
<thead>
<tr>
<th>Range Pattern Field</th>
<th>Pattern String Field</th>
</tr>
</thead>
<tr>
<td>[[Era]]</td>
<td>*"era"*</td>
</tr>
<tr>
<td>[[Year]]</td>
<td>*"year"*</td>
</tr>
<tr>
<td>[[Month]]</td>
<td>*"month"*</td>
</tr>
<tr>
<td>[[Day]]</td>
<td>*"day"*</td>
</tr>
<tr>
<td>[[AmPm]]</td>
<td>*"ampm"*</td>
</tr>
<tr>
<td>[[Hour]]</td>
<td>*"hour"*</td>
</tr>
<tr>
<td>[[Minute]]</td>