You are here

date_timezone.install in Date 5.2

Installation file for Date Timezone

File

date_timezone/date_timezone.install
View source
<?php

function date_timezone_install() {
  $ret = array();
  module_enable(array(
    'date_api',
  ));
  if (version_compare(PHP_VERSION, '5.2', '<')) {
    module_enable(array(
      'date_php4',
    ));
  }
  return $ret;
}
function date_timezone_enable() {
  module_enable(array(
    'date_api',
  ));
  if (version_compare(PHP_VERSION, '5.2', '<')) {
    module_enable(array(
      'date_php4',
    ));
  }
}
function date_timezone_module_uninstall() {
  $ret = array();
  variable_del('date_default_timezone_name');
  return $ret;
}

/**
 * @file
 * Installation file for Date Timezone
 */

/**
 * Implementation of hook_requirements().
 * Make sure a site timezone name has been selected.
 */
function date_timezone_requirements($phase) {
  $requirements = array();
  $t = get_t();
  $error = FALSE;
  $value = array();
  switch ($phase) {
    case 'runtime':
      $tz_name = variable_get('date_default_timezone_name', NULL);
      if ($tz_name === NULL) {
        $error = TRUE;
        $severity = REQUIREMENT_ERROR;
        $value = $t('The Date Timezone module requires you to !link.', array(
          '!link' => l($t('set the site timezone name'), 'admin/settings/date-time'),
        ));
      }
      elseif (function_exists('date_create')) {
        $date = date_now($tz_name);
        if (date_offset_get($date) != variable_get('date_default_timezone', 0)) {
          $error = TRUE;
          $value = $t('The !link may not be correct.', array(
            '!link' => l($t('site timezone name'), 'admin/settings/date-time'),
          ));
          $severity = REQUIREMENT_WARNING;
        }
      }
  }
  if ($error) {
    $requirements['date_default_timezone'] = array(
      'title' => $t('Date Timezone requirements'),
      'value' => $value,
      'severity' => $severity,
    );
  }
  return $requirements;
}

/**
 * Get rid of deprecated timezone names.
 */
function date_timezone_update_5200() {
  $ret = array();
  $old = variable_get('date_default_timezone_name', NULL);
  if (!empty($old)) {
    $new = _date_timezone_replacement($old);
    if (!empty($new) && $new != $old) {
      variable_set('date_default_timezone_name', $new);
    }
  }
  $results = db_query("SELECT DISTINCT timezone_name FROM {users} ORDER BY timezone_name");
  while ($row = db_fetch_object($results)) {
    if (!empty($row->timezone_name)) {
      $new = _date_timezone_replacement($row->timezone_name);
      if (!empty($new) && $new != $row->timezone_name) {
        db_query("UPDATE {users} SET timezone_name = '%s' WHERE timezone_name = '%s'", $new, $row->timezone_name);
      }
    }
  }

  // Make sure the timezone name list gets updated.
  cache_clear_all('date_timezone_identifiers_list', 'cache');
  return $ret;
}

/**
 * Create replacement values for deprecated timezone names.
 */
