SHARE
TWEET

Untitled

a guest Oct 12th, 2017 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. if (!function_exists('timezoneArray')) {
  4.  
  5.   /**
  6.    * description
  7.    *
  8.    * @param
  9.    * @return
  10.    */
  11.   function timezoneArray($regions = ["africa", "america", "antarctica", "asia", "atlantic", "australia", "europe", "indian", "pacific"], $detailed = true)
  12.   {
  13.     static $zones = [];
  14.     foreach ($regions as $region) {
  15.       if (strtoupper($region) == "AFRICA") {
  16.         array_push($zones, DateTimeZone::AFRICA);
  17.       } else if (strtoupper($region) == "AMERICA") {
  18.         array_push($zones, DateTimeZone::AMERICA);
  19.       } else if (strtoupper($region) == "ANTARCTICA") {
  20.         array_push($zones, DateTimeZone::ANTARCTICA);
  21.       } else if (strtoupper($region) == "ASIA") {
  22.         array_push($zones, DateTimeZone::ASIA);
  23.       } else if (strtoupper($region) == "ATLANTIC") {
  24.         array_push($zones, DateTimeZone::ATLANTIC);
  25.       } else if (strtoupper($region) == "AUSTRALIA") {
  26.         array_push($zones, DateTimeZone::AUSTRALIA);
  27.       } else if (strtoupper($region) == "EUROPE") {
  28.         array_push($zones, DateTimeZone::EUROPE);
  29.       } else if (strtoupper($region) == "INDIAN") {
  30.         array_push($zones, DateTimeZone::INDIAN);
  31.       } else if (strtoupper($region) == "PACIFIC") {
  32.         array_push($zones, DateTimeZone::PACIFIC);
  33.       }
  34.  
  35.       $timezones = array();
  36.       foreach( $zones as $zone )
  37.       {
  38.         $timezones = array_merge( $timezones, DateTimeZone::listIdentifiers( $zone ) );
  39.       }
  40.  
  41.       $timezone_offsets = array();
  42.       foreach( $timezones as $timezone )
  43.       {
  44.         $tz = new DateTimeZone($timezone);
  45.         $timezone_offsets[$timezone] = $tz->getOffset(new DateTime);
  46.       }
  47.  
  48.       // sort timezone by offset
  49.       asort($timezone_offsets);
  50.  
  51.       $timezone_list = array();
  52.       foreach( $timezone_offsets as $timezone => $offset )
  53.       {
  54.           $offset_prefix = $offset < 0 ? '-' : '+';
  55.           $offset_formatted = gmdate( 'H:i', abs($offset) );
  56.  
  57.           $pretty_offset = "UTC${offset_prefix}${offset_formatted}";
  58.  
  59.           if ($detailed) {
  60.             $timezoneFormatted = $timezone;
  61.           } else {
  62.             $tzFormat = explode('/', $timezone, 2);
  63.             $timezoneFormatted = $tzFormat[1];
  64.           }
  65.           $timezone_list[$timezone] = "(${pretty_offset}) $timezoneFormatted";
  66.  
  67.       }
  68.     }
  69.     return $timezone_list;
  70.   }
  71. }
RAW Paste Data
Top