annotate vendor/sabre/vobject/lib/TimeZoneUtil.php @ 7:430dbd5346f7

vendor sabre as distributed
author Charlie Root
date Sat, 13 Jan 2018 09:06:10 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
1 <?php
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
2
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
4
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
5 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
6 * Time zone name translation
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
7 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
8 * This file translates well-known time zone names into "Olson database" time zone names.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
9 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
10 * @copyright Copyright (C) 2011-2015 fruux GmbH (https://fruux.com/).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
11 * @author Frank Edelhaeuser (fedel@users.sourceforge.net)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
12 * @author Evert Pot (http://evertpot.com/)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
13 * @license http://sabre.io/license/ Modified BSD License
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
14 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
15 class TimeZoneUtil {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
16
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
17 public static $map = null;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
18
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
19 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
20 * List of microsoft exchange timezone ids.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
21 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
22 * Source: http://msdn.microsoft.com/en-us/library/aa563018(loband).aspx
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
23 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
24 public static $microsoftExchangeMap = array(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
25 0 => 'UTC',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
26 31 => 'Africa/Casablanca',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
27
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
28 // Insanely, id #2 is used for both Europe/Lisbon, and Europe/Sarajevo.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
29 // I'm not even kidding.. We handle this special case in the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
30 // getTimeZone method.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
31 2 => 'Europe/Lisbon',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
32 1 => 'Europe/London',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
33 4 => 'Europe/Berlin',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
34 6 => 'Europe/Prague',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
35 3 => 'Europe/Paris',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
36 69 => 'Africa/Luanda', // This was a best guess
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
37 7 => 'Europe/Athens',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
38 5 => 'Europe/Bucharest',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
39 49 => 'Africa/Cairo',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
40 50 => 'Africa/Harare',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
41 59 => 'Europe/Helsinki',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
42 27 => 'Asia/Jerusalem',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
43 26 => 'Asia/Baghdad',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
44 74 => 'Asia/Kuwait',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
45 51 => 'Europe/Moscow',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
46 56 => 'Africa/Nairobi',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
47 25 => 'Asia/Tehran',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
48 24 => 'Asia/Muscat', // Best guess
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
49 54 => 'Asia/Baku',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
50 48 => 'Asia/Kabul',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
51 58 => 'Asia/Yekaterinburg',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
52 47 => 'Asia/Karachi',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
53 23 => 'Asia/Calcutta',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
54 62 => 'Asia/Kathmandu',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
55 46 => 'Asia/Almaty',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
56 71 => 'Asia/Dhaka',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
57 66 => 'Asia/Colombo',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
58 61 => 'Asia/Rangoon',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
59 22 => 'Asia/Bangkok',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
60 64 => 'Asia/Krasnoyarsk',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
61 45 => 'Asia/Shanghai',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
62 63 => 'Asia/Irkutsk',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
63 21 => 'Asia/Singapore',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
64 73 => 'Australia/Perth',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
65 75 => 'Asia/Taipei',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
66 20 => 'Asia/Tokyo',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
67 72 => 'Asia/Seoul',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
68 70 => 'Asia/Yakutsk',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
69 19 => 'Australia/Adelaide',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
70 44 => 'Australia/Darwin',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
71 18 => 'Australia/Brisbane',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
72 76 => 'Australia/Sydney',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
73 43 => 'Pacific/Guam',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
74 42 => 'Australia/Hobart',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
75 68 => 'Asia/Vladivostok',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
76 41 => 'Asia/Magadan',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
77 17 => 'Pacific/Auckland',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
78 40 => 'Pacific/Fiji',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
79 67 => 'Pacific/Tongatapu',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
80 29 => 'Atlantic/Azores',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
81 53 => 'Atlantic/Cape_Verde',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
82 30 => 'America/Noronha',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
83 8 => 'America/Sao_Paulo', // Best guess
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
84 32 => 'America/Argentina/Buenos_Aires',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
85 60 => 'America/Godthab',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
86 28 => 'America/St_Johns',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
87 9 => 'America/Halifax',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
88 33 => 'America/Caracas',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
89 65 => 'America/Santiago',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
90 35 => 'America/Bogota',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
91 10 => 'America/New_York',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
92 34 => 'America/Indiana/Indianapolis',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
93 55 => 'America/Guatemala',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
94 11 => 'America/Chicago',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
95 37 => 'America/Mexico_City',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
96 36 => 'America/Edmonton',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
97 38 => 'America/Phoenix',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
98 12 => 'America/Denver', // Best guess
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
99 13 => 'America/Los_Angeles', // Best guess
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
100 14 => 'America/Anchorage',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
101 15 => 'Pacific/Honolulu',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
102 16 => 'Pacific/Midway',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
103 39 => 'Pacific/Kwajalein',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
104 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
105
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
106 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
107 * This method will try to find out the correct timezone for an iCalendar
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
108 * date-time value.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
109 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
110 * You must pass the contents of the TZID parameter, as well as the full
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
111 * calendar.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
112 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
113 * If the lookup fails, this method will return the default PHP timezone
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
114 * (as configured using date_default_timezone_set, or the date.timezone ini
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
115 * setting).
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
116 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
117 * Alternatively, if $failIfUncertain is set to true, it will throw an
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
118 * exception if we cannot accurately determine the timezone.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
119 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
120 * @param string $tzid
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
121 * @param Sabre\VObject\Component $vcalendar
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
122 * @return DateTimeZone
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
123 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
124 static public function getTimeZone($tzid, Component $vcalendar = null, $failIfUncertain = false) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
125
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
126 // First we will just see if the tzid is a support timezone identifier.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
127 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
128 // The only exception is if the timezone starts with (. This is to
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
129 // handle cases where certain microsoft products generate timezone
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
130 // identifiers that for instance look like:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
131 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
132 // (GMT+01.00) Sarajevo/Warsaw/Zagreb
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
133 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
134 // Since PHP 5.5.10, the first bit will be used as the timezone and
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
135 // this method will return just GMT+01:00. This is wrong, because it
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
136 // doesn't take DST into account.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
137 if ($tzid[0]!=='(') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
138
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
139 // PHP has a bug that logs PHP warnings even it shouldn't:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
140 // https://bugs.php.net/bug.php?id=67881
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
141 //
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
142 // That's why we're checking if we'll be able to successfull instantiate
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
143 // \DateTimeZone() before doing so. Otherwise we could simply instantiate
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
144 // and catch the exception.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
145 $tzIdentifiers = \DateTimeZone::listIdentifiers();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
146
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
147 try {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
148 if (
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
149 (in_array($tzid, $tzIdentifiers)) ||
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
150 (preg_match('/^GMT(\+|-)([0-9]{4})$/', $tzid, $matches)) ||
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
151 (in_array($tzid, self::getIdentifiersBC()))
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
152 ) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
153 return new \DateTimeZone($tzid);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
154 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
155 } catch(\Exception $e) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
156 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
157
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
158 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
159
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
160 self::loadTzMaps();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
161
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
162 // Next, we check if the tzid is somewhere in our tzid map.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
163 if (isset(self::$map[$tzid])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
164 return new \DateTimeZone(self::$map[$tzid]);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
165 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
166
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
167 // Maybe the author was hyper-lazy and just included an offset. We
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
168 // support it, but we aren't happy about it.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
169 if (preg_match('/^GMT(\+|-)([0-9]{4})$/', $tzid, $matches)) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
170
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
171 // Note that the path in the source will never be taken from PHP 5.5.10
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
172 // onwards. PHP 5.5.10 supports the "GMT+0100" style of format, so it
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
173 // already gets returned early in this function. Once we drop support
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
174 // for versions under PHP 5.5.10, this bit can be taken out of the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
175 // source.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
176 // @codeCoverageIgnoreStart
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
177 return new \DateTimeZone('Etc/GMT' . $matches[1] . ltrim(substr($matches[2],0,2),'0'));
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
178 // @codeCoverageIgnoreEnd
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
179 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
180
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
181 if ($vcalendar) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
182
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
183 // If that didn't work, we will scan VTIMEZONE objects
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
184 foreach($vcalendar->select('VTIMEZONE') as $vtimezone) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
185
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
186 if ((string)$vtimezone->TZID === $tzid) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
187
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
188 // Some clients add 'X-LIC-LOCATION' with the olson name.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
189 if (isset($vtimezone->{'X-LIC-LOCATION'})) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
190
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
191 $lic = (string)$vtimezone->{'X-LIC-LOCATION'};
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
192
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
193 // Libical generators may specify strings like
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
194 // "SystemV/EST5EDT". For those we must remove the
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
195 // SystemV part.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
196 if (substr($lic,0,8)==='SystemV/') {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
197 $lic = substr($lic,8);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
198 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
199
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
200 return self::getTimeZone($lic, null, $failIfUncertain);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
201
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
202 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
203 // Microsoft may add a magic number, which we also have an
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
204 // answer for.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
205 if (isset($vtimezone->{'X-MICROSOFT-CDO-TZID'})) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
206 $cdoId = (int)$vtimezone->{'X-MICROSOFT-CDO-TZID'}->getValue();
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
207
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
208 // 2 can mean both Europe/Lisbon and Europe/Sarajevo.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
209 if ($cdoId===2 && strpos((string)$vtimezone->TZID, 'Sarajevo')!==false) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
210 return new \DateTimeZone('Europe/Sarajevo');
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
211 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
212
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
213 if (isset(self::$microsoftExchangeMap[$cdoId])) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
214 return new \DateTimeZone(self::$microsoftExchangeMap[$cdoId]);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
215 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
216 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
217
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
218 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
219
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
220 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
221
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
222 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
223
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
224 if ($failIfUncertain) {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
225 throw new \InvalidArgumentException('We were unable to determine the correct PHP timezone for tzid: ' . $tzid);
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
226 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
227
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
228 // If we got all the way here, we default to UTC.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
229 return new \DateTimeZone(date_default_timezone_get());
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
230
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
231 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
232
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
233 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
234 * This method will load in all the tz mapping information, if it's not yet
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
235 * done.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
236 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
237 static public function loadTzMaps() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
238
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
239 if (!is_null(self::$map)) return;
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
240
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
241 self::$map = array_merge(
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
242 include __DIR__ . '/timezonedata/windowszones.php',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
243 include __DIR__ . '/timezonedata/lotuszones.php',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
244 include __DIR__ . '/timezonedata/exchangezones.php',
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
245 include __DIR__ . '/timezonedata/php-workaround.php'
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
246 );
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
247
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
248 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
249
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
250 /**
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
251 * This method returns an array of timezone identifiers, that are supported
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
252 * by DateTimeZone(), but not returned by DateTimeZone::listIdentifiers()
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
253 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
254 * We're not using DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC) because:
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
255 * - It's not supported by some PHP versions as well as HHVM.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
256 * - It also returns identifiers, that are invalid values for new DateTimeZone() on some PHP versions.
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
257 * (See timezonedata/php-bc.php and timezonedata php-workaround.php)
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
258 *
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
259 * @return array
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
260 */
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
261 static public function getIdentifiersBC() {
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
262 return include __DIR__ . '/timezonedata/php-bc.php';
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
263 }
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
264
430dbd5346f7 vendor sabre as distributed
Charlie Root
parents:
diff changeset
265 }