function _date_timezone_replacement($old) {
  $replace = array(
    'Brazil/Acre' => 'America/Rio_Branco',
    'Brazil/DeNoronha' => 'America/Noronha',
    'Brazil/East' => 'America/Recife',
    'Brazil/West' => 'America/Manaus',
    'Canada/Atlantic' => 'America/Halifax',
    'Canada/Central' => 'America/Winnipeg',
    'Canada/East-Saskatchewan' => 'America/Regina',
    'Canada/Eastern' => 'America/Toronto',
    'Canada/Mountain' => 'America/Edmonton',
    'Canada/Newfoundland' => 'America/St_Johns',
    'Canada/Pacific' => 'America/Vancouver',
    'Canada/Saskatchewan' => 'America/Regina',
    'Canada/Yukon' => 'America/Whitehorse',
    'CET' => 'Europe/Berlin',
    'Chile/Continental' => 'America/Santiago',
    'Chile/EasterIsland' => 'Pacific/Easter',
    'CST6CDT' => 'America/Chicago',
    'Cuba' => 'America/Havana',
    'EET' => 'Europe/Bucharest',
    'Egypt' => 'Africa/Cairo',
    'Eire' => 'Europe/Belfast',
    'EST' => 'America/New_York',
    'EST5EDT' => 'America/New_York',
    'GB' => 'Europe/London',
    'GB-Eire' => 'Europe/Belfast',
    'Etc/GMT' => 'UTC',
    'Etc/GMT+0' => 'UTC',
    'Etc/GMT+1' => 'UTC',
    'Etc/GMT+10' => 'UTC',
    'Etc/GMT+11' => 'UTC',
    'Etc/GMT+12' => 'UTC',
    'Etc/GMT+2' => 'UTC',
    'Etc/GMT+3' => 'UTC',
    'Etc/GMT+4' => 'UTC',
    'Etc/GMT+5' => 'UTC',
    'Etc/GMT+6' => 'UTC',
    'Etc/GMT+7' => 'UTC',
    'Etc/GMT+8' => 'UTC',
    'Etc/GMT+9' => 'UTC',
    'Etc/GMT-0' => 'UTC',
    'Etc/GMT-1' => 'UTC',
    'Etc/GMT-10' => 'UTC',
    'Etc/GMT-11' => 'UTC',
    'Etc/GMT-12' => 'UTC',
    'Etc/GMT-13' => 'UTC',
    'Etc/GMT-14' => 'UTC',
    'Etc/GMT-2' => 'UTC',
    'Etc/GMT-3' => 'UTC',
    'Etc/GMT-4' => 'UTC',
    'Etc/GMT-5' => 'UTC',
    'Etc/GMT-6' => 'UTC',
    'Etc/GMT-7' => 'UTC',
    'Etc/GMT-8' => 'UTC',
    'Etc/GMT-9' => 'UTC',
    'Etc/GMT0' => 'UTC',
    'Etc/Greenwich' => 'UTC',
    'Etc/UCT' => 'UTC',
    'Etc/Universal' => 'UTC',
    'Etc/UTC' => 'UTC',
    'Etc/Zulu' => 'UTC',
    'Factory' => 'UTC',
    'GMT' => 'UTC',
    'GMT+0' => 'UTC',
    'GMT-0' => 'UTC',
    'GMT0' => 'UTC',
    'Hongkong' => 'Asia/Hong_Kong',
    'HST' => 'Pacific/Honolulu',
    'Iceland' => 'Atlantic/Reykjavik',
    'Iran' => 'Asia/Tehran',
    'Israel' => 'Asia/Tel_Aviv',
    'Jamaica' => 'America/Jamaica',
    'Japan' => 'Asia/Tokyo',
    'Kwajalein' => 'Pacific/Kwajalein',
    'Libya' => 'Africa/Tunis',
    'MET' => 'Europe/Budapest',
    'Mexico/BajaNorte' => 'America/Tijuana',
    'Mexico/BajaSur' => 'America/Mazatlan',
    'Mexico/General' => 'America/Mexico_City',
    'MST' => 'America/Boise',
    'MST7MDT' => 'America/Boise',
    'Navajo' => 'America/Phoenix',
    'NZ' => 'Pacific/Auckland',
    'NZ-CHAT' => 'Pacific/Chatham',
    'Poland' => 'Europe/Warsaw',
    'Portugal' => 'Europe/Lisbon',
    'PRC' => 'Asia/Chongqing',
    'PST8PDT' => 'America/Los_Angeles',
    'ROC' => 'Asia/Taipei',
    'ROK' => 'Asia/Seoul',
    'Singapore' => 'Asia/Singapore',
    'Turkey' => 'Europe/Istanbul',
    'US/Alaska' => 'America/Anchorage',
    'US/Aleutian' => 'America/Adak',
    'US/Arizona' => 'America/Phoenix',
    'US/Central' => 'America/Chicago',
    'US/East-Indiana' => 'America/Indianapolis',
    'US/Eastern' => 'America/New_York',
    'US/Hawaii' => 'Pacific/Honolulu',
    'US/Indiana-Starke' => 'America/Indiana/Knox',
    'US/Michigan' => 'America/Detroit',
    'US/Mountain' => 'America/Boise',
    'US/Pacific' => 'America/Los_Angeles',
    'US/Pacific-New' => 'America/Los_Angeles',
    'US/Samoa' => 'Pacific/Samoa',
    'W-SU' => 'Europe/Moscow',
    'WET' => 'Europe/Paris',
  );
  if (array_key_exists($old, $replace)) {
    return $replace[$old];
  }
  else {
    return $old;
  }
}

/**
 * These strings exist only for the extractor to pick them up and make them
 * available for translation. Putting them here keeps them from being parsed
 * on normal pages.
 *
 * Idea borrowed from Event module. Thanks killes!
 */
