File tree Expand file tree Collapse file tree 4 files changed +40
-7
lines changed Expand file tree Collapse file tree 4 files changed +40
-7
lines changed Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ public static function exists(string $locale): bool
44
44
45
45
return true ;
46
46
} catch (MissingResourceException $ e ) {
47
- return false ;
47
+ return \in_array ( $ locale , self :: getAliases (), true ) ;
48
48
}
49
49
}
50
50
@@ -53,7 +53,15 @@ public static function exists(string $locale): bool
53
53
*/
54
54
public static function getName (string $ locale , string $ displayLocale = null ): string
55
55
{
56
- return self ::readEntry (['Names ' , $ locale ], $ displayLocale );
56
+ try {
57
+ return self ::readEntry (['Names ' , $ locale ], $ displayLocale );
58
+ } catch (MissingResourceException $ e ) {
59
+ if (false === $ aliased = array_search ($ locale , self ::getAliases (), true )) {
60
+ throw $ e ;
61
+ }
62
+
63
+ return self ::readEntry (['Names ' , $ aliased ], $ displayLocale );
64
+ }
57
65
}
58
66
59
67
/**
Original file line number Diff line number Diff line change @@ -93,9 +93,16 @@ public function testGetNameWithInvalidLocale()
93
93
Locales::getName ('foo ' );
94
94
}
95
95
96
+ public function testGetNameWithAliasLocale ()
97
+ {
98
+ $ this ->assertSame (Locales::getName ('tl_PH ' ), Locales::getName ('fil_PH ' ));
99
+ }
100
+
96
101
public function testExists ()
97
102
{
98
103
$ this ->assertTrue (Locales::exists ('nl_NL ' ));
104
+ $ this ->assertTrue (Locales::exists ('tl_PH ' ));
105
+ $ this ->assertTrue (Locales::exists ('fil_PH ' )); // alias for "tl_PH"
99
106
$ this ->assertFalse (Locales::exists ('zxx_ZZ ' ));
100
107
}
101
108
}
Original file line number Diff line number Diff line change @@ -530,14 +530,23 @@ public function testGetNameDefaultLocale()
530
530
/**
531
531
* @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
532
532
*/
533
- public function testGetNameWithInvalidTimezoneId ()
533
+ public function testGetNameWithInvalidTimezone ()
534
534
{
535
535
Timezones::getName ('foo ' );
536
536
}
537
537
538
+ /**
539
+ * @expectedException \Symfony\Component\Intl\Exception\MissingResourceException
540
+ */
541
+ public function testGetNameWithAliasTimezone ()
542
+ {
543
+ Timezones::getName ('US/Pacific ' ); // alias in icu (not compiled), name unavailable in php
544
+ }
545
+
538
546
public function testExists ()
539
547
{
540
548
$ this ->assertTrue (Timezones::exists ('Europe/Amsterdam ' ));
549
+ $ this ->assertTrue (Timezones::exists ('US/Pacific ' )); // alias in icu (not compiled), identifier available in php
541
550
$ this ->assertFalse (Timezones::exists ('Etc/Unknown ' ));
542
551
}
543
552
@@ -547,6 +556,9 @@ public function testGetRawOffset()
547
556
$ this ->assertSame (0 , Timezones::getRawOffset ('Etc/UTC ' ));
548
557
$ this ->assertSame (-10800 , Timezones::getRawOffset ('America/Buenos_Aires ' ));
549
558
$ this ->assertSame (20700 , Timezones::getRawOffset ('Asia/Katmandu ' ));
559
+
560
+ // ensure we support identifiers available in php (not compiled from icu)
561
+ Timezones::getRawOffset ('US/Pacific ' );
550
562
}
551
563
552
564
/**
Original file line number Diff line number Diff line change @@ -36,12 +36,18 @@ public static function exists(string $timezone): bool
36
36
37
37
return true ;
38
38
} catch (MissingResourceException $ e ) {
39
- return false ;
39
+ try {
40
+ new \DateTimeZone ($ timezone );
41
+
42
+ return true ;
43
+ } catch (\Exception $ e ) {
44
+ return false ;
45
+ }
40
46
}
41
47
}
42
48
43
49
/**
44
- * @throws MissingResourceException if the timezone identifier does not exists
50
+ * @throws MissingResourceException if the timezone identifier does not exist or is an alias
45
51
*/
46
52
public static function getName (string $ timezone , string $ displayLocale = null ): string
47
53
{
@@ -57,7 +63,7 @@ public static function getNames(string $displayLocale = null): array
57
63
}
58
64
59
65
/**
60
- * @throws \Exception if the timezone identifier does not exists
66
+ * @throws \Exception if the timezone identifier does not exist
61
67
* @throws RuntimeException if there's no timezone DST transition information available
62
68
*/
63
69
public static function getRawOffset (string $ timezone , int $ timestamp = null ): int
@@ -92,7 +98,7 @@ public static function getCountryCode(string $timezone): string
92
98
}
93
99
94
100
/**
95
- * @throws MissingResourceException if the country code does not exists
101
+ * @throws MissingResourceException if the country code does not exist
96
102
*/
97
103
public static function forCountryCode (string $ country ): array
98
104
{
You can’t perform that action at this time.
0 commit comments