Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findTimezoneByCountry($country)
- {
- try {
- $default = 'UTC';
- if (!in_array($country, array_column((new ISO3166())->getAll(), 'alpha2'))) {
- return $default;
- }
- $timezone = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $country);
- if (false === $timezone) {
- return $default;
- }
- return $timezone[0];
- } catch (\DomainException $e) {
- return $default;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement