Example #1
0
 /**
  * Returns a keyed array of timezone identifiers (keys are the standard PHP timezone names, values are the localized timezone names).
  *
  * @return array
  *
  * @see http://www.php.net/datetimezone.listidentifiers.php
  */
 public function getTimezones()
 {
     static $cache = array();
     $locale = Localization::activeLocale();
     if (array_key_exists($locale, $cache)) {
         $result = $cache[$locale];
     } else {
         $result = array();
         $continentNames = array('Africa' => \Punic\Territory::getName('002'), 'Asia' => \Punic\Territory::getName('142'), 'America' => \Punic\Territory::getName('019'), 'Antarctica' => \Punic\Territory::getName('AQ'), 'Arctic' => t('Arctic'), 'Atlantic' => t('Atlantic Ocean'), 'Australia' => \Punic\Territory::getName('AU'), 'Europe' => \Punic\Territory::getName('150'), 'Indian' => t('Indian Ocean'), 'Pacific' => t('Pacific Ocean'));
         foreach (\DateTimeZone::listIdentifiers() as $timezoneID) {
             switch ($timezoneID) {
                 case 'UTC':
                 case 'GMT':
                     $timezoneName = t('Greenwich Mean Time');
                     break;
                 default:
                     $chunks = explode('/', $timezoneID);
                     if (array_key_exists($chunks[0], $continentNames)) {
                         $chunks[0] = $continentNames[$chunks[0]];
                     }
                     if (count($chunks) > 0) {
                         $city = \Punic\Calendar::getTimezoneExemplarCity($timezoneID, false);
                         if (!strlen($city)) {
                             switch ($timezoneID) {
                                 case 'Antarctica/South_Pole':
                                     $city = t('South Pole');
                                     break;
                                 case 'America/Montreal':
                                     $city = t('Montreal');
                                     break;
                                 case 'America/Shiprock':
                                     $city = t('Shiprock');
                                     break;
                             }
                         }
                         if (strlen($city)) {
                             $chunks = array($chunks[0], $city);
                         }
                     }
                     $timezoneName = implode('/', $chunks);
                     break;
             }
             $result[$timezoneID] = $timezoneName;
         }
         natcasesort($result);
         $cache[$locale] = $result;
     }
     return $result;
 }