generated from tc39/template-for-proposals
-
Notifications
You must be signed in to change notification settings - Fork 4
/
spec.emu
1300 lines (1195 loc) · 74.9 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
<emu-clause id="datetimeformat-objects">
<h1>DateTimeFormat Objects</h1>
<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 href="#sec-internal-slots"></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]], <ins>[[EraDisplay]],</ins> [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[DayPeriod]], [[Hour]], [[Minute]], [[Second]], [[FractionalSecondDigits]], [[TimeZoneName]], [[HourCycle]], [[Pattern]], [[BoundFormat]] »).
1. Perform ? InitializeDateTimeFormat(_dateTimeFormat_, _locales_, _options_).
1. If the implementation supports the normative optional constructor mode of <emu-xref href="#legacy-constructor"></emu-xref>, then
1. Let _this_ be the *this* value.
1. Return ? ChainDateTimeFormat(_dateTimeFormat_, NewTarget, _this_).
1. Return _dateTimeFormat_.
</emu-alg>
<emu-normative-optional>
<emu-clause id="sec-chaindatetimeformat" aoid="ChainDateTimeFormat">
<h1>ChainDateTimeFormat ( _dateTimeFormat_, _newTarget_, _this_ )</h1>
<emu-alg>
1. If _newTarget_ is *undefined* and ? OrdinaryHasInstance(%DateTimeFormat%, _this_) is *true*, then
1. Perform ? DefinePropertyOrThrow(_this_, %Intl%.[[FallbackSymbol]], PropertyDescriptor{ [[Value]]: _dateTimeFormat_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }).
1. Return _this_.
1. Return _dateTimeFormat_.
</emu-alg>
</emu-clause>
</emu-normative-optional>
</emu-clause>
<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. Set _options_ to ? 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~, ~empty~, *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~, ~empty~, *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~, ~empty~, *undefined*).
1. Let _hourCycle_ be ? GetOption(_options_, *"hourCycle"*, ~string~, « *"h11"*, *"h12"*, *"h23"*, *"h24"* », *undefined*).
1. If _hour12_ is not *undefined*, then
1. Set _hourCycle_ to *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 _resolvedCalendar_ be _r_.[[ca]].
1. Set _dateTimeFormat_.[[Calendar]] to _resolvedCalendar_.
1. Set _dateTimeFormat_.[[NumberingSystem]] to _r_.[[nu]].
1. Let _dataLocale_ be _r_.[[dataLocale]].
1. Let _dataLocaleData_ be _localeData_.[[<_dataLocale_>]].
1. Let _hcDefault_ be _dataLocaleData_.[[hourCycle]].
1. If _hour12_ is *true*, then
1. If _hcDefault_ is *"h11"* or *"h23"*, let _hc_ be *"h11"*. Otherwise, let _hc_ be *"h12"*.
1. Else if _hour12_ is *false*, then
1. If _hcDefault_ is *"h11"* or *"h23"*, let _hc_ be *"h23"*. Otherwise, let _hc_ be *"h24"*.
1. Else,
1. Assert: _hour12_ is *undefined*.
1. Let _hc_ be _r_.[[hc]].
1. If _hc_ is *null*, set _hc_ to _hcDefault_.
1. Set _dateTimeFormat_.[[HourCycle]] to _hc_.
1. <ins>Set _dateTimeFormat_.[[HourCycle]] to ? GetOption (_options_, *"eraDisplay"*, *"string"*, « *"never"*, *"always"*, *"auto"* », *"auto"*).</ins>
1. <ins>If _dateTimeFormat_.[[EraDisplay]] is *"auto"*, then</ins>
1. <ins>If _dateTimeFormat_.[[Year]] is *undefined*, then</ins>
1. <ins>Set _dateTimeFormat_.[[EraDisplay]] to *"never"*.</ins>
1. <ins>If _dateTimeFormat_.[[EraDisplay]] is not *"never"*, then</ins>
1. <ins>If _dateTimeFormat_.[[Era]] is *undefined*, then</ins>
1. <ins>Set _dateTimeFormat_.[[Era]] to *"short"*.</ins>
1. Let _timeZone_ be ? Get(_options_, *"timeZone"*).
1. If _timeZone_ is *undefined*, then
1. Set _timeZone_ to DefaultTimeZone().
1. Else,
1. Set _timeZone_ to ? ToString(_timeZone_).
1. If the result of ! IsValidTimeZoneName(_timeZone_) is *false*, then
1. Throw a *RangeError* exception.
1. Set _timeZone_ to ! CanonicalizeTimeZoneName(_timeZone_).
1. Set _dateTimeFormat_.[[TimeZone]] to _timeZone_.
1. Let _formatOptions_ be a new Record.
1. Set _formatOptions_.[[hourCycle]] to _hc_.
1. Let _hasExplicitFormatComponents_ be *false*.
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 _values_ be a List whose elements are the strings given in the Values column of the row.
1. Let _value_ be ? GetOption(_options_, _prop_, ~string~, _values_, *undefined*).
1. Set _formatOptions_.[[<_prop_>]] to _value_.
1. If _value_ is not *undefined*, then
1. Set _hasExplicitFormatComponents_ to *true*.
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. If _hasExplicitFormatComponents_ is *true*, then
1. Throw a *TypeError* exception.
1. Let _styles_ be _dataLocaleData_.[[styles]].[[<_resolvedCalendar_>]].
1. Let _bestFormat_ be DateTimeStyleFormat(_dateStyle_, _timeStyle_, _styles_).
1. Else,
1. Let _formats_ be _dataLocaleData_.[[formats]].[[<_resolvedCalendar_>]].
1. If _matcher_ is *"basic"*, then
1. Let _bestFormat_ be BasicFormatMatcher(_formatOptions_, _formats_).
1. Else,
1. Let _bestFormat_ be BestFitFormatMatcher(_formatOptions_, _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. If _bestFormat_ has a field [[<_prop_>]], then
1. Let _p_ be _bestFormat_.[[<_prop_>]].
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. If _dateTimeformat_.[[HourCycle]] is *"h11"* or *"h12"*, then
1. Let _pattern_ be _bestFormat_.[[pattern12]].
1. Let _patternEra_ be _bestFormat_.[[pattern12Era]].
1. Let _rangePatterns_ be _bestFormat_.[[rangePatterns12]].
1. Else,
1. Let _pattern_ be _bestFormat_.[[pattern]].
1. Let _patternEra_ be _bestFormat_.[[patternEra]].
1. Let _rangePatterns_ be _bestFormat_.[[rangePatterns]].
1. Set _dateTimeFormat_.[[Pattern]] to _pattern_.
1. Set _dateTimeFormat_.[[PatternEra]] to _pattern_.
1. Set _dateTimeFormat_.[[RangePatterns]] to _rangePatterns_.
1. Return _dateTimeFormat_.
</emu-alg>
</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>
</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 href="#sec-internal-slots"></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 href="#sec-internal-slots"></emu-xref> and the following additional constraints, for all locale values _locale_:
</p>
<ul>
<li>
[[LocaleData]].[[<_locale_>]].[[nu]] must be a List 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 be a Record with [[<_calendar_>]] fields 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 the following fields:
<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 at least one of the substrings *"{ampm}"* or *"{dayPeriod}"*.</li>
<li>If the record has a [[year]] field, the [[pattern]] and [[pattern12]] values may contain the substrings *"{yearName}"* and *"{relatedYear}"*. <ins>In addition, it must also have a [[patternEra]] field, whose value is a String that, in addition to the substrings of the [[pattern]] field, contains the substring *"{Era}"*.</ins></li>
<li><ins class="block">If the record has a both an [[hour]] and a [[year]] field, it must also have a [[pattern12Era]] field, whose value is a String that, in addition to the substrings of the [[pattern12]] field, contains the substring *"{Era}"*.</ins></li>
<li>
A [[rangePatterns]] field with a Record value:
<ul>
<li>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 its value is a Record.
<ul>
<li>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 the month value is different.</li>
<li>The record will contain the following fields:</li>
<ul>
<li>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>. All fields required to format a date for any of the [[PatternParts]] records must be present.</li>
<li>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 is one of the String values *"shared"*, *"startRange"*, or *"endRange"*. It indicates which of the range's dates should be formatted using the value of the [[Pattern]] field.</li>
</ul>
</ul>
</li>
<li>The [[rangePatterns]] record must have a [[Default]] field which contains the default range pattern used when the specific range pattern is not available. Its value is a list of records with the same structure as the other fields in the [[rangePatterns]] record.</li>
</ul>
</li>
<li>If the record has an [[hour]] field, it must also have a [[rangePatterns12]] field. Its value is similar to the Record in [[rangePatterns]], but it uses a String similar to [[pattern12]] for each part of the range pattern.</li>
<li>If the record has a [[year]] field, the [[rangePatterns]] and [[rangePatterns12]] fields may contain range patterns where the [[Pattern]] values may contain the substrings *"{yearName}"* and *"{relatedYear}"*.</li>
</ol>
</li>
<li>
[[LocaleData]].[[<_locale_>]] must have a [[styles]] field. The [[styles]] field must be a Record with [[<_calendar_>]] fields for all calendar values _calendar_. The calendar records must contain [[DateFormat]], [[TimeFormat]], [[DateTimeFormat]] and [[DateTimeRangeFormat]] 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 <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>. Each of the records must also have the following fields:
<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 at least one of the substrings *"{ampm}"* or *"{dayPeriod}"*. <ins>In addition, it must also have a [[patternEra]] field, whose value is a String that, in addition to the substrings of the [[pattern]] field, contains the substring *"{Era}"*.</ins></li>
<li><ins class="block">If the record has a both an [[hour]] and a [[year]] field, it must also have a [[pattern12Era]] field, whose value is a String that, in addition to the substrings of the [[pattern12]] field, contains the substring *"{Era}"*.</ins></li>
<li>A [[rangePatterns]] field that contains a record similar to the one described in the [[formats]] field.</li>
<li>If the record has an [[hour]] field, it must also have a [[rangePatterns12]] field. Its value is similar to the record in [[rangePatterns]] but it uses a string similar to [[pattern12]] for each range pattern.</li>
</ol>
For [[DateTimeFormat]], the field value must be a string pattern which contains the strings *"{0}"* and *"{1}"*. For [[DateTimeRangeFormat]] the value of these fields must be a nested record which also has [[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]] field which are similar to the [[rangePatterns]] and [rangePatterns12]] fields in [[DateFormat]] and [[TimeFormat]].
</li>
</ul>
<emu-note>
For example, an implementation might include the following record as part of its English locale data:
<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>
</emu-note>
<emu-note>
It is recommended that implementations use the locale data provided by the Common Locale Data Repository (available at <a href="https://cldr.unicode.org/">https://cldr.unicode.org/</a>).
</emu-note>
<emu-table id="table-datetimeformat-rangepatternfields">
<emu-caption>Range pattern fields</emu-caption>
<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>[[DayPeriod]]</td>
<td>*"dayPeriod"*</td>
</tr>
<tr>
<td>[[Hour]]</td>
<td>*"hour"*</td>
</tr>
<tr>
<td>[[Minute]]</td>
<td>*"minute"*</td>
</tr>
<tr>
<td>[[Second]]</td>
<td>*"second"*</td>
</tr>
<tr>
<td>[[FractionalSecondDigits]]</td>
<td>*"fractionalSecondDigits"*</td>
</tr>
</table>
</emu-table>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-intl-datetimeformat-prototype-object">
<h1>Properties of the Intl.DateTimeFormat Prototype Object</h1>
<p>
The Intl.DateTimeFormat prototype object is itself an ordinary object. <dfn>%DateTimeFormat.prototype%</dfn> is not an Intl.DateTimeFormat instance and does not have an [[InitializedDateTimeFormat]] internal slot or any of the other internal slots of Intl.DateTimeFormat instance objects.
</p>
<emu-clause id="sec-intl.datetimeformat.prototype.constructor">
<h1>Intl.DateTimeFormat.prototype.constructor</h1>
<p>
The initial value of `Intl.DateTimeFormat.prototype.constructor` is %DateTimeFormat%.
</p>
</emu-clause>
<emu-clause id="sec-intl.datetimeformat.prototype-@@tostringtag">
<h1>Intl.DateTimeFormat.prototype [ @@toStringTag ]</h1>
<p>
The initial value of the @@toStringTag property is the String value *"Intl.DateTimeFormat"*.
</p>
<p>
This property has the attributes { [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *true* }.
</p>
</emu-clause>
<emu-clause id="sec-intl.datetimeformat.prototype.format">
<h1>get Intl.DateTimeFormat.prototype.format</h1>
<p>
Intl.DateTimeFormat.prototype.format is an accessor property whose set accessor function is *undefined*. Its get accessor function performs the following steps:
</p>
<emu-alg>
1. Let _dtf_ be the *this* value.
1. If the implementation supports the normative optional constructor mode of <emu-xref href="#legacy-constructor"></emu-xref>, then
1. Set _dtf_ to ? UnwrapDateTimeFormat(_dtf_).
1. Perform ? RequireInternalSlot(_dtf_, [[InitializedDateTimeFormat]]).
1. If _dtf_.[[BoundFormat]] is *undefined*, then
1. Let _F_ be a new built-in function object as defined in DateTime Format Functions (<emu-xref href="#sec-datetime-format-functions"></emu-xref>).
1. Set _F_.[[DateTimeFormat]] to _dtf_.
1. Set _dtf_.[[BoundFormat]] to _F_.
1. Return _dtf_.[[BoundFormat]].
</emu-alg>
<emu-note>
The returned function is bound to _dtf_ so that it can be passed directly to `Array.prototype.map` or other functions.
This is considered a historical artefact, as part of a convention which is no longer followed for new features, but is preserved to maintain compatibility with existing programs.
</emu-note>
</emu-clause>
<emu-clause id="sec-Intl.DateTimeFormat.prototype.formatToParts">
<h1>Intl.DateTimeFormat.prototype.formatToParts ( _date_ )</h1>
<p>
When the `formatToParts` method is called with an argument _date_, the following steps are taken:
</p>
<emu-alg>
1. Let _dtf_ be the *this* value.
1. Perform ? RequireInternalSlot(_dtf_, [[InitializedDateTimeFormat]]).
1. If _date_ is *undefined*, then
1. Let _x_ be ! Call(%Date.now%, *undefined*).
1. Else,
1. Let _x_ be ? ToNumber(_date_).
1. Return ? FormatDateTimeToParts(_dtf_, _x_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-intl.datetimeformat.prototype.formatRange">
<h1>Intl.DateTimeFormat.prototype.formatRange ( _startDate_, _endDate_ )</h1>
<p>
When the `formatRange` method is called with arguments _startDate_ and _endDate_, the following steps are taken:
</p>
<emu-alg>
1. Let _dtf_ be *this* value.
1. Perform ? RequireInternalSlot(_dtf_, [[InitializedDateTimeFormat]]).
1. If _startDate_ is *undefined* or _endDate_ is *undefined*, throw a *TypeError* exception.
1. Let _x_ be ? ToNumber(_startDate_).
1. Let _y_ be ? ToNumber(_endDate_).
1. Return ? FormatDateTimeRange(_dtf_, _x_, _y_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-Intl.DateTimeFormat.prototype.formatRangeToParts">
<h1>Intl.DateTimeFormat.prototype.formatRangeToParts ( _startDate_, _endDate_ )</h1>
<p>
When the `formatRangeToParts` method is called with arguments _startDate_ and _endDate_, the following steps are taken:
</p>
<emu-alg>
1. Let _dtf_ be *this* value.
1. Perform ? RequireInternalSlot(_dtf_, [[InitializedDateTimeFormat]]).
1. If _startDate_ is *undefined* or _endDate_ is *undefined*, throw a *TypeError* exception.
1. Let _x_ be ? ToNumber(_startDate_).
1. Let _y_ be ? ToNumber(_endDate_).
1. Return ? FormatDateTimeRangeToParts(_dtf_, _x_, _y_).
</emu-alg>
</emu-clause>
<emu-clause id="sec-intl.datetimeformat.prototype.resolvedoptions">
<h1>Intl.DateTimeFormat.prototype.resolvedOptions ( )</h1>
<p>
This function provides access to the locale and options computed during initialization of the object.
</p>
<emu-alg>
1. Let _dtf_ be the *this* value.
1. If the implementation supports the normative optional constructor mode of <emu-xref href="#legacy-constructor"></emu-xref>, then
1. Set _dtf_ to ? UnwrapDateTimeFormat(_dtf_).
1. Perform ? RequireInternalSlot(_dtf_, [[InitializedDateTimeFormat]]).
1. Let _options_ be OrdinaryObjectCreate(%Object.prototype%).
1. For each row of <emu-xref href="#table-datetimeformat-resolvedoptions-properties"></emu-xref>, except the header row, in table order, do
1. Let _p_ be the Property value of the current row.
1. If _p_ is *"hour12"*, then
1. Let _hc_ be _dtf_.[[HourCycle]].
1. If _hc_ is *"h11"* or *"h12"*, let _v_ be *true*.
1. Else if, _hc_ is *"h23"* or *"h24"*, let _v_ be *false*.
1. Else, let _v_ be *undefined*.
1. Else,
1. Let _v_ be the value of _dtf_'s internal slot whose name is the Internal Slot value of the current row.
1. If the Internal Slot value of the current row is an Internal Slot value in <emu-xref href="#table-datetimeformat-components"></emu-xref>, then
1. If _dtf_.[[DateStyle]] is not *undefined* or _dtf_.[[TimeStyle]] is not *undefined*, then
1. Let _v_ be *undefined*.
1. If _v_ is not *undefined*, then
1. Perform ! CreateDataPropertyOrThrow(_options_, _p_, _v_).
1. Return _options_.
</emu-alg>
<emu-table id="table-datetimeformat-resolvedoptions-properties">
<emu-caption>Resolved Options of DateTimeFormat Instances</emu-caption>
<table class="real-table">
<thead>
<tr>
<th>Internal Slot</th>
<th>Property</th>
</tr>
</thead>
<tr>
<td>[[Locale]]</td>
<td>*"locale"*</td>
</tr>
<tr>
<td>[[Calendar]]</td>
<td>*"calendar"*</td>
</tr>
<tr>
<td>[[NumberingSystem]]</td>
<td>*"numberingSystem"*</td>
</tr>
<tr>
<td>[[TimeZone]]</td>
<td>*"timeZone"*</td>
</tr>
<tr>
<td>[[HourCycle]]</td>
<td>*"hourCycle"*</td>
</tr>
<tr>
<td></td>
<td>*"hour12"*</td>
</tr>
<tr>
<td>[[Weekday]]</td>
<td>*"weekday"*</td>
</tr>
<tr>
<td><ins>[[EraDisplay]]</ins></td>
<td><ins>*"eraDisplay"*</ins></td>
</tr>
<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>[[DayPeriod]]</td>
<td>*"dayPeriod"*</td>
</tr>
<tr>
<td>[[Hour]]</td>
<td>*"hour"*</td>
</tr>
<tr>
<td>[[Minute]]</td>
<td>*"minute"*</td>
</tr>
<tr>
<td>[[Second]]</td>
<td>*"second"*</td>
</tr>
<tr>
<td>[[FractionalSecondDigits]]</td>
<td>*"fractionalSecondDigits"*</td>
</tr>
<tr>
<td>[[TimeZoneName]]</td>
<td>*"timeZoneName"*</td>
</tr>
<tr>
<td>[[DateStyle]]</td>
<td>*"dateStyle"*</td>
</tr>
<tr>
<td>[[TimeStyle]]</td>
<td>*"timeStyle"*</td>
</tr>
</table>
</emu-table>
<p>
For web compatibility reasons, if the property *"hourCycle"* is set, the *"hour12"* property should be set to *true* when *"hourCycle"* is *"h11"* or *"h12"*, or to *false* when *"hourCycle"* is *"h23"* or *"h24"*.
</p>
<emu-note>
In this version of the ECMAScript 2023 Internationalization API, the *"timeZone"* property will be the name of the default time zone if no *"timeZone"* property was provided in the options object provided to the Intl.DateTimeFormat constructor. The first edition left the *"timeZone"* property *undefined* in this case.
</emu-note>
<emu-note>
For compatibility with versions prior to the fifth edition, the *"hour12"* property is set in addition to the *"hourCycle"* property.
</emu-note>
</emu-clause>
</emu-clause>
<emu-clause id="sec-properties-of-intl-datetimeformat-instances">
<h1>Properties of Intl.DateTimeFormat Instances</h1>
<p>
Intl.DateTimeFormat instances are ordinary objects that inherit properties from %DateTimeFormat.prototype%.
</p>
<p>
Intl.DateTimeFormat instances have an [[InitializedDateTimeFormat]] internal slot.
</p>
<p>
Intl.DateTimeFormat instances also have several internal slots that are computed by the constructor:
</p>
<ul>
<li>[[Locale]] is a String value with the language tag of the locale whose localization is used for formatting.</li>
<li>[[Calendar]] is a String value with the *"type"* given in Unicode Technical Standard 35 for the calendar used for formatting.</li>
<li>[[NumberingSystem]] is a String value with the *"type"* given in Unicode Technical Standard 35 for the numbering system used for formatting.</li>
<li>[[TimeZone]] is a String value with the IANA time zone name of the time zone used for formatting.</li>
<li>[[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[DayPeriod]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]] are each either *undefined*, indicating that the component is not used for formatting, or one of the String values given in <emu-xref href="#table-datetimeformat-components"></emu-xref>, indicating how the component should be presented in the formatted output.</li>
<li>[[FractionalSecondDigits]] is either *undefined* or a positive, non-zero integer Number value indicating the fraction digits to be used for fractional seconds. Numbers will be rounded or padded with trailing zeroes if necessary.</li>
<li>[[HourCycle]] is a String value indicating whether the 12-hour format (*"h11"*, *"h12"*) or the 24-hour format (*"h23"*, *"h24"*) should be used. *"h11"* and *"h23"* start with hour 0 and go up to 11 and 23 respectively. *"h12"* and *"h24"* start with hour 1 and go up to 12 and 24. [[HourCycle]] is only used when [[Hour]] is not *undefined*.</li>
<li><ins>[[EraDisplay]] is a String value indicating if a test on the _x_ Number passed to the PartitionDateTimePattern abstract operation should be done in order to possibly skip the [[Era]] component.</ins></li>
<li>[[DateStyle]], [[TimeStyle]] are each either *undefined*, or a String value with values *"full"*, *"long"*, *"medium"*, or *"short"*.</li>
<li>[[Pattern]] is a String value as described in <emu-xref href="#sec-intl.datetimeformat-internal-slots"></emu-xref>.</li>
<li>[[PatternEra]] is a Record as described in <emu-xref href="#sec-intl.datetimeformat-internal-slots"></emu-xref>.</li>
<li>[[RangePatterns]] is a Record as described in <emu-xref href="#sec-intl.datetimeformat-internal-slots"></emu-xref>.</li>
</ul>
<p>
Finally, Intl.DateTimeFormat instances have a [[BoundFormat]] internal slot that caches the function returned by the format accessor (<emu-xref href="#sec-intl.datetimeformat.prototype.format"></emu-xref>).
</p>
</emu-clause>
<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*<sub>𝔽</sub>, *2*<sub>𝔽</sub>, *3*<sub>𝔽</sub></td>
</tr>
<tr>
<td>[[TimeZoneName]]</td>
<td>*"timeZoneName"*</td>
<td>*"short"*, *"long"*, *"shortOffset"*, *"longOffset"*, *"shortGeneric"*, *"longGeneric"*</td>
</tr>
</table>
</emu-table>
<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 OrdinaryObjectCreate(_options_).
1. Let _needDefaults_ be *true*.
1. If _required_ is *"date"* or *"any"*, then
1. For each property name _prop_ of « *"weekday"*, *"year"*, *"month"*, *"day"* », do
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 property name _prop_ of « *"dayPeriod"*, *"hour"*, *"minute"*, *"second"*, *"fractionalSecondDigits"* », do
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 property name _prop_ of « *"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 property name _prop_ of « *"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_, _styles_ )</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 _styles_, which is a record from %DateTimeFormat%.[[LocaleData]].[[<_locale_>]].[[styles]].[[<_calendar_>]] for some locale _locale_ and calendar _calendar_. 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 _styles_.[[TimeFormat]].[[<_timeStyle_>]].
1. If _dateStyle_ is not *undefined*, then
1. Assert: _dateStyle_ is one of *"full"*, *"long"*, *"medium"*, or *"short"*.
1. Let _dateFormat_ be _styles_.[[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>[[patternEra]],</ins> and [[rangePatterns]].
1. Add to _format_ all fields from _timeFormat_ except [[pattern]], <ins>[[patternEra]],</ins>, [[rangePatterns]], [[pattern12]], and [[rangePatterns12]], if present.
1. Let _connector_ be _styles_.[[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 class="block">If _dateFormat_ has a [[patternEra]] field, then</ins>
1. <ins class="block">Let _patternEra_ be the string _connector_ with the substring *"{0}"* replaced with _timeFormat_.[[pattern]] and the substring *"{1}"* replaced with _dateFormat_.[[patternEra]].</ins>
1. <ins class="block">Set _format_.[[patternEra]] to _patternEra_.</ins>
1. <ins class="block">If _dateFormat_ has a [[patternEra]] field and _timeFormat_ has a [[pattern12]] field, then</ins>
1. <ins class="block">Let _pattern12Era_ be the string _connector_ with the substring *"{0}"* replaced with _timeFormat_.[[pattern12]] and the substring *"{1}"* replaced with _dateFormat_.[[patternEra]].</ins>
1. <ins class="block">Set _format_.[[pattern12Era]] to _pattern12Era_.</ins>
1. Let _dateTimeRangeFormat_ be _styles_.[[DateTimeRangeFormat]].[[<_dateStyle_>]].[[<_timeStyle_>]].
1. Set _format_.[[rangePatterns]] to _dateTimeRangeFormat_.[[rangePatterns]].
1. If _dateTimeRangeFormat_ has a [[rangePatterns12]] field, then
1. Set _format_.[[rangePatterns12]] to _dateTimeRangeFormat_.[[rangePatterns12]].
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 _offsetPenalty_ be 1.
1. Let _bestScore_ be -*Infinity*.
1. Let _bestFormat_ be *undefined*.
1. Assert: Type(_formats_) is List.
1. For each element _format_ of _formats_, do
1. Let _score_ be 0.
1. For each property name _property_ shown in <emu-xref href="#table-datetimeformat-components"></emu-xref>, do
1. If _options_ has a field [[<_property_>]], let _optionsProp_ be _options_.[[<_property_>]]; else let _optionsProp_ be *undefined*.
1. If _format_ has a field [[<_property_>]], let _formatProp_ be _format_.[[<_property_>]]; else let _formatProp_ be *undefined*.
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 _property_ is *"timeZoneName"*, then
1. If _optionsProp_ is *"short"* or *"shortGeneric"*, then
1. If _formatProp_ is *"shortOffset"*, decrease _score_ by _offsetPenalty_.
1. Else if _formatProp_ is *"longOffset"*, decrease _score_ by (_offsetPenalty_ + _shortMorePenalty_).
1. Else if _optionsProp_ is *"short"* and _formatProp_ is *"long"*, decrease _score_ by _shortMorePenalty_.
1. Else if _optionsProp_ is *"shortGeneric"* and _formatProp_ is *"longGeneric"*, decrease _score_ by _shortMorePenalty_.
1. Else if _optionsProp_ ≠ _formatProp_, decrease _score_ by _removalPenalty_.
1. Else if _optionsProp_ is *"shortOffset"* and _formatProp_ is *"longOffset"*, decrease _score_ by _shortMorePenalty_.
1. Else if _optionsProp_ is *"long"* or *"longGeneric"*, then
1. If _formatProp_ is *"longOffset"*, decrease _score_ by _offsetPenalty_.
1. Else if _formatProp_ is *"shortOffset"*, decrease _score_ by (_offsetPenalty_ + _longLessPenalty_).
1. Else if _optionsProp_ is *"long"* and _formatProp_ is *"short"*, decrease _score_ by _longLessPenalty_.
1. Else if _optionsProp_ is *"longGeneric"* and _formatProp_ is *"shortGeneric"*, decrease _score_ by _longLessPenalty_.
1. Else if _optionsProp_ ≠ _formatProp_, decrease _score_ by _removalPenalty_.
1. Else if _optionsProp_ is *"longOffset"* and _formatProp_ is *"shortOffset"*, decrease _score_ by _longLessPenalty_.
1. Else if _optionsProp_ ≠ _formatProp_, decrease _score_ by _removalPenalty_.
1. Else if _optionsProp_ ≠ _formatProp_, then
1. If _property_ is *"fractionalSecondDigits"*, then
1. Let _values_ be « *1*<sub>𝔽</sub>, *2*<sub>𝔽</sub>, *3*<sub>𝔽</sub> ».
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>FormatDateTimePattern ( _dateTimeFormat_, _patternParts_, _x_, _rangeFormatOptions_ )</h1>
<p>
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 es2023, <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:
</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 OrdinaryObjectCreate(*null*).
1. Perform ! CreateDataPropertyOrThrow(_nfOptions_, *"useGrouping"*, *false*).
1. Let _nf_ be ? Construct(%NumberFormat%, « _locale_, _nfOptions_ »).
1. Let _nf2Options_ be OrdinaryObjectCreate(*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 OrdinaryObjectCreate(*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_) × 10<sup>6</sup>), _dateTimeFormat_.[[Calendar]], _dateTimeFormat_.[[TimeZone]]).
1. Let _result_ be a new empty List.
1. For each Record { [[Type]], [[Value]] } _patternPart_ in _patternParts_, 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_ is equal to *"dayPeriod"*, then
1. Let _f_ be the value of _dateTimeFormat_'s internal slot whose name is the Internal Slot column of the matching row.
1. Let _fv_ be a String value representing the day period of _tm_ in the form given by _f_; the String value depends upon the implementation and the effective locale of _dateTimeFormat_.
1. Append a new Record { [[Type]]: _p_, [[Value]]: _fv_ } as the last element of the list _result_.
1. Else if _p_ is equal to *"timeZoneName"*, then
1. Let _f_ be _dateTimeFormat_.[[TimeZoneName]].
1. Let _v_ be _dateTimeFormat_.[[TimeZone]].
1. 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 of _dateTimeFormat_. The String value may also depend on the value of the [[InDST]] field of _tm_ if _f_ is *"short"*, *"long"*, *"shortOffset"*, or *"longOffset"*. If the implementation does not have a localized representation of _f_, then use the String value of _v_ itself.
1. Append a new Record { [[Type]]: _p_, [[Value]]: _fv_ } as the last element of the list _result_.
1. Else if _p_ matches a Property column of the row in <emu-xref href="#table-datetimeformat-components"></emu-xref>, then
1. If _rangeFormatOptions_ is not *undefined*, let _f_ be the value of _rangeFormatOptions_'s field whose name matches _p_.
1. Else, 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"* and _rangeFormatOptions_ is *undefined*, then the String value may also depend on whether _dateTimeFormat_.[[Day]] is *undefined*. If _p_ is *"month"* and _rangeFormatOptions_ is not *undefined*, then the String value may also depend on whether _rangeFormatOptions_.[[day]] is *undefined*. If _p_ is *"era"* and _rangeFormatOptions_ is *undefined*, then the String value may also depend on whether _dateTimeFormat_.[[Era]] is *undefined*. If _p_ is *"era"* and _rangeFormatOptions_ is not *undefined*, then the String value may also depend on whether _rangeFormatOptions_.[[era]] is *undefined*. If the implementation does not have a localized representation of _f_, then use the String value of _v_ 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]].