function date_timezone_translate() {
  t('Africa/Algiers');
  t('Africa/Asmera');
  t('Africa/Bangui');
  t('Africa/Blantyre');
  t('Africa/Brazzaville');
  t('Africa/Bujumbura');
  t('Africa/Cairo');
  t('Africa/Ceuta');
  t('Africa/Dar_es_Salaam');
  t('Africa/Djibouti');
  t('Africa/Douala');
  t('Africa/Gaborone');
  t('Africa/Harare');
  t('Africa/Johannesburg');
  t('Africa/Kampala');
  t('Africa/Khartoum');
  t('Africa/Kigali');
  t('Africa/Kinshasa');
  t('Africa/Lagos');
  t('Africa/Libreville');
  t('Africa/Luanda');
  t('Africa/Lubumbashi');
  t('Africa/Lusaka');
  t('Africa/Malabo');
  t('Africa/Maputo');
  t('Africa/Maseru');
  t('Africa/Mbabane');
  t('Africa/Mogadishu');
  t('Africa/Nairobi');
  t('Africa/Ndjamena');
  t('Africa/Niamey');
  t('Africa/Porto-Novo');
  t('Africa/Tripoli');
  t('Africa/Tunis');
  t('Africa/Windhoek');
  t('America/Adak');
  t('America/Anchorage');
  t('America/Anguilla');
  t('America/Antigua');
  t('America/Araguaina');
  t('America/Aruba');
  t('America/Asuncion');
  t('America/Atka');
  t('America/Barbados');
  t('America/Belem');
  t('America/Belize');
  t('America/Boa_Vista');
  t('America/Bogota');
  t('America/Boise');
  t('America/Buenos_Aires');
  t('America/Cambridge_Bay');
  t('America/Cancun');
  t('America/Caracas');
  t('America/Catamarca');
  t('America/Cayenne');
  t('America/Cayman');
  t('America/Chicago');
  t('America/Chihuahua');
  t('America/Cordoba');
  t('America/Costa_Rica');
  t('America/Cuiaba');
  t('America/Curacao');
  t('America/Dawson');
  t('America/Dawson_Creek');
  t('America/Denver');
  t('America/Detroit');
  t('America/Dominica');
  t('America/Edmonton');
  t('America/Eirunepe');
  t('America/El_Salvador');
  t('America/Ensenada');
  t('America/Fort_Wayne');
  t('America/Fortaleza');
  t('America/Glace_Bay');
  t('America/Godthab');
  t('America/Goose_Bay');
  t('America/Grand_Turk');
  t('America/Grenada');
  t('America/Guadeloupe');
  t('America/Guatemala');
  t('America/Guayaquil');
  t('America/Guyana');
  t('America/Halifax');
  t('America/Havana');
  t('America/Hermosillo');
  t('America/Indiana/Indianapolis');
  t('America/Indiana/Knox');
  t('America/Indiana/Marengo');
  t('America/Indiana/Vevay');
  t('America/Indianapolis');
  t('America/Inuvik');
  t('America/Iqaluit');
  t('America/Jamaica');
  t('America/Jujuy');
  t('America/Juneau');
  t('America/Kentucky/Louisville');
  t('America/Kentucky/Monticello');
  t('America/Knox_IN');
  t('America/La_Paz');
  t('America/Lima');
  t('America/Los_Angeles');
  t('America/Louisville');
  t('America/Maceio');
  t('America/Managua');
  t('America/Manaus');
  t('America/Martinique');
  t('America/Mazatlan');
  t('America/Mendoza');
  t('America/Menominee');
  t('America/Merida');
  t('America/Mexico_City');
  t('America/Miquelon');
  t('America/Monterrey');
  t('America/Montevideo');
  t('America/Montreal');
  t('America/Montserrat');
  t('America/Nassau');
  t('America/New_York');
  t('America/Nipigon');
  t('America/Nome');
  t('America/Noronha');
  t('America/Panama');
  t('America/Pangnirtung');
  t('America/Paramaribo');
  t('America/Phoenix');
  t('America/Port-au-Prince');
  t('America/Port_of_Spain');
  t('America/Porto_Acre');
  t('America/Porto_Velho');
  t('America/Puerto_Rico');
  t('America/Rainy_River');
  t('America/Rankin_Inlet');
  t('America/Recife');
  t('America/Regina');
  t('America/Rio_Branco');
  t('America/Rosario');
  t('America/Santiago');
  t('America/Santo_Domingo');
  t('America/Sao_Paulo');
  t('America/Scoresbysund');
  t('America/Shiprock');
  t('America/St_Johns');
  t('America/St_Kitts');
  t('America/St_Lucia');
  t('America/St_Thomas');
  t('America/St_Vincent');
  t('America/Swift_Current');
  t('America/Tegucigalpa');
  t('America/Thule');
  t('America/Thunder_Bay');
  t('America/Tijuana');
  t('America/Tortola');
  t('America/Vancouver');
  t('America/Virgin');
  t('America/Whitehorse');
  t('America/Winnipeg');
  t('America/Yakutat');
  t('America/Yellowknife');
  t('Antarctica/Casey');
  t('Antarctica/Davis');
  t('Antarctica/DumontDUrville');
  t('Antarctica/Mawson');
  t('Antarctica/McMurdo');
  t('Antarctica/Palmer');
  t('Antarctica/South_Pole');
  t('Antarctica/Syowa');
  t('Antarctica/Vostok');
  t('Arctic/Longyearbyen');
  t('Asia/Aden');
  t('Asia/Almaty');
  t('Asia/Amman');
  t('Asia/Anadyr');
  t('Asia/Aqtau');
  t('Asia/Aqtobe');
  t('Asia/Ashgabat');
  t('Asia/Ashkhabad');
  t('Asia/Baghdad');
  t('Asia/Bahrain');
  t('Asia/Baku');
  t('Asia/Bangkok');
  t('Asia/Beirut');
  t('Asia/Bishkek');
  t('Asia/Brunei');
  t('Asia/Calcutta');
  t('Asia/Chungking');
  t('Asia/Colombo');
  t('Asia/Dacca');
  t('Asia/Damascus');
  t('Asia/Dhaka');
  t('Asia/Dili');
  t('Asia/Dubai');
  t('Asia/Dushanbe');
  t('Asia/Gaza');
  t('Asia/Harbin');
  t('Asia/Hong_Kong');
  t('Asia/Hovd');
  t('Asia/Irkutsk');
  t('Asia/Istanbul');
  t('Asia/Jakarta');
  t('Asia/Jayapura');
  t('Asia/Jerusalem');
  t('Asia/Kabul');
  t('Asia/Kamchatka');
  t('Asia/Karachi');
  t('Asia/Kashgar');
  t('Asia/Katmandu');
  t('Asia/Krasnoyarsk');
  t('Asia/Kuala_Lumpur');
  t('Asia/Kuching');
  t('Asia/Kuwait');
  t('Asia/Macao');
  t('Asia/Magadan');
  t('Asia/Manila');
  t('Asia/Muscat');
  t('Asia/Nicosia');
  t('Asia/Novosibirsk');
  t('Asia/Omsk');
  t('Asia/Phnom_Penh');
  t('Asia/Pyongyang');
  t('Asia/Qatar');
  t('Asia/Rangoon');
  t('Asia/Riyadh');
  t('Asia/Riyadh87');
  t('Asia/Riyadh88');
  t('Asia/Riyadh89');
  t('Asia/Saigon');
  t('Asia/Samarkand');
  t('Asia/Seoul');
  t('Asia/Shanghai');
  t('Asia/Singapore');
  t('Asia/Taipei');
  t('Asia/Tashkent');
  t('Asia/Tbilisi');
  t('Asia/Tehran');
  t('Asia/Tel_Aviv');
  t('Asia/Thimbu');
  t('Asia/Thimphu');
  t('Asia/Tokyo');
  t('Asia/Ujung_Pandang');
  t('Asia/Ulaanbaatar');
  t('Asia/Ulan_Bator');
  t('Asia/Urumqi');
  t('Asia/Vientiane');
  t('Asia/Vladivostok');
  t('Asia/Yakutsk');
  t('Asia/Yekaterinburg');
  t('Asia/Yerevan');
  t('Atlantic/Azores');
  t('Atlantic/Bermuda');
  t('Atlantic/Canary');
  t('Atlantic/Cape_Verde');
  t('Atlantic/Faeroe');
  t('Atlantic/Jan_Mayen');
  t('Atlantic/Madeira');
  t('Atlantic/South_Georgia');
  t('Atlantic/Stanley');
  t('Australia/ACT');
  t('Australia/Adelaide');
  t('Australia/Brisbane');
  t('Australia/Broken_Hill');
  t('Australia/Canberra');
  t('Australia/Darwin');
  t('Australia/Hobart');
  t('Australia/LHI');
  t('Australia/Lindeman');
  t('Australia/Lord_Howe');
  t('Australia/Melbourne');
  t('Australia/NSW');
  t('Australia/North');
  t('Australia/Perth');
  t('Australia/Queensland');
  t('Australia/South');
  t('Australia/Sydney');
  t('Australia/Tasmania');
  t('Australia/Victoria');
  t('Australia/West');
  t('Australia/Yancowinna');
  t('Europe/Amsterdam');
  t('Europe/Andorra');
  t('Europe/Athens');
  t('Europe/Belfast');
  t('Europe/Belgrade');
  t('Europe/Berlin');
  t('Europe/Bratislava');
  t('Europe/Brussels');
  t('Europe/Bucharest');
  t('Europe/Budapest');
  t('Europe/Chisinau');
  t('Europe/Copenhagen');
  t('Europe/Dublin');
  t('Europe/Gibraltar');
  t('Europe/Helsinki');
  t('Europe/Istanbul');
  t('Europe/Kaliningrad');
  t('Europe/Kiev');
  t('Europe/Lisbon');
  t('Europe/Ljubljana');
  t('Europe/London');
  t('Europe/Luxembourg');
  t('Europe/Madrid');
  t('Europe/Malta');
  t('Europe/Minsk');
  t('Europe/Monaco');
  t('Europe/Moscow');
  t('Europe/Nicosia');
  t('Europe/Oslo');
  t('Europe/Paris');
  t('Europe/Prague');
  t('Europe/Riga');
  t('Europe/Rome');
  t('Europe/Samara');
  t('Europe/San_Marino');
  t('Europe/Sarajevo');
  t('Europe/Simferopol');
  t('Europe/Skopje');
  t('Europe/Sofia');
  t('Europe/Stockholm');
  t('Europe/Tallinn');
  t('Europe/Tirane');
  t('Europe/Tiraspol');
  t('Europe/Uzhgorod');
  t('Europe/Vaduz');
  t('Europe/Vatican');
  t('Europe/Vienna');
  t('Europe/Vilnius');
  t('Europe/Warsaw');
  t('Europe/Zagreb');
  t('Europe/Zaporozhye');
  t('Europe/Zurich');
  t('Indian/Antananarivo');
  t('Indian/Chagos');
  t('Indian/Christmas');
  t('Indian/Cocos');
  t('Indian/Comoro');
  t('Indian/Kerguelen');
  t('Indian/Mahe');
  t('Indian/Maldives');
  t('Indian/Mauritius');
  t('Indian/Mayotte');
  t('Indian/Reunion');
  t('Pacific/Apia');
  t('Pacific/Auckland');
  t('Pacific/Chatham');
  t('Pacific/Easter');
  t('Pacific/Efate');
  t('Pacific/Enderbury');
  t('Pacific/Fakaofo');
  t('Pacific/Fiji');
  t('Pacific/Funafuti');
  t('Pacific/Galapagos');
  t('Pacific/Gambier');
  t('Pacific/Guadalcanal');
  t('Pacific/Guam');
  t('Pacific/Honolulu');
  t('Pacific/Johnston');
  t('Pacific/Kiritimati');
  t('Pacific/Kosrae');
  t('Pacific/Kwajalein');
  t('Pacific/Majuro');
  t('Pacific/Marquesas');
  t('Pacific/Midway');
  t('Pacific/Nauru');
  t('Pacific/Niue');
  t('Pacific/Norfolk');
  t('Pacific/Noumea');
  t('Pacific/Pago_Pago');
  t('Pacific/Palau');
  t('Pacific/Pitcairn');
  t('Pacific/Ponape');
  t('Pacific/Port_Moresby');
  t('Pacific/Rarotonga');
  t('Pacific/Saipan');
  t('Pacific/Samoa');
  t('Pacific/Tahiti');
  t('Pacific/Tarawa');
  t('Pacific/Tongatapu');
  t('Pacific/Truk');
  t('Pacific/Wake');
  t('Pacific/Wallis');
  t('Pacific/Yap');
  t('Pacific/French_Polynesia-Marquesas_Islands');
  t('UTC');
}

Functions

Namesort descending Description
date_timezone_enable
date_timezone_install
date_timezone_module_uninstall
date_timezone_requirements Implementation of hook_requirements(). Make sure a site timezone name has been selected.
date_timezone_translate These strings exist only for the extractor to pick them up and make them available for translation. Putting them here keeps them from being parsed on normal pages.
date_timezone_update_5200 Get rid of deprecated timezone names.
_date_timezone_replacement Create replacement values for deprecated timezone names.