Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. function findTimezoneByCountry($country)
  2. {
  3. try {
  4. $default = 'UTC';
  5.  
  6. if (!in_array($country, array_column((new ISO3166())->getAll(), 'alpha2'))) {
  7. return $default;
  8. }
  9.  
  10. $timezone = \DateTimeZone::listIdentifiers(\DateTimeZone::PER_COUNTRY, $country);
  11.  
  12. if (false === $timezone) {
  13. return $default;
  14. }
  15.  
  16. return $timezone[0];
  17.  
  18.  
  19. } catch (\DomainException $e) {
  20. return $default;
  21. }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement