PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.4
Booking for Appointments and Events Calendar – Amelia v2.4.4
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / vendor / sabre / vobject / lib / TimeZoneUtil.php
ameliabooking / vendor / sabre / vobject / lib Last commit date
Component 6 months ago ITip 6 months ago Parser 6 months ago Property 6 months ago Recur 6 months ago Splitter 6 months ago TimezoneGuesser 6 months ago timezonedata 1 year ago BirthdayCalendarGenerator.php 6 months ago Cli.php 6 months ago Component.php 6 months ago DateTimeParser.php 6 months ago Document.php 6 months ago ElementList.php 6 months ago EofException.php 6 months ago FreeBusyData.php 6 months ago FreeBusyGenerator.php 6 months ago InvalidDataException.php 6 months ago Node.php 6 months ago PHPUnitAssertions.php 6 months ago Parameter.php 6 months ago ParseException.php 6 months ago Property.php 6 months ago Reader.php 6 months ago Settings.php 6 months ago StringUtil.php 6 months ago TimeZoneUtil.php 6 months ago UUIDUtil.php 6 months ago VCardConverter.php 6 months ago Version.php 6 months ago Writer.php 6 months ago
TimeZoneUtil.php
273 lines
1 <?php
2
3 namespace AmeliaVendor\Sabre\VObject;
4
5 use DateTimeZone;
6 use InvalidArgumentException;
7 use AmeliaVendor\Sabre\VObject\TimezoneGuesser\FindFromOffset;
8 use AmeliaVendor\Sabre\VObject\TimezoneGuesser\FindFromTimezoneIdentifier;
9 use AmeliaVendor\Sabre\VObject\TimezoneGuesser\FindFromTimezoneMap;
10 use AmeliaVendor\Sabre\VObject\TimezoneGuesser\GuessFromLicEntry;
11 use AmeliaVendor\Sabre\VObject\TimezoneGuesser\GuessFromMsTzId;
12 use AmeliaVendor\Sabre\VObject\TimezoneGuesser\TimezoneFinder;
13 use AmeliaVendor\Sabre\VObject\TimezoneGuesser\TimezoneGuesser;
14
15 /**
16 * Time zone name translation.
17 *
18 * This file translates well-known time zone names into "Olson database" time zone names.
19 *
20 * @copyright Copyright (C) fruux GmbH (https://fruux.com/)
21 * @author Frank Edelhaeuser (fedel@users.sourceforge.net)
22 * @author Evert Pot (http://evertpot.com/)
23 * @license http://sabre.io/license/ Modified BSD License
24 */
25 class TimeZoneUtil
26 {
27 /** @var self */
28 private static $instance = null;
29
30 /** @var TimezoneGuesser[] */
31 private $timezoneGuessers = [];
32
33 /** @var TimezoneFinder[] */
34 private $timezoneFinders = [];
35
36 private function __construct()
37 {
38 $this->addGuesser('lic', new GuessFromLicEntry());
39 $this->addGuesser('msTzId', new GuessFromMsTzId());
40 $this->addFinder('tzid', new FindFromTimezoneIdentifier());
41 $this->addFinder('tzmap', new FindFromTimezoneMap());
42 $this->addFinder('offset', new FindFromOffset());
43 }
44
45 private static function getInstance(): self
46 {
47 if (null === self::$instance) {
48 self::$instance = new self();
49 }
50
51 return self::$instance;
52 }
53
54 private function addGuesser(string $key, TimezoneGuesser $guesser): void
55 {
56 $this->timezoneGuessers[$key] = $guesser;
57 }
58
59 private function addFinder(string $key, TimezoneFinder $finder): void
60 {
61 $this->timezoneFinders[$key] = $finder;
62 }
63
64 /**
65 * This method will try to find out the correct timezone for an iCalendar
66 * date-time value.
67 *
68 * You must pass the contents of the TZID parameter, as well as the full
69 * calendar.
70 *
71 * If the lookup fails, this method will return the default PHP timezone
72 * (as configured using date_default_timezone_set, or the date.timezone ini
73 * setting).
74 *
75 * Alternatively, if $failIfUncertain is set to true, it will throw an
76 * exception if we cannot accurately determine the timezone.
77 */
78 private function findTimeZone(string $tzid, ?Component $vcalendar = null, bool $failIfUncertain = false): DateTimeZone
79 {
80 foreach ($this->timezoneFinders as $timezoneFinder) {
81 $timezone = $timezoneFinder->find($tzid, $failIfUncertain);
82 if (!$timezone instanceof DateTimeZone) {
83 continue;
84 }
85
86 return $timezone;
87 }
88
89 if ($vcalendar) {
90 // If that didn't work, we will scan VTIMEZONE objects
91 foreach ($vcalendar->select('VTIMEZONE') as $vtimezone) {
92 if ((string) $vtimezone->TZID === $tzid) {
93 foreach ($this->timezoneGuessers as $timezoneGuesser) {
94 $timezone = $timezoneGuesser->guess($vtimezone, $failIfUncertain);
95 if (!$timezone instanceof DateTimeZone) {
96 continue;
97 }
98
99 return $timezone;
100 }
101 }
102 }
103 }
104
105 if ($failIfUncertain) {
106 throw new InvalidArgumentException('We were unable to determine the correct PHP timezone for tzid: '.$tzid);
107 }
108
109 // If we got all the way here, we default to whatever has been set as the PHP default timezone.
110 return new DateTimeZone(date_default_timezone_get());
111 }
112
113 public static function addTimezoneGuesser(string $key, TimezoneGuesser $guesser): void
114 {
115 self::getInstance()->addGuesser($key, $guesser);
116 }
117
118 public static function addTimezoneFinder(string $key, TimezoneFinder $finder): void
119 {
120 self::getInstance()->addFinder($key, $finder);
121 }
122
123 /**
124 * @param string $tzid
125 * @param false $failIfUncertain
126 *
127 * @return DateTimeZone
128 */
129 public static function getTimeZone($tzid, ?Component $vcalendar = null, $failIfUncertain = false)
130 {
131 return self::getInstance()->findTimeZone($tzid, $vcalendar, $failIfUncertain);
132 }
133
134 public static function clean(): void
135 {
136 self::$instance = null;
137 }
138
139 // Keeping things for backwards compatibility
140 /**
141 * @var array|null
142 *
143 * @deprecated
144 */
145 public static $map = null;
146
147 /**
148 * List of microsoft exchange timezone ids.
149 *
150 * Source: http://msdn.microsoft.com/en-us/library/aa563018(loband).aspx
151 *
152 * @deprecated
153 */
154 public static $microsoftExchangeMap = [
155 0 => 'UTC',
156 31 => 'Africa/Casablanca',
157 // Insanely, id #2 is used for both Europe/Lisbon, and Europe/Sarajevo.
158 // I'm not even kidding.. We handle this special case in the
159 // getTimeZone method.
160 2 => 'Europe/Lisbon',
161 1 => 'Europe/London',
162 4 => 'Europe/Berlin',
163 6 => 'Europe/Prague',
164 3 => 'Europe/Paris',
165 69 => 'Africa/Luanda', // This was a best guess
166 7 => 'Europe/Athens',
167 5 => 'Europe/Bucharest',
168 49 => 'Africa/Cairo',
169 50 => 'Africa/Harare',
170 59 => 'Europe/Helsinki',
171 27 => 'Asia/Jerusalem',
172 26 => 'Asia/Baghdad',
173 74 => 'Asia/Kuwait',
174 51 => 'Europe/Moscow',
175 56 => 'Africa/Nairobi',
176 25 => 'Asia/Tehran',
177 24 => 'Asia/Muscat', // Best guess
178 54 => 'Asia/Baku',
179 48 => 'Asia/Kabul',
180 58 => 'Asia/Yekaterinburg',
181 47 => 'Asia/Karachi',
182 23 => 'Asia/Calcutta',
183 62 => 'Asia/Kathmandu',
184 46 => 'Asia/Almaty',
185 71 => 'Asia/Dhaka',
186 66 => 'Asia/Colombo',
187 61 => 'Asia/Rangoon',
188 22 => 'Asia/Bangkok',
189 64 => 'Asia/Krasnoyarsk',
190 45 => 'Asia/Shanghai',
191 63 => 'Asia/Irkutsk',
192 21 => 'Asia/Singapore',
193 73 => 'Australia/Perth',
194 75 => 'Asia/Taipei',
195 20 => 'Asia/Tokyo',
196 72 => 'Asia/Seoul',
197 70 => 'Asia/Yakutsk',
198 19 => 'Australia/Adelaide',
199 44 => 'Australia/Darwin',
200 18 => 'Australia/Brisbane',
201 76 => 'Australia/Sydney',
202 43 => 'Pacific/Guam',
203 42 => 'Australia/Hobart',
204 68 => 'Asia/Vladivostok',
205 41 => 'Asia/Magadan',
206 17 => 'Pacific/Auckland',
207 40 => 'Pacific/Fiji',
208 67 => 'Pacific/Tongatapu',
209 29 => 'Atlantic/Azores',
210 53 => 'Atlantic/Cape_Verde',
211 30 => 'America/Noronha',
212 8 => 'America/Sao_Paulo', // Best guess
213 32 => 'America/Argentina/Buenos_Aires',
214 60 => 'America/Godthab',
215 28 => 'America/St_Johns',
216 9 => 'America/Halifax',
217 33 => 'America/Caracas',
218 65 => 'America/Santiago',
219 35 => 'America/Bogota',
220 10 => 'America/New_York',
221 34 => 'America/Indiana/Indianapolis',
222 55 => 'America/Guatemala',
223 11 => 'America/Chicago',
224 37 => 'America/Mexico_City',
225 36 => 'America/Edmonton',
226 38 => 'America/Phoenix',
227 12 => 'America/Denver', // Best guess
228 13 => 'America/Los_Angeles', // Best guess
229 14 => 'America/Anchorage',
230 15 => 'Pacific/Honolulu',
231 16 => 'Pacific/Midway',
232 39 => 'Pacific/Kwajalein',
233 ];
234
235 /**
236 * This method will load in all the tz mapping information, if it's not yet
237 * done.
238 *
239 * @deprecated
240 */
241 public static function loadTzMaps()
242 {
243 if (!is_null(self::$map)) {
244 return;
245 }
246
247 self::$map = array_merge(
248 include __DIR__.'/timezonedata/windowszones.php',
249 include __DIR__.'/timezonedata/lotuszones.php',
250 include __DIR__.'/timezonedata/exchangezones.php',
251 include __DIR__.'/timezonedata/php-workaround.php'
252 );
253 }
254
255 /**
256 * This method returns an array of timezone identifiers, that are supported
257 * by DateTimeZone(), but not returned by DateTimeZone::listIdentifiers().
258 *
259 * We're not using DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC) because:
260 * - It's not supported by some PHP versions as well as HHVM.
261 * - It also returns identifiers, that are invalid values for new DateTimeZone() on some PHP versions.
262 * (See timezonedata/php-bc.php and timezonedata php-workaround.php)
263 *
264 * @return array
265 *
266 * @deprecated
267 */
268 public static function getIdentifiersBC()
269 {
270 return include __DIR__.'/timezonedata/php-bc.php';
271 }
272 }
273