Mercurial > hg > rc1
comparison plugins/libcalendaring/lib/Sabre/VObject/TimeZoneUtil.php @ 4:888e774ee983
libcalendar plugin as distributed
author | Charlie Root |
---|---|
date | Sat, 13 Jan 2018 08:57:56 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
3:f6fe4b6ae66a | 4:888e774ee983 |
---|---|
1 <?php | |
2 | |
3 namespace Sabre\VObject; | |
4 | |
5 /** | |
6 * Time zone name translation | |
7 * | |
8 * This file translates well-known time zone names into "Olson database" time zone names. | |
9 * | |
10 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/). | |
11 * @author Frank Edelhaeuser (fedel@users.sourceforge.net) | |
12 * @author Evert Pot (http://evertpot.com/) | |
13 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License | |
14 */ | |
15 class TimeZoneUtil { | |
16 | |
17 public static $map = array( | |
18 | |
19 // from http://unicode.org/repos/cldr-tmp/trunk/diff/supplemental/zone_tzid.html | |
20 // snapshot taken on 2012/01/16 | |
21 | |
22 // windows | |
23 'AUS Central Standard Time'=>'Australia/Darwin', | |
24 'AUS Eastern Standard Time'=>'Australia/Sydney', | |
25 'Afghanistan Standard Time'=>'Asia/Kabul', | |
26 'Alaskan Standard Time'=>'America/Anchorage', | |
27 'Arab Standard Time'=>'Asia/Riyadh', | |
28 'Arabian Standard Time'=>'Asia/Dubai', | |
29 'Arabic Standard Time'=>'Asia/Baghdad', | |
30 'Argentina Standard Time'=>'America/Buenos_Aires', | |
31 'Armenian Standard Time'=>'Asia/Yerevan', | |
32 'Atlantic Standard Time'=>'America/Halifax', | |
33 'Azerbaijan Standard Time'=>'Asia/Baku', | |
34 'Azores Standard Time'=>'Atlantic/Azores', | |
35 'Bangladesh Standard Time'=>'Asia/Dhaka', | |
36 'Canada Central Standard Time'=>'America/Regina', | |
37 'Cape Verde Standard Time'=>'Atlantic/Cape_Verde', | |
38 'Caucasus Standard Time'=>'Asia/Yerevan', | |
39 'Cen. Australia Standard Time'=>'Australia/Adelaide', | |
40 'Central America Standard Time'=>'America/Guatemala', | |
41 'Central Asia Standard Time'=>'Asia/Almaty', | |
42 'Central Brazilian Standard Time'=>'America/Cuiaba', | |
43 'Central Europe Standard Time'=>'Europe/Budapest', | |
44 'Central European Standard Time'=>'Europe/Warsaw', | |
45 'Central Pacific Standard Time'=>'Pacific/Guadalcanal', | |
46 'Central Standard Time'=>'America/Chicago', | |
47 'Central Standard Time (Mexico)'=>'America/Mexico_City', | |
48 'China Standard Time'=>'Asia/Shanghai', | |
49 'Dateline Standard Time'=>'Etc/GMT+12', | |
50 'E. Africa Standard Time'=>'Africa/Nairobi', | |
51 'E. Australia Standard Time'=>'Australia/Brisbane', | |
52 'E. Europe Standard Time'=>'Europe/Minsk', | |
53 'E. South America Standard Time'=>'America/Sao_Paulo', | |
54 'Eastern Standard Time'=>'America/New_York', | |
55 'Egypt Standard Time'=>'Africa/Cairo', | |
56 'Ekaterinburg Standard Time'=>'Asia/Yekaterinburg', | |
57 'FLE Standard Time'=>'Europe/Kiev', | |
58 'Fiji Standard Time'=>'Pacific/Fiji', | |
59 'GMT Standard Time'=>'Europe/London', | |
60 'GTB Standard Time'=>'Europe/Istanbul', | |
61 'Georgian Standard Time'=>'Asia/Tbilisi', | |
62 'Greenland Standard Time'=>'America/Godthab', | |
63 'Greenwich Standard Time'=>'Atlantic/Reykjavik', | |
64 'Hawaiian Standard Time'=>'Pacific/Honolulu', | |
65 'India Standard Time'=>'Asia/Calcutta', | |
66 'Iran Standard Time'=>'Asia/Tehran', | |
67 'Israel Standard Time'=>'Asia/Jerusalem', | |
68 'Jordan Standard Time'=>'Asia/Amman', | |
69 'Kamchatka Standard Time'=>'Asia/Kamchatka', | |
70 'Korea Standard Time'=>'Asia/Seoul', | |
71 'Magadan Standard Time'=>'Asia/Magadan', | |
72 'Mauritius Standard Time'=>'Indian/Mauritius', | |
73 'Mexico Standard Time'=>'America/Mexico_City', | |
74 'Mexico Standard Time 2'=>'America/Chihuahua', | |
75 'Mid-Atlantic Standard Time'=>'Etc/GMT-2', | |
76 'Middle East Standard Time'=>'Asia/Beirut', | |
77 'Montevideo Standard Time'=>'America/Montevideo', | |
78 'Morocco Standard Time'=>'Africa/Casablanca', | |
79 'Mountain Standard Time'=>'America/Denver', | |
80 'Mountain Standard Time (Mexico)'=>'America/Chihuahua', | |
81 'Myanmar Standard Time'=>'Asia/Rangoon', | |
82 'N. Central Asia Standard Time'=>'Asia/Novosibirsk', | |
83 'Namibia Standard Time'=>'Africa/Windhoek', | |
84 'Nepal Standard Time'=>'Asia/Katmandu', | |
85 'New Zealand Standard Time'=>'Pacific/Auckland', | |
86 'Newfoundland Standard Time'=>'America/St_Johns', | |
87 'North Asia East Standard Time'=>'Asia/Irkutsk', | |
88 'North Asia Standard Time'=>'Asia/Krasnoyarsk', | |
89 'Pacific SA Standard Time'=>'America/Santiago', | |
90 'Pacific Standard Time'=>'America/Los_Angeles', | |
91 'Pacific Standard Time (Mexico)'=>'America/Santa_Isabel', | |
92 'Pakistan Standard Time'=>'Asia/Karachi', | |
93 'Paraguay Standard Time'=>'America/Asuncion', | |
94 'Romance Standard Time'=>'Europe/Paris', | |
95 'Russian Standard Time'=>'Europe/Moscow', | |
96 'SA Eastern Standard Time'=>'America/Cayenne', | |
97 'SA Pacific Standard Time'=>'America/Bogota', | |
98 'SA Western Standard Time'=>'America/La_Paz', | |
99 'SE Asia Standard Time'=>'Asia/Bangkok', | |
100 'Samoa Standard Time'=>'Pacific/Apia', | |
101 'Singapore Standard Time'=>'Asia/Singapore', | |
102 'South Africa Standard Time'=>'Africa/Johannesburg', | |
103 'Sri Lanka Standard Time'=>'Asia/Colombo', | |
104 'Syria Standard Time'=>'Asia/Damascus', | |
105 'Taipei Standard Time'=>'Asia/Taipei', | |
106 'Tasmania Standard Time'=>'Australia/Hobart', | |
107 'Tokyo Standard Time'=>'Asia/Tokyo', | |
108 'Tonga Standard Time'=>'Pacific/Tongatapu', | |
109 'US Eastern Standard Time'=>'America/Indianapolis', | |
110 'US Mountain Standard Time'=>'America/Phoenix', | |
111 'UTC+12'=>'Etc/GMT-12', | |
112 'UTC-02'=>'Etc/GMT+2', | |
113 'UTC-11'=>'Etc/GMT+11', | |
114 'Ulaanbaatar Standard Time'=>'Asia/Ulaanbaatar', | |
115 'Venezuela Standard Time'=>'America/Caracas', | |
116 'Vladivostok Standard Time'=>'Asia/Vladivostok', | |
117 'W. Australia Standard Time'=>'Australia/Perth', | |
118 'W. Central Africa Standard Time'=>'Africa/Lagos', | |
119 'W. Europe Standard Time'=>'Europe/Berlin', | |
120 'West Asia Standard Time'=>'Asia/Tashkent', | |
121 'West Pacific Standard Time'=>'Pacific/Port_Moresby', | |
122 'Yakutsk Standard Time'=>'Asia/Yakutsk', | |
123 | |
124 // Microsoft exchange timezones | |
125 // Source: | |
126 // http://msdn.microsoft.com/en-us/library/ms988620%28v=exchg.65%29.aspx | |
127 // | |
128 // Correct timezones deduced with help from: | |
129 // http://en.wikipedia.org/wiki/List_of_tz_database_time_zones | |
130 'Universal Coordinated Time' => 'UTC', | |
131 'Casablanca, Monrovia' => 'Africa/Casablanca', | |
132 'Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London' => 'Europe/Lisbon', | |
133 'Greenwich Mean Time; Dublin, Edinburgh, London' => 'Europe/London', | |
134 'Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna' => 'Europe/Berlin', | |
135 'Belgrade, Pozsony, Budapest, Ljubljana, Prague' => 'Europe/Prague', | |
136 'Brussels, Copenhagen, Madrid, Paris' => 'Europe/Paris', | |
137 'Paris, Madrid, Brussels, Copenhagen' => 'Europe/Paris', | |
138 'Prague, Central Europe' => 'Europe/Prague', | |
139 'Sarajevo, Skopje, Sofija, Vilnius, Warsaw, Zagreb' => 'Europe/Sarajevo', | |
140 'West Central Africa' => 'Africa/Luanda', // This was a best guess | |
141 'Athens, Istanbul, Minsk' => 'Europe/Athens', | |
142 'Bucharest' => 'Europe/Bucharest', | |
143 'Cairo' => 'Africa/Cairo', | |
144 'Harare, Pretoria' => 'Africa/Harare', | |
145 'Helsinki, Riga, Tallinn' => 'Europe/Helsinki', | |
146 'Israel, Jerusalem Standard Time' => 'Asia/Jerusalem', | |
147 'Baghdad' => 'Asia/Baghdad', | |
148 'Arab, Kuwait, Riyadh' => 'Asia/Kuwait', | |
149 'Moscow, St. Petersburg, Volgograd' => 'Europe/Moscow', | |
150 'East Africa, Nairobi' => 'Africa/Nairobi', | |
151 'Tehran' => 'Asia/Tehran', | |
152 'Abu Dhabi, Muscat' => 'Asia/Muscat', // Best guess | |
153 'Baku, Tbilisi, Yerevan' => 'Asia/Baku', | |
154 'Kabul' => 'Asia/Kabul', | |
155 'Ekaterinburg' => 'Asia/Yekaterinburg', | |
156 'Islamabad, Karachi, Tashkent' => 'Asia/Karachi', | |
157 'Kolkata, Chennai, Mumbai, New Delhi, India Standard Time' => 'Asia/Calcutta', | |
158 'Kathmandu, Nepal' => 'Asia/Kathmandu', | |
159 'Almaty, Novosibirsk, North Central Asia' => 'Asia/Almaty', | |
160 'Astana, Dhaka' => 'Asia/Dhaka', | |
161 'Sri Jayawardenepura, Sri Lanka' => 'Asia/Colombo', | |
162 'Rangoon' => 'Asia/Rangoon', | |
163 'Bangkok, Hanoi, Jakarta' => 'Asia/Bangkok', | |
164 'Krasnoyarsk' => 'Asia/Krasnoyarsk', | |
165 'Beijing, Chongqing, Hong Kong SAR, Urumqi' => 'Asia/Shanghai', | |
166 'Irkutsk, Ulaan Bataar' => 'Asia/Irkutsk', | |
167 'Kuala Lumpur, Singapore' => 'Asia/Singapore', | |
168 'Perth, Western Australia' => 'Australia/Perth', | |
169 'Taipei' => 'Asia/Taipei', | |
170 'Osaka, Sapporo, Tokyo' => 'Asia/Tokyo', | |
171 'Seoul, Korea Standard time' => 'Asia/Seoul', | |
172 'Yakutsk' => 'Asia/Yakutsk', | |
173 'Adelaide, Central Australia' => 'Australia/Adelaide', | |
174 'Darwin' => 'Australia/Darwin', | |
175 'Brisbane, East Australia' => 'Australia/Brisbane', | |
176 'Canberra, Melbourne, Sydney, Hobart (year 2000 only)' => 'Australia/Sydney', | |
177 'Guam, Port Moresby' => 'Pacific/Guam', | |
178 'Hobart, Tasmania' => 'Australia/Hobart', | |
179 'Vladivostok' => 'Asia/Vladivostok', | |
180 'Magadan, Solomon Is., New Caledonia' => 'Asia/Magadan', | |
181 'Auckland, Wellington' => 'Pacific/Auckland', | |
182 'Fiji Islands, Kamchatka, Marshall Is.' => 'Pacific/Fiji', | |
183 'Nuku\'alofa, Tonga' => 'Pacific/Tongatapu', | |
184 'Azores' => 'Atlantic/Azores', | |
185 'Cape Verde Is.' => 'Atlantic/Cape_Verde', | |
186 'Mid-Atlantic' => 'America/Noronha', | |
187 'Brasilia' => 'America/Sao_Paulo', // Best guess | |
188 'Buenos Aires' => 'America/Argentina/Buenos_Aires', | |
189 'Greenland' => 'America/Godthab', | |
190 'Newfoundland' => 'America/St_Johns', | |
191 'Atlantic Time (Canada)' => 'America/Halifax', | |
192 'Caracas, La Paz' => 'America/Caracas', | |
193 'Santiago' => 'America/Santiago', | |
194 'Bogota, Lima, Quito' => 'America/Bogota', | |
195 'Eastern Time (US & Canada)' => 'America/New_York', | |
196 'Indiana (East)' => 'America/Indiana/Indianapolis', | |
197 'Central America' => 'America/Guatemala', | |
198 'Central Time (US & Canada)' => 'America/Chicago', | |
199 'Mexico City, Tegucigalpa' => 'America/Mexico_City', | |
200 'Saskatchewan' => 'America/Edmonton', | |
201 'Arizona' => 'America/Phoenix', | |
202 'Mountain Time (US & Canada)' => 'America/Denver', // Best guess | |
203 'Pacific Time (US & Canada); Tijuana' => 'America/Los_Angeles', // Best guess | |
204 'Alaska' => 'America/Anchorage', | |
205 'Hawaii' => 'Pacific/Honolulu', | |
206 'Midway Island, Samoa' => 'Pacific/Midway', | |
207 'Eniwetok, Kwajalein, Dateline Time' => 'Pacific/Kwajalein', | |
208 | |
209 // The following list are timezone names that could be generated by | |
210 // Lotus / Domino | |
211 'Dateline' => 'Etc/GMT-12', | |
212 'Samoa' => 'Pacific/Apia', | |
213 'Hawaiian' => 'Pacific/Honolulu', | |
214 'Alaskan' => 'America/Anchorage', | |
215 'Pacific' => 'America/Los_Angeles', | |
216 'Pacific Standard Time' => 'America/Los_Angeles', | |
217 'Mexico Standard Time 2' => 'America/Chihuahua', | |
218 'Mountain' => 'America/Denver', | |
219 'Mountain Standard Time' => 'America/Chihuahua', | |
220 'US Mountain' => 'America/Phoenix', | |
221 'Canada Central' => 'America/Edmonton', | |
222 'Central America' => 'America/Guatemala', | |
223 'Central' => 'America/Chicago', | |
224 'Central Standard Time' => 'America/Mexico_City', | |
225 'Mexico' => 'America/Mexico_City', | |
226 'Eastern' => 'America/New_York', | |
227 'SA Pacific' => 'America/Bogota', | |
228 'US Eastern' => 'America/Indiana/Indianapolis', | |
229 'Venezuela' => 'America/Caracas', | |
230 'Atlantic' => 'America/Halifax', | |
231 'Central Brazilian' => 'America/Manaus', | |
232 'Pacific SA' => 'America/Santiago', | |
233 'SA Western' => 'America/La_Paz', | |
234 'Newfoundland' => 'America/St_Johns', | |
235 'Argentina' => 'America/Argentina/Buenos_Aires', | |
236 'E. South America' => 'America/Belem', | |
237 'Greenland' => 'America/Godthab', | |
238 'Montevideo' => 'America/Montevideo', | |
239 'SA Eastern' => 'America/Belem', | |
240 'Mid-Atlantic' => 'Etc/GMT-2', | |
241 'Azores' => 'Atlantic/Azores', | |
242 'Cape Verde' => 'Atlantic/Cape_Verde', | |
243 'Greenwich' => 'Atlantic/Reykjavik', // No I'm serious.. Greenwich is not GMT. | |
244 'Morocco' => 'Africa/Casablanca', | |
245 'Central Europe' => 'Europe/Prague', | |
246 'Central European' => 'Europe/Sarajevo', | |
247 'Romance' => 'Europe/Paris', | |
248 'W. Central Africa' => 'Africa/Lagos', // Best guess | |
249 'W. Europe' => 'Europe/Amsterdam', | |
250 'E. Europe' => 'Europe/Minsk', | |
251 'Egypt' => 'Africa/Cairo', | |
252 'FLE' => 'Europe/Helsinki', | |
253 'GTB' => 'Europe/Athens', | |
254 'Israel' => 'Asia/Jerusalem', | |
255 'Jordan' => 'Asia/Amman', | |
256 'Middle East' => 'Asia/Beirut', | |
257 'Namibia' => 'Africa/Windhoek', | |
258 'South Africa' => 'Africa/Harare', | |
259 'Arab' => 'Asia/Kuwait', | |
260 'Arabic' => 'Asia/Baghdad', | |
261 'E. Africa' => 'Africa/Nairobi', | |
262 'Georgian' => 'Asia/Tbilisi', | |
263 'Russian' => 'Europe/Moscow', | |
264 'Iran' => 'Asia/Tehran', | |
265 'Arabian' => 'Asia/Muscat', | |
266 'Armenian' => 'Asia/Yerevan', | |
267 'Azerbijan' => 'Asia/Baku', | |
268 'Caucasus' => 'Asia/Yerevan', | |
269 'Mauritius' => 'Indian/Mauritius', | |
270 'Afghanistan' => 'Asia/Kabul', | |
271 'Ekaterinburg' => 'Asia/Yekaterinburg', | |
272 'Pakistan' => 'Asia/Karachi', | |
273 'West Asia' => 'Asia/Tashkent', | |
274 'India' => 'Asia/Calcutta', | |
275 'Sri Lanka' => 'Asia/Colombo', | |
276 'Nepal' => 'Asia/Kathmandu', | |
277 'Central Asia' => 'Asia/Dhaka', | |
278 'N. Central Asia' => 'Asia/Almaty', | |
279 'Myanmar' => 'Asia/Rangoon', | |
280 'North Asia' => 'Asia/Krasnoyarsk', | |
281 'SE Asia' => 'Asia/Bangkok', | |
282 'China' => 'Asia/Shanghai', | |
283 'North Asia East' => 'Asia/Irkutsk', | |
284 'Singapore' => 'Asia/Singapore', | |
285 'Taipei' => 'Asia/Taipei', | |
286 'W. Australia' => 'Australia/Perth', | |
287 'Korea' => 'Asia/Seoul', | |
288 'Tokyo' => 'Asia/Tokyo', | |
289 'Yakutsk' => 'Asia/Yakutsk', | |
290 'AUS Central' => 'Australia/Darwin', | |
291 'Cen. Australia' => 'Australia/Adelaide', | |
292 'AUS Eastern' => 'Australia/Sydney', | |
293 'E. Australia' => 'Australia/Brisbane', | |
294 'Tasmania' => 'Australia/Hobart', | |
295 'Vladivostok' => 'Asia/Vladivostok', | |
296 'West Pacific' => 'Pacific/Guam', | |
297 'Central Pacific' => 'Asia/Magadan', | |
298 'Fiji' => 'Pacific/Fiji', | |
299 'New Zealand' => 'Pacific/Auckland', | |
300 'Tonga' => 'Pacific/Tongatapu', | |
301 ); | |
302 | |
303 /** | |
304 * List of microsoft exchange timezone ids. | |
305 * | |
306 * Source: http://msdn.microsoft.com/en-us/library/aa563018(loband).aspx | |
307 */ | |
308 public static $microsoftExchangeMap = array( | |
309 0 => 'UTC', | |
310 31 => 'Africa/Casablanca', | |
311 | |
312 // Insanely, id #2 is used for both Europe/Lisbon, and Europe/Sarajevo. | |
313 // I'm not even kidding.. We handle this special case in the | |
314 // getTimeZone method. | |
315 2 => 'Europe/Lisbon', | |
316 1 => 'Europe/London', | |
317 4 => 'Europe/Berlin', | |
318 6 => 'Europe/Prague', | |
319 3 => 'Europe/Paris', | |
320 69 => 'Africa/Luanda', // This was a best guess | |
321 7 => 'Europe/Athens', | |
322 5 => 'Europe/Bucharest', | |
323 49 => 'Africa/Cairo', | |
324 50 => 'Africa/Harare', | |
325 59 => 'Europe/Helsinki', | |
326 27 => 'Asia/Jerusalem', | |
327 26 => 'Asia/Baghdad', | |
328 74 => 'Asia/Kuwait', | |
329 51 => 'Europe/Moscow', | |
330 56 => 'Africa/Nairobi', | |
331 25 => 'Asia/Tehran', | |
332 24 => 'Asia/Muscat', // Best guess | |
333 54 => 'Asia/Baku', | |
334 48 => 'Asia/Kabul', | |
335 58 => 'Asia/Yekaterinburg', | |
336 47 => 'Asia/Karachi', | |
337 23 => 'Asia/Calcutta', | |
338 62 => 'Asia/Kathmandu', | |
339 46 => 'Asia/Almaty', | |
340 71 => 'Asia/Dhaka', | |
341 66 => 'Asia/Colombo', | |
342 61 => 'Asia/Rangoon', | |
343 22 => 'Asia/Bangkok', | |
344 64 => 'Asia/Krasnoyarsk', | |
345 45 => 'Asia/Shanghai', | |
346 63 => 'Asia/Irkutsk', | |
347 21 => 'Asia/Singapore', | |
348 73 => 'Australia/Perth', | |
349 75 => 'Asia/Taipei', | |
350 20 => 'Asia/Tokyo', | |
351 72 => 'Asia/Seoul', | |
352 70 => 'Asia/Yakutsk', | |
353 19 => 'Australia/Adelaide', | |
354 44 => 'Australia/Darwin', | |
355 18 => 'Australia/Brisbane', | |
356 76 => 'Australia/Sydney', | |
357 43 => 'Pacific/Guam', | |
358 42 => 'Australia/Hobart', | |
359 68 => 'Asia/Vladivostok', | |
360 41 => 'Asia/Magadan', | |
361 17 => 'Pacific/Auckland', | |
362 40 => 'Pacific/Fiji', | |
363 67 => 'Pacific/Tongatapu', | |
364 29 => 'Atlantic/Azores', | |
365 53 => 'Atlantic/Cape_Verde', | |
366 30 => 'America/Noronha', | |
367 8 => 'America/Sao_Paulo', // Best guess | |
368 32 => 'America/Argentina/Buenos_Aires', | |
369 60 => 'America/Godthab', | |
370 28 => 'America/St_Johns', | |
371 9 => 'America/Halifax', | |
372 33 => 'America/Caracas', | |
373 65 => 'America/Santiago', | |
374 35 => 'America/Bogota', | |
375 10 => 'America/New_York', | |
376 34 => 'America/Indiana/Indianapolis', | |
377 55 => 'America/Guatemala', | |
378 11 => 'America/Chicago', | |
379 37 => 'America/Mexico_City', | |
380 36 => 'America/Edmonton', | |
381 38 => 'America/Phoenix', | |
382 12 => 'America/Denver', // Best guess | |
383 13 => 'America/Los_Angeles', // Best guess | |
384 14 => 'America/Anchorage', | |
385 15 => 'Pacific/Honolulu', | |
386 16 => 'Pacific/Midway', | |
387 39 => 'Pacific/Kwajalein', | |
388 ); | |
389 | |
390 /** | |
391 * This method will try to find out the correct timezone for an iCalendar | |
392 * date-time value. | |
393 * | |
394 * You must pass the contents of the TZID parameter, as well as the full | |
395 * calendar. | |
396 * | |
397 * If the lookup fails, this method will return the default PHP timezone | |
398 * (as configured using date_default_timezone_set, or the date.timezone ini | |
399 * setting). | |
400 * | |
401 * Alternatively, if $failIfUncertain is set to true, it will throw an | |
402 * exception if we cannot accurately determine the timezone. | |
403 * | |
404 * @param string $tzid | |
405 * @param Sabre\VObject\Component $vcalendar | |
406 * @return DateTimeZone | |
407 */ | |
408 static public function getTimeZone($tzid, Component $vcalendar = null, $failIfUncertain = false) { | |
409 | |
410 // First we will just see if the tzid is a support timezone identifier. | |
411 try { | |
412 return new \DateTimeZone($tzid); | |
413 } catch (\Exception $e) { | |
414 } | |
415 | |
416 // Next, we check if the tzid is somewhere in our tzid map. | |
417 if (isset(self::$map[$tzid])) { | |
418 return new \DateTimeZone(self::$map[$tzid]); | |
419 } | |
420 | |
421 // Maybe the author was hyper-lazy and just included an offset. We | |
422 // support it, but we aren't happy about it. | |
423 if (preg_match('/^GMT(\+|-)([0-9]{4})$/', $tzid, $matches)) { | |
424 return new \DateTimeZone('Etc/GMT' . $matches[1] . ltrim(substr($matches[2],0,2),'0')); | |
425 } | |
426 | |
427 if ($vcalendar) { | |
428 | |
429 // If that didn't work, we will scan VTIMEZONE objects | |
430 foreach($vcalendar->select('VTIMEZONE') as $vtimezone) { | |
431 | |
432 if ((string)$vtimezone->TZID === $tzid) { | |
433 | |
434 // Some clients add 'X-LIC-LOCATION' with the olson name. | |
435 if (isset($vtimezone->{'X-LIC-LOCATION'})) { | |
436 | |
437 $lic = (string)$vtimezone->{'X-LIC-LOCATION'}; | |
438 | |
439 // Libical generators may specify strings like | |
440 // "SystemV/EST5EDT". For those we must remove the | |
441 // SystemV part. | |
442 if (substr($lic,0,8)==='SystemV/') { | |
443 $lic = substr($lic,8); | |
444 } | |
445 | |
446 try { | |
447 return new \DateTimeZone($lic); | |
448 } catch (\Exception $e) { | |
449 } | |
450 | |
451 } | |
452 // Microsoft may add a magic number, which we also have an | |
453 // answer for. | |
454 if (isset($vtimezone->{'X-MICROSOFT-CDO-TZID'})) { | |
455 $cdoId = (int)$vtimezone->{'X-MICROSOFT-CDO-TZID'}->value; | |
456 | |
457 // 2 can mean both Europe/Lisbon and Europe/Sarajevo. | |
458 if ($cdoId===2 && strpos((string)$vtimezone->TZID, 'Sarajevo')!==false) { | |
459 return new \DateTimeZone('Europe/Sarajevo'); | |
460 } | |
461 | |
462 if (isset(self::$microsoftExchangeMap[$cdoId])) { | |
463 return new \DateTimeZone(self::$microsoftExchangeMap[$cdoId]); | |
464 } | |
465 } | |
466 | |
467 } | |
468 | |
469 } | |
470 | |
471 } | |
472 | |
473 if ($failIfUncertain) { | |
474 throw new \InvalidArgumentException('We were unable to determine the correct PHP timezone for tzid: ' . $tzid); | |
475 } | |
476 | |
477 // If we got all the way here, we default to UTC. | |
478 return new \DateTimeZone(date_default_timezone_get()); | |
479 | |
480 } | |
481 | |
482 } |