timezone.php
changeset 8 0acb8d9a3194
equal deleted inserted replaced
7:1d6e762433fe 8:0acb8d9a3194
       
     1 <?php
       
     2 
       
     3 define('COOKIE_NAME', 'db_stats_tz');
       
     4 
       
     5 $tz = ( isset($_COOKIE[COOKIE_NAME]) ) ? $_COOKIE[COOKIE_NAME] : 'UTC';
       
     6 $zones = get_raw_timezone_list();
       
     7 if ( in_array($tz, $zones) )
       
     8 {
       
     9   date_default_timezone_set($tz);
       
    10 }
       
    11 
       
    12 /**
       
    13  * List of standard time zones.
       
    14  * @return array
       
    15  */
       
    16 
       
    17 function get_timezone_list()
       
    18 {
       
    19   static $zones = false;
       
    20   if ( !$zones )
       
    21   {
       
    22     $zonelist = get_raw_timezone_list();
       
    23     $zones = array();
       
    24     foreach ( $zonelist as $rawzone )
       
    25     {
       
    26       @list($region, $area, $city) = explode('/', $rawzone);
       
    27       if ( empty($area) )
       
    28       {
       
    29         $zones[$region] = $region;
       
    30         continue;
       
    31       }
       
    32       if ( !isset($zones[$region]) )
       
    33         $zones[$region] = array();
       
    34       
       
    35       if ( empty($city) )
       
    36       {
       
    37         $zones[$region][] = $area;
       
    38       }
       
    39       else
       
    40       {
       
    41         if ( !isset($zones[$region][$area]) || ( isset($zones[$region][$area]) && !is_array($zones[$region][$area]) ) )
       
    42         {
       
    43           $zones[$region][$area] = array();
       
    44         }
       
    45         $zones[$region][$area][] = $city;
       
    46       }
       
    47     }
       
    48   }
       
    49   return $zones;
       
    50 }
       
    51 
       
    52 /**
       
    53  * Get the raw, flat array of time zones.
       
    54  * @return array
       
    55  */
       
    56 
       
    57 function get_raw_timezone_list()
       
    58 {
       
    59   return array(
       
    60     'UTC',
       
    61     'Africa/Abidjan',
       
    62     'Africa/Accra',
       
    63     'Africa/Addis_Ababa',
       
    64     'Africa/Algiers',
       
    65     'Africa/Asmara',
       
    66     'Africa/Asmera',
       
    67     'Africa/Bamako',
       
    68     'Africa/Bangui',
       
    69     'Africa/Banjul',
       
    70     'Africa/Bissau',
       
    71     'Africa/Blantyre',
       
    72     'Africa/Brazzaville',
       
    73     'Africa/Bujumbura',
       
    74     'Africa/Cairo',
       
    75     'Africa/Casablanca',
       
    76     'Africa/Ceuta',
       
    77     'Africa/Conakry',
       
    78     'Africa/Dakar',
       
    79     'Africa/Dar_es_Salaam',
       
    80     'Africa/Djibouti',
       
    81     'Africa/Douala',
       
    82     'Africa/El_Aaiun',
       
    83     'Africa/Freetown',
       
    84     'Africa/Gaborone',
       
    85     'Africa/Harare',
       
    86     'Africa/Johannesburg',
       
    87     'Africa/Kampala',
       
    88     'Africa/Khartoum',
       
    89     'Africa/Kigali',
       
    90     'Africa/Kinshasa',
       
    91     'Africa/Lagos',
       
    92     'Africa/Libreville',
       
    93     'Africa/Lome',
       
    94     'Africa/Luanda',
       
    95     'Africa/Lubumbashi',
       
    96     'Africa/Lusaka',
       
    97     'Africa/Malabo',
       
    98     'Africa/Maputo',
       
    99     'Africa/Maseru',
       
   100     'Africa/Mbabane',
       
   101     'Africa/Mogadishu',
       
   102     'Africa/Monrovia',
       
   103     'Africa/Nairobi',
       
   104     'Africa/Ndjamena',
       
   105     'Africa/Niamey',
       
   106     'Africa/Nouakchott',
       
   107     'Africa/Ouagadougou',
       
   108     'Africa/Porto-Novo',
       
   109     'Africa/Sao_Tome',
       
   110     'Africa/Timbuktu',
       
   111     'Africa/Tripoli',
       
   112     'Africa/Tunis',
       
   113     'Africa/Windhoek',
       
   114     'America/Adak',
       
   115     'America/Anchorage',
       
   116     'America/Anguilla',
       
   117     'America/Antigua',
       
   118     'America/Araguaina',
       
   119     'America/Argentina/Buenos_Aires',
       
   120     'America/Argentina/Catamarca',
       
   121     'America/Argentina/ComodRivadavia',
       
   122     'America/Argentina/Cordoba',
       
   123     'America/Argentina/Jujuy',
       
   124     'America/Argentina/La_Rioja',
       
   125     'America/Argentina/Mendoza',
       
   126     'America/Argentina/Rio_Gallegos',
       
   127     'America/Argentina/San_Juan',
       
   128     'America/Argentina/San_Luis',
       
   129     'America/Argentina/Tucuman',
       
   130     'America/Argentina/Ushuaia',
       
   131     'America/Aruba',
       
   132     'America/Asuncion',
       
   133     'America/Atikokan',
       
   134     'America/Atka',
       
   135     'America/Bahia',
       
   136     'America/Barbados',
       
   137     'America/Belem',
       
   138     'America/Belize',
       
   139     'America/Blanc-Sablon',
       
   140     'America/Boa_Vista',
       
   141     'America/Bogota',
       
   142     'America/Boise',
       
   143     'America/Buenos_Aires',
       
   144     'America/Cambridge_Bay',
       
   145     'America/Campo_Grande',
       
   146     'America/Cancun',
       
   147     'America/Caracas',
       
   148     'America/Catamarca',
       
   149     'America/Cayenne',
       
   150     'America/Cayman',
       
   151     'America/Chicago',
       
   152     'America/Chihuahua',
       
   153     'America/Coral_Harbour',
       
   154     'America/Cordoba',
       
   155     'America/Costa_Rica',
       
   156     'America/Cuiaba',
       
   157     'America/Curacao',
       
   158     'America/Danmarkshavn',
       
   159     'America/Dawson',
       
   160     'America/Dawson_Creek',
       
   161     'America/Denver',
       
   162     'America/Detroit',
       
   163     'America/Dominica',
       
   164     'America/Edmonton',
       
   165     'America/Eirunepe',
       
   166     'America/El_Salvador',
       
   167     'America/Ensenada',
       
   168     'America/Fort_Wayne',
       
   169     'America/Fortaleza',
       
   170     'America/Glace_Bay',
       
   171     'America/Godthab',
       
   172     'America/Goose_Bay',
       
   173     'America/Grand_Turk',
       
   174     'America/Grenada',
       
   175     'America/Guadeloupe',
       
   176     'America/Guatemala',
       
   177     'America/Guayaquil',
       
   178     'America/Guyana',
       
   179     'America/Halifax',
       
   180     'America/Havana',
       
   181     'America/Hermosillo',
       
   182     'America/Indiana/Indianapolis',
       
   183     'America/Indiana/Knox',
       
   184     'America/Indiana/Marengo',
       
   185     'America/Indiana/Petersburg',
       
   186     'America/Indiana/Tell_City',
       
   187     'America/Indiana/Vevay',
       
   188     'America/Indiana/Vincennes',
       
   189     'America/Indiana/Winamac',
       
   190     'America/Indianapolis',
       
   191     'America/Inuvik',
       
   192     'America/Iqaluit',
       
   193     'America/Jamaica',
       
   194     'America/Jujuy',
       
   195     'America/Juneau',
       
   196     'America/Kentucky/Louisville',
       
   197     'America/Kentucky/Monticello',
       
   198     'America/Knox_IN',
       
   199     'America/La_Paz',
       
   200     'America/Lima',
       
   201     'America/Los_Angeles',
       
   202     'America/Louisville',
       
   203     'America/Maceio',
       
   204     'America/Managua',
       
   205     'America/Manaus',
       
   206     'America/Marigot',
       
   207     'America/Martinique',
       
   208     'America/Mazatlan',
       
   209     'America/Mendoza',
       
   210     'America/Menominee',
       
   211     'America/Merida',
       
   212     'America/Mexico_City',
       
   213     'America/Miquelon',
       
   214     'America/Moncton',
       
   215     'America/Monterrey',
       
   216     'America/Montevideo',
       
   217     'America/Montreal',
       
   218     'America/Montserrat',
       
   219     'America/Nassau',
       
   220     'America/New_York',
       
   221     'America/Nipigon',
       
   222     'America/Nome',
       
   223     'America/Noronha',
       
   224     'America/North_Dakota/Center',
       
   225     'America/North_Dakota/New_Salem',
       
   226     'America/Panama',
       
   227     'America/Pangnirtung',
       
   228     'America/Paramaribo',
       
   229     'America/Phoenix',
       
   230     'America/Port-au-Prince',
       
   231     'America/Port_of_Spain',
       
   232     'America/Porto_Acre',
       
   233     'America/Porto_Velho',
       
   234     'America/Puerto_Rico',
       
   235     'America/Rainy_River',
       
   236     'America/Rankin_Inlet',
       
   237     'America/Recife',
       
   238     'America/Regina',
       
   239     'America/Resolute',
       
   240     'America/Rio_Branco',
       
   241     'America/Rosario',
       
   242     'America/Santiago',
       
   243     'America/Santo_Domingo',
       
   244     'America/Sao_Paulo',
       
   245     'America/Scoresbysund',
       
   246     'America/Shiprock',
       
   247     'America/St_Barthelemy',
       
   248     'America/St_Johns',
       
   249     'America/St_Kitts',
       
   250     'America/St_Lucia',
       
   251     'America/St_Thomas',
       
   252     'America/St_Vincent',
       
   253     'America/Swift_Current',
       
   254     'America/Tegucigalpa',
       
   255     'America/Thule',
       
   256     'America/Thunder_Bay',
       
   257     'America/Tijuana',
       
   258     'America/Toronto',
       
   259     'America/Tortola',
       
   260     'America/Vancouver',
       
   261     'America/Virgin',
       
   262     'America/Whitehorse',
       
   263     'America/Winnipeg',
       
   264     'America/Yakutat',
       
   265     'America/Yellowknife',
       
   266     'Antarctica/Casey',
       
   267     'Antarctica/Davis',
       
   268     'Antarctica/DumontDUrville',
       
   269     'Antarctica/Mawson',
       
   270     'Antarctica/McMurdo',
       
   271     'Antarctica/Palmer',
       
   272     'Antarctica/Rothera',
       
   273     'Antarctica/South_Pole',
       
   274     'Antarctica/Syowa',
       
   275     'Antarctica/Vostok',
       
   276     'Arctic/Longyearbyen',
       
   277     'Asia/Aden',
       
   278     'Asia/Almaty',
       
   279     'Asia/Amman',
       
   280     'Asia/Anadyr',
       
   281     'Asia/Aqtau',
       
   282     'Asia/Aqtobe',
       
   283     'Asia/Ashgabat',
       
   284     'Asia/Ashkhabad',
       
   285     'Asia/Baghdad',
       
   286     'Asia/Bahrain',
       
   287     'Asia/Baku',
       
   288     'Asia/Bangkok',
       
   289     'Asia/Beirut',
       
   290     'Asia/Bishkek',
       
   291     'Asia/Brunei',
       
   292     'Asia/Calcutta',
       
   293     'Asia/Choibalsan',
       
   294     'Asia/Chongqing',
       
   295     'Asia/Chungking',
       
   296     'Asia/Colombo',
       
   297     'Asia/Dacca',
       
   298     'Asia/Damascus',
       
   299     'Asia/Dhaka',
       
   300     'Asia/Dili',
       
   301     'Asia/Dubai',
       
   302     'Asia/Dushanbe',
       
   303     'Asia/Gaza',
       
   304     'Asia/Harbin',
       
   305     'Asia/Ho_Chi_Minh',
       
   306     'Asia/Hong_Kong',
       
   307     'Asia/Hovd',
       
   308     'Asia/Irkutsk',
       
   309     'Asia/Istanbul',
       
   310     'Asia/Jakarta',
       
   311     'Asia/Jayapura',
       
   312     'Asia/Jerusalem',
       
   313     'Asia/Kabul',
       
   314     'Asia/Kamchatka',
       
   315     'Asia/Karachi',
       
   316     'Asia/Kashgar',
       
   317     'Asia/Katmandu',
       
   318     'Asia/Kolkata',
       
   319     'Asia/Krasnoyarsk',
       
   320     'Asia/Kuala_Lumpur',
       
   321     'Asia/Kuching',
       
   322     'Asia/Kuwait',
       
   323     'Asia/Macao',
       
   324     'Asia/Macau',
       
   325     'Asia/Magadan',
       
   326     'Asia/Makassar',
       
   327     'Asia/Manila',
       
   328     'Asia/Muscat',
       
   329     'Asia/Nicosia',
       
   330     'Asia/Novosibirsk',
       
   331     'Asia/Omsk',
       
   332     'Asia/Oral',
       
   333     'Asia/Phnom_Penh',
       
   334     'Asia/Pontianak',
       
   335     'Asia/Pyongyang',
       
   336     'Asia/Qatar',
       
   337     'Asia/Qyzylorda',
       
   338     'Asia/Rangoon',
       
   339     'Asia/Riyadh',
       
   340     'Asia/Saigon',
       
   341     'Asia/Sakhalin',
       
   342     'Asia/Samarkand',
       
   343     'Asia/Seoul',
       
   344     'Asia/Shanghai',
       
   345     'Asia/Singapore',
       
   346     'Asia/Taipei',
       
   347     'Asia/Tashkent',
       
   348     'Asia/Tbilisi',
       
   349     'Asia/Tehran',
       
   350     'Asia/Tel_Aviv',
       
   351     'Asia/Thimbu',
       
   352     'Asia/Thimphu',
       
   353     'Asia/Tokyo',
       
   354     'Asia/Ujung_Pandang',
       
   355     'Asia/Ulaanbaatar',
       
   356     'Asia/Ulan_Bator',
       
   357     'Asia/Urumqi',
       
   358     'Asia/Vientiane',
       
   359     'Asia/Vladivostok',
       
   360     'Asia/Yakutsk',
       
   361     'Asia/Yekaterinburg',
       
   362     'Asia/Yerevan',
       
   363     'Atlantic/Azores',
       
   364     'Atlantic/Bermuda',
       
   365     'Atlantic/Canary',
       
   366     'Atlantic/Cape_Verde',
       
   367     'Atlantic/Faeroe',
       
   368     'Atlantic/Faroe',
       
   369     'Atlantic/Jan_Mayen',
       
   370     'Atlantic/Madeira',
       
   371     'Atlantic/Reykjavik',
       
   372     'Atlantic/South_Georgia',
       
   373     'Atlantic/St_Helena',
       
   374     'Atlantic/Stanley',
       
   375     'Australia/ACT',
       
   376     'Australia/Adelaide',
       
   377     'Australia/Brisbane',
       
   378     'Australia/Broken_Hill',
       
   379     'Australia/Canberra',
       
   380     'Australia/Currie',
       
   381     'Australia/Darwin',
       
   382     'Australia/Eucla',
       
   383     'Australia/Hobart',
       
   384     'Australia/LHI',
       
   385     'Australia/Lindeman',
       
   386     'Australia/Lord_Howe',
       
   387     'Australia/Melbourne',
       
   388     'Australia/North',
       
   389     'Australia/NSW',
       
   390     'Australia/Perth',
       
   391     'Australia/Queensland',
       
   392     'Australia/South',
       
   393     'Australia/Sydney',
       
   394     'Australia/Tasmania',
       
   395     'Australia/Victoria',
       
   396     'Australia/West',
       
   397     'Australia/Yancowinna',
       
   398     'Europe/Amsterdam',
       
   399     'Europe/Andorra',
       
   400     'Europe/Athens',
       
   401     'Europe/Belfast',
       
   402     'Europe/Belgrade',
       
   403     'Europe/Berlin',
       
   404     'Europe/Bratislava',
       
   405     'Europe/Brussels',
       
   406     'Europe/Bucharest',
       
   407     'Europe/Budapest',
       
   408     'Europe/Chisinau',
       
   409     'Europe/Copenhagen',
       
   410     'Europe/Dublin',
       
   411     'Europe/Gibraltar',
       
   412     'Europe/Guernsey',
       
   413     'Europe/Helsinki',
       
   414     'Europe/Isle_of_Man',
       
   415     'Europe/Istanbul',
       
   416     'Europe/Jersey',
       
   417     'Europe/Kaliningrad',
       
   418     'Europe/Kiev',
       
   419     'Europe/Lisbon',
       
   420     'Europe/Ljubljana',
       
   421     'Europe/London',
       
   422     'Europe/Luxembourg',
       
   423     'Europe/Madrid',
       
   424     'Europe/Malta',
       
   425     'Europe/Mariehamn',
       
   426     'Europe/Minsk',
       
   427     'Europe/Monaco',
       
   428     'Europe/Moscow',
       
   429     'Europe/Nicosia',
       
   430     'Europe/Oslo',
       
   431     'Europe/Paris',
       
   432     'Europe/Podgorica',
       
   433     'Europe/Prague',
       
   434     'Europe/Riga',
       
   435     'Europe/Rome',
       
   436     'Europe/Samara',
       
   437     'Europe/San_Marino',
       
   438     'Europe/Sarajevo',
       
   439     'Europe/Simferopol',
       
   440     'Europe/Skopje',
       
   441     'Europe/Sofia',
       
   442     'Europe/Stockholm',
       
   443     'Europe/Tallinn',
       
   444     'Europe/Tirane',
       
   445     'Europe/Tiraspol',
       
   446     'Europe/Uzhgorod',
       
   447     'Europe/Vaduz',
       
   448     'Europe/Vatican',
       
   449     'Europe/Vienna',
       
   450     'Europe/Vilnius',
       
   451     'Europe/Volgograd',
       
   452     'Europe/Warsaw',
       
   453     'Europe/Zagreb',
       
   454     'Europe/Zaporozhye',
       
   455     'Europe/Zurich',
       
   456     'Indian/Antananarivo',
       
   457     'Indian/Chagos',
       
   458     'Indian/Christmas',
       
   459     'Indian/Cocos',
       
   460     'Indian/Comoro',
       
   461     'Indian/Kerguelen',
       
   462     'Indian/Mahe',
       
   463     'Indian/Maldives',
       
   464     'Indian/Mauritius',
       
   465     'Indian/Mayotte',
       
   466     'Indian/Reunion',
       
   467     'Pacific/Apia',
       
   468     'Pacific/Auckland',
       
   469     'Pacific/Chatham',
       
   470     'Pacific/Easter',
       
   471     'Pacific/Efate',
       
   472     'Pacific/Enderbury',
       
   473     'Pacific/Fakaofo',
       
   474     'Pacific/Fiji',
       
   475     'Pacific/Funafuti',
       
   476     'Pacific/Galapagos',
       
   477     'Pacific/Gambier',
       
   478     'Pacific/Guadalcanal',
       
   479     'Pacific/Guam',
       
   480     'Pacific/Honolulu',
       
   481     'Pacific/Johnston',
       
   482     'Pacific/Kiritimati',
       
   483     'Pacific/Kosrae',
       
   484     'Pacific/Kwajalein',
       
   485     'Pacific/Majuro',
       
   486     'Pacific/Marquesas',
       
   487     'Pacific/Midway',
       
   488     'Pacific/Nauru',
       
   489     'Pacific/Niue',
       
   490     'Pacific/Norfolk',
       
   491     'Pacific/Noumea',
       
   492     'Pacific/Pago_Pago',
       
   493     'Pacific/Palau',
       
   494     'Pacific/Pitcairn',
       
   495     'Pacific/Ponape',
       
   496     'Pacific/Port_Moresby',
       
   497     'Pacific/Rarotonga',
       
   498     'Pacific/Saipan',
       
   499     'Pacific/Samoa',
       
   500     'Pacific/Tahiti',
       
   501     'Pacific/Tarawa',
       
   502     'Pacific/Tongatapu',
       
   503     'Pacific/Truk',
       
   504     'Pacific/Wake',
       
   505     'Pacific/Wallis',
       
   506     'Pacific/Yap'
       
   507   );
       
   508 }
       
   509 
       
   510 ?>