May 21, 2019 Javier Eguiluz

Symfony 4.3 will add a new Timezone validator to check that the given value is a valid timezone ID as defined by PHP. In addition to that validator, we've worked hard on many other features to improve the support of timezones.

Added timezones to the Intl component¶ The Intl component added a new Timezone class to get information about timezones, such as their names (in all languages): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 use Symfony\Component\Intl\Timezones ; \Locale :: setDefault ( 'en' ); $timezones = Timezones :: getNames (); // ('timezoneID' => 'timezoneValue') // => ['America/Eirunepe' => 'Acre Time (Eirunepe)', 'America/Rio_Branco' => 'Acre Time (Rio Branco)', ...] $timezones = Timezones :: getNames ( 'de' ); // => ['America/Eirunepe' => 'Acre-Zeit (Eirunepe)', 'America/Rio_Branco' => 'Acre-Zeit (Rio Branco)', ...] $timezone = Timezones :: getName ( 'Africa/Nairobi' ); // => 'East Africa Time (Nairobi)' $timezone = Timezones :: getName ( 'Africa/Nairobi' , 'de' ); // => 'Ostafrikanische Zeit (Nairobi)' You can also check if a given timezone ID is valid: 1 $isValidTimezone = Timezones :: exists ( $timezoneId ); Finally, you can get the timezone offset for any given timezone: 1 2 3 4 5 6 7 $offset = Timezones :: getRawOffset ( 'Etc/UTC' ); // $offset = 0 $offset = Timezones :: getRawOffset ( 'America/Buenos_Aires' ); // $offset = -10800 $offset = Timezones :: getRawOffset ( 'Asia/Katmandu' ); // $offset = 20700 $offset = Timezones :: getGmtOffset ( 'Etc/UTC' ); // $offset = 'GMT+00:00' $offset = Timezones :: getGmtOffset ( 'America/Buenos_Aires' ); // $offset = 'GMT-03:00' $offset = Timezones :: getGmtOffset ( 'Asia/Katmandu' ); // $offset = 'GMT+05:45'

Intl timezones in TimezoneType¶ The TimezoneType form element supports both strings and PHP timezones in its input option (which defines the format the timezone is stored on your underlying object). In Symfony 4.3 this option supports a new value called intltimezone to use \IntlTimeZone objects to store timezones.

Allow Intl timezones in validator¶ The Timezone validator added in Symfony 4.3 has been improved to also consider valid the ICU timezones, not only the PHP timezones. Besides, the list of ICU timezones has been updated to its 64.2 version. The only difference is that expired timezones cannot be used with IntlTimeZone . In practice, this considers valid both UTC (the PHP format) and Etc/UTC (the ICU format), whereas Etc/UTC was considered wrong before (which is not).