@@ -105,23 +105,60 @@ public function testFormatThrowsExceptionWhenDateStyleOrTimeStyleMixedWithStyleP
105105
106106 public function testHour12OverridesHourCycle (): void
107107 {
108- $ enLocale = new Locale ('en ' );
108+ $ enLocale = new Locale ('en-u-hc-h11 ' );
109+ $ enLocale = $ enLocale ->withHourCycle ('h23 ' );
110+
109111 $ formatOptions = new DateTimeFormatOptions ([
110- 'dateStyle ' => 'full ' ,
111- 'timeStyle ' => 'full ' ,
112+ 'hour ' => '2-digit ' ,
112113 // Specify both hourCycle and hour12 to show that hour12 overrides hourCycle.
113- 'hourCycle ' => 'h23 ' ,
114114 'hour12 ' => true ,
115+ 'hourCycle ' => 'h24 ' ,
116+ 'minute ' => '2-digit ' ,
117+ 'second ' => '2-digit ' ,
115118 'timeZone ' => 'America/Denver ' ,
116119 ]);
117120
118121 $ enFormatter = new DateTimeFormat ($ enLocale , $ formatOptions );
119122 $ date = new DateTimeImmutable ('@ ' . self ::TS );
120123
121- $ this ->assertSame (
122- 'Monday, June 15, 2020 at 10:48:20 PM Mountain Daylight Time ' ,
123- $ enFormatter ->format ($ date ),
124- );
124+ $ this ->assertSame ('10:48:20 PM ' , $ enFormatter ->format ($ date ));
125+
126+ $ this ->assertSame ('hhmmss ' , $ enFormatter ->getSkeleton ());
127+ $ this ->assertSame ('en-u-hc-h12 ' , $ enFormatter ->getEvaluatedLocale ());
128+ }
129+
130+ public function testEvaluatedLocaleWithNoOptions (): void
131+ {
132+ $ locale = new Locale ('en-US ' );
133+ $ formatter = new DateTimeFormat ($ locale );
134+
135+ // We automatically look up the locale's preferred hour cycle and add it.
136+ $ this ->assertSame ('en-US-u-hc-h12 ' , $ formatter ->getEvaluatedLocale ());
137+ }
138+
139+ public function testEvaluatedLocaleWithOptionsUsingHour12 (): void
140+ {
141+ $ locale = new Locale ('en-US ' );
142+ $ formatter = new DateTimeFormat ($ locale , new DateTimeFormatOptions ([
143+ 'hour12 ' => false ,
144+ 'hourCycle ' => 'h12 ' ,
145+ 'calendar ' => 'islamic ' ,
146+ 'numberingSystem ' => 'thai ' ,
147+ ]));
148+
149+ $ this ->assertSame ('en-US-u-ca-islamic-nu-thai-hc-h23 ' , $ formatter ->getEvaluatedLocale ());
150+ }
151+
152+ public function testEvaluatedLocaleWithOptionsUsingHourCycle (): void
153+ {
154+ $ locale = new Locale ('en-US ' );
155+ $ formatter = new DateTimeFormat ($ locale , new DateTimeFormatOptions ([
156+ 'hourCycle ' => 'h24 ' ,
157+ 'calendar ' => 'coptic ' ,
158+ 'numberingSystem ' => 'mathmono ' ,
159+ ]));
160+
161+ $ this ->assertSame ('en-US-u-ca-coptic-nu-mathmono-hc-h24 ' , $ formatter ->getEvaluatedLocale ());
125162 }
126163
127164 public function testUseHourCycleFromLocale (): void
@@ -130,18 +167,19 @@ public function testUseHourCycleFromLocale(): void
130167 $ enLocale = $ enLocale ->withHourCycle ('h23 ' );
131168
132169 $ formatOptions = new DateTimeFormatOptions ([
133- 'dateStyle ' => 'full ' ,
134- 'timeStyle ' => 'full ' ,
170+ 'hour ' => '2-digit ' ,
171+ 'minute ' => '2-digit ' ,
172+ 'second ' => '2-digit ' ,
135173 'timeZone ' => 'America/Denver ' ,
136174 ]);
137175
138176 $ enFormatter = new DateTimeFormat ($ enLocale , $ formatOptions );
139177 $ date = new DateTimeImmutable ('@ ' . self ::TS );
140178
141- $ this ->assertSame (
142- ' Monday, June 15, 2020 at 10:48:20 PM Mountain Daylight Time ' ,
143- $ enFormatter ->format ( $ date ),
144- );
179+ $ this ->assertSame (' 22:48:20 ' , $ enFormatter -> format ( $ date ));
180+
181+ $ this -> assertSame ( ' HHmmss ' , $ enFormatter ->getSkeleton ());
182+ $ this -> assertSame ( ' en-u-hc-h23 ' , $ enFormatter -> getEvaluatedLocale () );
145183 }
146184
147185 /**
@@ -489,6 +527,78 @@ public function formatProvider(): array
489527 'en ' => 'Monday, June 15, 2020 at 10:48:20 PM Mountain Daylight Time ' ,
490528 'skeleton ' => 'EEEEMMMMdyhmmssazzzz ' ,
491529 ],
530+ [
531+ 'options ' => [
532+ 'dayPeriod ' => 'long ' ,
533+ 'hour ' => 'numeric ' ,
534+ 'minute ' => 'numeric ' ,
535+ 'second ' => 'numeric ' ,
536+ 'timeZone ' => 'America/Chicago ' ,
537+ ],
538+ 'ko ' => '밤 11:48:20 ' ,
539+ 'en ' => '11:48:20 at night ' ,
540+ 'skeleton ' => 'hmsB ' ,
541+ ],
542+ [
543+ 'options ' => [
544+ 'dayPeriod ' => 'short ' ,
545+ 'hour ' => 'numeric ' ,
546+ 'minute ' => 'numeric ' ,
547+ 'second ' => 'numeric ' ,
548+ 'timeZone ' => 'America/Chicago ' ,
549+ ],
550+ 'ko ' => '오후 11:48:20 ' ,
551+ 'en ' => '11:48:20 PM ' ,
552+ 'skeleton ' => 'hmsb ' ,
553+ ],
554+ [
555+ 'options ' => [
556+ 'dayPeriod ' => 'narrow ' ,
557+ 'hour ' => 'numeric ' ,
558+ 'minute ' => 'numeric ' ,
559+ 'second ' => 'numeric ' ,
560+ 'timeZone ' => 'America/Chicago ' ,
561+ ],
562+ 'ko ' => 'PM 11:48:20 ' ,
563+ 'en ' => '11:48:20 p ' ,
564+ 'skeleton ' => 'hmsbbbbb ' ,
565+ ],
566+ [
567+ 'options ' => [
568+ 'dayPeriod ' => 'long ' ,
569+ 'hour ' => 'numeric ' ,
570+ 'minute ' => 'numeric ' ,
571+ 'second ' => 'numeric ' ,
572+ 'timeZone ' => 'Asia/Kolkata ' ,
573+ ],
574+ 'ko ' => '오전 10:18:20 ' ,
575+ 'en ' => '10:18:20 in the morning ' ,
576+ 'skeleton ' => 'hmsB ' ,
577+ ],
578+ [
579+ 'options ' => [
580+ 'dayPeriod ' => 'short ' ,
581+ 'hour ' => 'numeric ' ,
582+ 'minute ' => 'numeric ' ,
583+ 'second ' => 'numeric ' ,
584+ 'timeZone ' => 'Asia/Kolkata ' ,
585+ ],
586+ 'ko ' => '오전 10:18:20 ' ,
587+ 'en ' => '10:18:20 AM ' ,
588+ 'skeleton ' => 'hmsb ' ,
589+ ],
590+ [
591+ 'options ' => [
592+ 'dayPeriod ' => 'narrow ' ,
593+ 'hour ' => 'numeric ' ,
594+ 'minute ' => 'numeric ' ,
595+ 'second ' => 'numeric ' ,
596+ 'timeZone ' => 'Asia/Kolkata ' ,
597+ ],
598+ 'ko ' => 'AM 10:18:20 ' ,
599+ 'en ' => '10:18:20 a ' ,
600+ 'skeleton ' => 'hmsbbbbb ' ,
601+ ],
492602 ];
493603 }
494604
0 commit comments