@@ -24,249 +24,249 @@ |
||
| 24 | 24 | */ |
| 25 | 25 | class TimeZoneUtil |
| 26 | 26 | { |
| 27 | - /** @var self */ |
|
| 28 | - private static $instance = null; |
|
| 27 | + /** @var self */ |
|
| 28 | + private static $instance = null; |
|
| 29 | 29 | |
| 30 | - /** @var TimezoneGuesser[] */ |
|
| 31 | - private $timezoneGuessers = []; |
|
| 30 | + /** @var TimezoneGuesser[] */ |
|
| 31 | + private $timezoneGuessers = []; |
|
| 32 | 32 | |
| 33 | - /** @var TimezoneFinder[] */ |
|
| 34 | - private $timezoneFinders = []; |
|
| 33 | + /** @var TimezoneFinder[] */ |
|
| 34 | + private $timezoneFinders = []; |
|
| 35 | 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 | - } |
|
| 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 | 44 | |
| 45 | - private static function getInstance(): self |
|
| 46 | - { |
|
| 47 | - if (null === self::$instance) { |
|
| 48 | - self::$instance = new self(); |
|
| 49 | - } |
|
| 45 | + private static function getInstance(): self |
|
| 46 | + { |
|
| 47 | + if (null === self::$instance) { |
|
| 48 | + self::$instance = new self(); |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - return self::$instance; |
|
| 52 | - } |
|
| 51 | + return self::$instance; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - private function addGuesser(string $key, TimezoneGuesser $guesser): void |
|
| 55 | - { |
|
| 56 | - $this->timezoneGuessers[$key] = $guesser; |
|
| 57 | - } |
|
| 54 | + private function addGuesser(string $key, TimezoneGuesser $guesser): void |
|
| 55 | + { |
|
| 56 | + $this->timezoneGuessers[$key] = $guesser; |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - private function addFinder(string $key, TimezoneFinder $finder): void |
|
| 60 | - { |
|
| 61 | - $this->timezoneFinders[$key] = $finder; |
|
| 62 | - } |
|
| 59 | + private function addFinder(string $key, TimezoneFinder $finder): void |
|
| 60 | + { |
|
| 61 | + $this->timezoneFinders[$key] = $finder; |
|
| 62 | + } |
|
| 63 | 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 | - } |
|
| 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 | 85 | |
| 86 | - return $timezone; |
|
| 87 | - } |
|
| 86 | + return $timezone; |
|
| 87 | + } |
|
| 88 | 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 | - } |
|
| 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 | 98 | |
| 99 | - return $timezone; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - } |
|
| 99 | + return $timezone; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | 104 | |
| 105 | - if ($failIfUncertain) { |
|
| 106 | - throw new InvalidArgumentException('We were unable to determine the correct PHP timezone for tzid: '.$tzid); |
|
| 107 | - } |
|
| 105 | + if ($failIfUncertain) { |
|
| 106 | + throw new InvalidArgumentException('We were unable to determine the correct PHP timezone for tzid: '.$tzid); |
|
| 107 | + } |
|
| 108 | 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 | - } |
|
| 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 | 112 | |
| 113 | - public static function addTimezoneGuesser(string $key, TimezoneGuesser $guesser): void |
|
| 114 | - { |
|
| 115 | - self::getInstance()->addGuesser($key, $guesser); |
|
| 116 | - } |
|
| 113 | + public static function addTimezoneGuesser(string $key, TimezoneGuesser $guesser): void |
|
| 114 | + { |
|
| 115 | + self::getInstance()->addGuesser($key, $guesser); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - public static function addTimezoneFinder(string $key, TimezoneFinder $finder): void |
|
| 119 | - { |
|
| 120 | - self::getInstance()->addFinder($key, $finder); |
|
| 121 | - } |
|
| 118 | + public static function addTimezoneFinder(string $key, TimezoneFinder $finder): void |
|
| 119 | + { |
|
| 120 | + self::getInstance()->addFinder($key, $finder); |
|
| 121 | + } |
|
| 122 | 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 | - } |
|
| 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 | 133 | |
| 134 | - public static function clean(): void |
|
| 135 | - { |
|
| 136 | - self::$instance = null; |
|
| 137 | - } |
|
| 134 | + public static function clean(): void |
|
| 135 | + { |
|
| 136 | + self::$instance = null; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - // Keeping things for backwards compatibility |
|
| 140 | - /** |
|
| 141 | - * @var array|null |
|
| 142 | - * |
|
| 143 | - * @deprecated |
|
| 144 | - */ |
|
| 145 | - public static $map = null; |
|
| 139 | + // Keeping things for backwards compatibility |
|
| 140 | + /** |
|
| 141 | + * @var array|null |
|
| 142 | + * |
|
| 143 | + * @deprecated |
|
| 144 | + */ |
|
| 145 | + public static $map = null; |
|
| 146 | 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 | - ]; |
|
| 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 | 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 | - } |
|
| 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 | 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 | - } |
|
| 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 | 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 | - } |
|
| 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 | 272 | } |
@@ -18,247 +18,247 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | abstract class Document extends Component |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Unknown document type. |
|
| 23 | - */ |
|
| 24 | - const UNKNOWN = 1; |
|
| 21 | + /** |
|
| 22 | + * Unknown document type. |
|
| 23 | + */ |
|
| 24 | + const UNKNOWN = 1; |
|
| 25 | 25 | |
| 26 | - /** |
|
| 27 | - * vCalendar 1.0. |
|
| 28 | - */ |
|
| 29 | - const VCALENDAR10 = 2; |
|
| 26 | + /** |
|
| 27 | + * vCalendar 1.0. |
|
| 28 | + */ |
|
| 29 | + const VCALENDAR10 = 2; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * iCalendar 2.0. |
|
| 33 | - */ |
|
| 34 | - const ICALENDAR20 = 3; |
|
| 31 | + /** |
|
| 32 | + * iCalendar 2.0. |
|
| 33 | + */ |
|
| 34 | + const ICALENDAR20 = 3; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * vCard 2.1. |
|
| 38 | - */ |
|
| 39 | - const VCARD21 = 4; |
|
| 36 | + /** |
|
| 37 | + * vCard 2.1. |
|
| 38 | + */ |
|
| 39 | + const VCARD21 = 4; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * vCard 3.0. |
|
| 43 | - */ |
|
| 44 | - const VCARD30 = 5; |
|
| 41 | + /** |
|
| 42 | + * vCard 3.0. |
|
| 43 | + */ |
|
| 44 | + const VCARD30 = 5; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * vCard 4.0. |
|
| 48 | - */ |
|
| 49 | - const VCARD40 = 6; |
|
| 46 | + /** |
|
| 47 | + * vCard 4.0. |
|
| 48 | + */ |
|
| 49 | + const VCARD40 = 6; |
|
| 50 | 50 | |
| 51 | - /** |
|
| 52 | - * The default name for this component. |
|
| 53 | - * |
|
| 54 | - * This should be 'VCALENDAR' or 'VCARD'. |
|
| 55 | - * |
|
| 56 | - * @var string |
|
| 57 | - */ |
|
| 58 | - public static $defaultName; |
|
| 51 | + /** |
|
| 52 | + * The default name for this component. |
|
| 53 | + * |
|
| 54 | + * This should be 'VCALENDAR' or 'VCARD'. |
|
| 55 | + * |
|
| 56 | + * @var string |
|
| 57 | + */ |
|
| 58 | + public static $defaultName; |
|
| 59 | 59 | |
| 60 | - /** |
|
| 61 | - * List of properties, and which classes they map to. |
|
| 62 | - * |
|
| 63 | - * @var array |
|
| 64 | - */ |
|
| 65 | - public static $propertyMap = []; |
|
| 60 | + /** |
|
| 61 | + * List of properties, and which classes they map to. |
|
| 62 | + * |
|
| 63 | + * @var array |
|
| 64 | + */ |
|
| 65 | + public static $propertyMap = []; |
|
| 66 | 66 | |
| 67 | - /** |
|
| 68 | - * List of components, along with which classes they map to. |
|
| 69 | - * |
|
| 70 | - * @var array |
|
| 71 | - */ |
|
| 72 | - public static $componentMap = []; |
|
| 67 | + /** |
|
| 68 | + * List of components, along with which classes they map to. |
|
| 69 | + * |
|
| 70 | + * @var array |
|
| 71 | + */ |
|
| 72 | + public static $componentMap = []; |
|
| 73 | 73 | |
| 74 | - /** |
|
| 75 | - * List of value-types, and which classes they map to. |
|
| 76 | - * |
|
| 77 | - * @var array |
|
| 78 | - */ |
|
| 79 | - public static $valueMap = []; |
|
| 74 | + /** |
|
| 75 | + * List of value-types, and which classes they map to. |
|
| 76 | + * |
|
| 77 | + * @var array |
|
| 78 | + */ |
|
| 79 | + public static $valueMap = []; |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Creates a new document. |
|
| 83 | - * |
|
| 84 | - * We're changing the default behavior slightly here. First, we don't want |
|
| 85 | - * to have to specify a name (we already know it), and we want to allow |
|
| 86 | - * children to be specified in the first argument. |
|
| 87 | - * |
|
| 88 | - * But, the default behavior also works. |
|
| 89 | - * |
|
| 90 | - * So the two sigs: |
|
| 91 | - * |
|
| 92 | - * new Document(array $children = [], $defaults = true); |
|
| 93 | - * new Document(string $name, array $children = [], $defaults = true) |
|
| 94 | - */ |
|
| 95 | - public function __construct() |
|
| 96 | - { |
|
| 97 | - $args = func_get_args(); |
|
| 98 | - $name = static::$defaultName; |
|
| 99 | - if (0 === count($args) || is_array($args[0])) { |
|
| 100 | - $children = isset($args[0]) ? $args[0] : []; |
|
| 101 | - $defaults = isset($args[1]) ? $args[1] : true; |
|
| 102 | - } else { |
|
| 103 | - $name = $args[0]; |
|
| 104 | - $children = isset($args[1]) ? $args[1] : []; |
|
| 105 | - $defaults = isset($args[2]) ? $args[2] : true; |
|
| 106 | - } |
|
| 107 | - parent::__construct($this, $name, $children, $defaults); |
|
| 108 | - } |
|
| 81 | + /** |
|
| 82 | + * Creates a new document. |
|
| 83 | + * |
|
| 84 | + * We're changing the default behavior slightly here. First, we don't want |
|
| 85 | + * to have to specify a name (we already know it), and we want to allow |
|
| 86 | + * children to be specified in the first argument. |
|
| 87 | + * |
|
| 88 | + * But, the default behavior also works. |
|
| 89 | + * |
|
| 90 | + * So the two sigs: |
|
| 91 | + * |
|
| 92 | + * new Document(array $children = [], $defaults = true); |
|
| 93 | + * new Document(string $name, array $children = [], $defaults = true) |
|
| 94 | + */ |
|
| 95 | + public function __construct() |
|
| 96 | + { |
|
| 97 | + $args = func_get_args(); |
|
| 98 | + $name = static::$defaultName; |
|
| 99 | + if (0 === count($args) || is_array($args[0])) { |
|
| 100 | + $children = isset($args[0]) ? $args[0] : []; |
|
| 101 | + $defaults = isset($args[1]) ? $args[1] : true; |
|
| 102 | + } else { |
|
| 103 | + $name = $args[0]; |
|
| 104 | + $children = isset($args[1]) ? $args[1] : []; |
|
| 105 | + $defaults = isset($args[2]) ? $args[2] : true; |
|
| 106 | + } |
|
| 107 | + parent::__construct($this, $name, $children, $defaults); |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Returns the current document type. |
|
| 112 | - * |
|
| 113 | - * @return int |
|
| 114 | - */ |
|
| 115 | - public function getDocumentType() |
|
| 116 | - { |
|
| 117 | - return self::UNKNOWN; |
|
| 118 | - } |
|
| 110 | + /** |
|
| 111 | + * Returns the current document type. |
|
| 112 | + * |
|
| 113 | + * @return int |
|
| 114 | + */ |
|
| 115 | + public function getDocumentType() |
|
| 116 | + { |
|
| 117 | + return self::UNKNOWN; |
|
| 118 | + } |
|
| 119 | 119 | |
| 120 | - /** |
|
| 121 | - * Creates a new component or property. |
|
| 122 | - * |
|
| 123 | - * If it's a known component, we will automatically call createComponent. |
|
| 124 | - * otherwise, we'll assume it's a property and call createProperty instead. |
|
| 125 | - * |
|
| 126 | - * @param string $name |
|
| 127 | - * @param string $arg1,... Unlimited number of args |
|
| 128 | - * |
|
| 129 | - * @return mixed |
|
| 130 | - */ |
|
| 131 | - public function create($name) |
|
| 132 | - { |
|
| 133 | - if (isset(static::$componentMap[strtoupper($name)])) { |
|
| 134 | - return call_user_func_array([$this, 'createComponent'], func_get_args()); |
|
| 135 | - } else { |
|
| 136 | - return call_user_func_array([$this, 'createProperty'], func_get_args()); |
|
| 137 | - } |
|
| 138 | - } |
|
| 120 | + /** |
|
| 121 | + * Creates a new component or property. |
|
| 122 | + * |
|
| 123 | + * If it's a known component, we will automatically call createComponent. |
|
| 124 | + * otherwise, we'll assume it's a property and call createProperty instead. |
|
| 125 | + * |
|
| 126 | + * @param string $name |
|
| 127 | + * @param string $arg1,... Unlimited number of args |
|
| 128 | + * |
|
| 129 | + * @return mixed |
|
| 130 | + */ |
|
| 131 | + public function create($name) |
|
| 132 | + { |
|
| 133 | + if (isset(static::$componentMap[strtoupper($name)])) { |
|
| 134 | + return call_user_func_array([$this, 'createComponent'], func_get_args()); |
|
| 135 | + } else { |
|
| 136 | + return call_user_func_array([$this, 'createProperty'], func_get_args()); |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - /** |
|
| 141 | - * Creates a new component. |
|
| 142 | - * |
|
| 143 | - * This method automatically searches for the correct component class, based |
|
| 144 | - * on its name. |
|
| 145 | - * |
|
| 146 | - * You can specify the children either in key=>value syntax, in which case |
|
| 147 | - * properties will automatically be created, or you can just pass a list of |
|
| 148 | - * Component and Property object. |
|
| 149 | - * |
|
| 150 | - * By default, a set of sensible values will be added to the component. For |
|
| 151 | - * an iCalendar object, this may be something like CALSCALE:GREGORIAN. To |
|
| 152 | - * ensure that this does not happen, set $defaults to false. |
|
| 153 | - * |
|
| 154 | - * @param string $name |
|
| 155 | - * @param array $children |
|
| 156 | - * @param bool $defaults |
|
| 157 | - * |
|
| 158 | - * @return Component |
|
| 159 | - */ |
|
| 160 | - public function createComponent($name, array $children = null, $defaults = true) |
|
| 161 | - { |
|
| 162 | - $name = strtoupper($name); |
|
| 163 | - $class = Component::class; |
|
| 140 | + /** |
|
| 141 | + * Creates a new component. |
|
| 142 | + * |
|
| 143 | + * This method automatically searches for the correct component class, based |
|
| 144 | + * on its name. |
|
| 145 | + * |
|
| 146 | + * You can specify the children either in key=>value syntax, in which case |
|
| 147 | + * properties will automatically be created, or you can just pass a list of |
|
| 148 | + * Component and Property object. |
|
| 149 | + * |
|
| 150 | + * By default, a set of sensible values will be added to the component. For |
|
| 151 | + * an iCalendar object, this may be something like CALSCALE:GREGORIAN. To |
|
| 152 | + * ensure that this does not happen, set $defaults to false. |
|
| 153 | + * |
|
| 154 | + * @param string $name |
|
| 155 | + * @param array $children |
|
| 156 | + * @param bool $defaults |
|
| 157 | + * |
|
| 158 | + * @return Component |
|
| 159 | + */ |
|
| 160 | + public function createComponent($name, array $children = null, $defaults = true) |
|
| 161 | + { |
|
| 162 | + $name = strtoupper($name); |
|
| 163 | + $class = Component::class; |
|
| 164 | 164 | |
| 165 | - if (isset(static::$componentMap[$name])) { |
|
| 166 | - $class = static::$componentMap[$name]; |
|
| 167 | - } |
|
| 168 | - if (is_null($children)) { |
|
| 169 | - $children = []; |
|
| 170 | - } |
|
| 165 | + if (isset(static::$componentMap[$name])) { |
|
| 166 | + $class = static::$componentMap[$name]; |
|
| 167 | + } |
|
| 168 | + if (is_null($children)) { |
|
| 169 | + $children = []; |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | - return new $class($this, $name, $children, $defaults); |
|
| 173 | - } |
|
| 172 | + return new $class($this, $name, $children, $defaults); |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /** |
|
| 176 | - * Factory method for creating new properties. |
|
| 177 | - * |
|
| 178 | - * This method automatically searches for the correct property class, based |
|
| 179 | - * on its name. |
|
| 180 | - * |
|
| 181 | - * You can specify the parameters either in key=>value syntax, in which case |
|
| 182 | - * parameters will automatically be created, or you can just pass a list of |
|
| 183 | - * Parameter objects. |
|
| 184 | - * |
|
| 185 | - * @param string $name |
|
| 186 | - * @param mixed $value |
|
| 187 | - * @param array $parameters |
|
| 188 | - * @param string $valueType Force a specific valuetype, such as URI or TEXT |
|
| 189 | - * |
|
| 190 | - * @return Property |
|
| 191 | - */ |
|
| 192 | - public function createProperty($name, $value = null, array $parameters = null, $valueType = null) |
|
| 193 | - { |
|
| 194 | - // If there's a . in the name, it means it's prefixed by a groupname. |
|
| 195 | - if (false !== ($i = strpos($name, '.'))) { |
|
| 196 | - $group = substr($name, 0, $i); |
|
| 197 | - $name = strtoupper(substr($name, $i + 1)); |
|
| 198 | - } else { |
|
| 199 | - $name = strtoupper($name); |
|
| 200 | - $group = null; |
|
| 201 | - } |
|
| 175 | + /** |
|
| 176 | + * Factory method for creating new properties. |
|
| 177 | + * |
|
| 178 | + * This method automatically searches for the correct property class, based |
|
| 179 | + * on its name. |
|
| 180 | + * |
|
| 181 | + * You can specify the parameters either in key=>value syntax, in which case |
|
| 182 | + * parameters will automatically be created, or you can just pass a list of |
|
| 183 | + * Parameter objects. |
|
| 184 | + * |
|
| 185 | + * @param string $name |
|
| 186 | + * @param mixed $value |
|
| 187 | + * @param array $parameters |
|
| 188 | + * @param string $valueType Force a specific valuetype, such as URI or TEXT |
|
| 189 | + * |
|
| 190 | + * @return Property |
|
| 191 | + */ |
|
| 192 | + public function createProperty($name, $value = null, array $parameters = null, $valueType = null) |
|
| 193 | + { |
|
| 194 | + // If there's a . in the name, it means it's prefixed by a groupname. |
|
| 195 | + if (false !== ($i = strpos($name, '.'))) { |
|
| 196 | + $group = substr($name, 0, $i); |
|
| 197 | + $name = strtoupper(substr($name, $i + 1)); |
|
| 198 | + } else { |
|
| 199 | + $name = strtoupper($name); |
|
| 200 | + $group = null; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - $class = null; |
|
| 203 | + $class = null; |
|
| 204 | 204 | |
| 205 | - if ($valueType) { |
|
| 206 | - // The valueType argument comes first to figure out the correct |
|
| 207 | - // class. |
|
| 208 | - $class = $this->getClassNameForPropertyValue($valueType); |
|
| 209 | - } |
|
| 205 | + if ($valueType) { |
|
| 206 | + // The valueType argument comes first to figure out the correct |
|
| 207 | + // class. |
|
| 208 | + $class = $this->getClassNameForPropertyValue($valueType); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - if (is_null($class)) { |
|
| 212 | - // If a VALUE parameter is supplied, we should use that. |
|
| 213 | - if (isset($parameters['VALUE'])) { |
|
| 214 | - $class = $this->getClassNameForPropertyValue($parameters['VALUE']); |
|
| 215 | - if (is_null($class)) { |
|
| 216 | - throw new InvalidDataException('Unsupported VALUE parameter for '.$name.' property. You supplied "'.$parameters['VALUE'].'"'); |
|
| 217 | - } |
|
| 218 | - } else { |
|
| 219 | - $class = $this->getClassNameForPropertyName($name); |
|
| 220 | - } |
|
| 221 | - } |
|
| 222 | - if (is_null($parameters)) { |
|
| 223 | - $parameters = []; |
|
| 224 | - } |
|
| 211 | + if (is_null($class)) { |
|
| 212 | + // If a VALUE parameter is supplied, we should use that. |
|
| 213 | + if (isset($parameters['VALUE'])) { |
|
| 214 | + $class = $this->getClassNameForPropertyValue($parameters['VALUE']); |
|
| 215 | + if (is_null($class)) { |
|
| 216 | + throw new InvalidDataException('Unsupported VALUE parameter for '.$name.' property. You supplied "'.$parameters['VALUE'].'"'); |
|
| 217 | + } |
|
| 218 | + } else { |
|
| 219 | + $class = $this->getClassNameForPropertyName($name); |
|
| 220 | + } |
|
| 221 | + } |
|
| 222 | + if (is_null($parameters)) { |
|
| 223 | + $parameters = []; |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - return new $class($this, $name, $value, $parameters, $group); |
|
| 227 | - } |
|
| 226 | + return new $class($this, $name, $value, $parameters, $group); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - /** |
|
| 230 | - * This method returns a full class-name for a value parameter. |
|
| 231 | - * |
|
| 232 | - * For instance, DTSTART may have VALUE=DATE. In that case we will look in |
|
| 233 | - * our valueMap table and return the appropriate class name. |
|
| 234 | - * |
|
| 235 | - * This method returns null if we don't have a specialized class. |
|
| 236 | - * |
|
| 237 | - * @param string $valueParam |
|
| 238 | - * |
|
| 239 | - * @return string|null |
|
| 240 | - */ |
|
| 241 | - public function getClassNameForPropertyValue($valueParam) |
|
| 242 | - { |
|
| 243 | - $valueParam = strtoupper($valueParam); |
|
| 244 | - if (isset(static::$valueMap[$valueParam])) { |
|
| 245 | - return static::$valueMap[$valueParam]; |
|
| 246 | - } |
|
| 247 | - } |
|
| 229 | + /** |
|
| 230 | + * This method returns a full class-name for a value parameter. |
|
| 231 | + * |
|
| 232 | + * For instance, DTSTART may have VALUE=DATE. In that case we will look in |
|
| 233 | + * our valueMap table and return the appropriate class name. |
|
| 234 | + * |
|
| 235 | + * This method returns null if we don't have a specialized class. |
|
| 236 | + * |
|
| 237 | + * @param string $valueParam |
|
| 238 | + * |
|
| 239 | + * @return string|null |
|
| 240 | + */ |
|
| 241 | + public function getClassNameForPropertyValue($valueParam) |
|
| 242 | + { |
|
| 243 | + $valueParam = strtoupper($valueParam); |
|
| 244 | + if (isset(static::$valueMap[$valueParam])) { |
|
| 245 | + return static::$valueMap[$valueParam]; |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - /** |
|
| 250 | - * Returns the default class for a property name. |
|
| 251 | - * |
|
| 252 | - * @param string $propertyName |
|
| 253 | - * |
|
| 254 | - * @return string |
|
| 255 | - */ |
|
| 256 | - public function getClassNameForPropertyName($propertyName) |
|
| 257 | - { |
|
| 258 | - if (isset(static::$propertyMap[$propertyName])) { |
|
| 259 | - return static::$propertyMap[$propertyName]; |
|
| 260 | - } else { |
|
| 261 | - return Property\Unknown::class; |
|
| 262 | - } |
|
| 263 | - } |
|
| 249 | + /** |
|
| 250 | + * Returns the default class for a property name. |
|
| 251 | + * |
|
| 252 | + * @param string $propertyName |
|
| 253 | + * |
|
| 254 | + * @return string |
|
| 255 | + */ |
|
| 256 | + public function getClassNameForPropertyName($propertyName) |
|
| 257 | + { |
|
| 258 | + if (isset(static::$propertyMap[$propertyName])) { |
|
| 259 | + return static::$propertyMap[$propertyName]; |
|
| 260 | + } else { |
|
| 261 | + return Property\Unknown::class; |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | 264 | } |
@@ -25,525 +25,525 @@ |
||
| 25 | 25 | */ |
| 26 | 26 | class FreeBusyGenerator |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * Input objects. |
|
| 30 | - * |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - protected $objects = []; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Start of range. |
|
| 37 | - * |
|
| 38 | - * @var DateTimeInterface|null |
|
| 39 | - */ |
|
| 40 | - protected $start; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * End of range. |
|
| 44 | - * |
|
| 45 | - * @var DateTimeInterface|null |
|
| 46 | - */ |
|
| 47 | - protected $end; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * VCALENDAR object. |
|
| 51 | - * |
|
| 52 | - * @var Document |
|
| 53 | - */ |
|
| 54 | - protected $baseObject; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Reference timezone. |
|
| 58 | - * |
|
| 59 | - * When we are calculating busy times, and we come across so-called |
|
| 60 | - * floating times (times without a timezone), we use the reference timezone |
|
| 61 | - * instead. |
|
| 62 | - * |
|
| 63 | - * This is also used for all-day events. |
|
| 64 | - * |
|
| 65 | - * This defaults to UTC. |
|
| 66 | - * |
|
| 67 | - * @var DateTimeZone |
|
| 68 | - */ |
|
| 69 | - protected $timeZone; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * A VAVAILABILITY document. |
|
| 73 | - * |
|
| 74 | - * If this is set, its information will be included when calculating |
|
| 75 | - * freebusy time. |
|
| 76 | - * |
|
| 77 | - * @var Document |
|
| 78 | - */ |
|
| 79 | - protected $vavailability; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Creates the generator. |
|
| 83 | - * |
|
| 84 | - * Check the setTimeRange and setObjects methods for details about the |
|
| 85 | - * arguments. |
|
| 86 | - * |
|
| 87 | - * @param DateTimeInterface $start |
|
| 88 | - * @param DateTimeInterface $end |
|
| 89 | - * @param mixed $objects |
|
| 90 | - * @param DateTimeZone $timeZone |
|
| 91 | - */ |
|
| 92 | - public function __construct(DateTimeInterface $start = null, DateTimeInterface $end = null, $objects = null, DateTimeZone $timeZone = null) |
|
| 93 | - { |
|
| 94 | - $this->setTimeRange($start, $end); |
|
| 95 | - |
|
| 96 | - if ($objects) { |
|
| 97 | - $this->setObjects($objects); |
|
| 98 | - } |
|
| 99 | - if (is_null($timeZone)) { |
|
| 100 | - $timeZone = new DateTimeZone('UTC'); |
|
| 101 | - } |
|
| 102 | - $this->setTimeZone($timeZone); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Sets the VCALENDAR object. |
|
| 107 | - * |
|
| 108 | - * If this is set, it will not be generated for you. You are responsible |
|
| 109 | - * for setting things like the METHOD, CALSCALE, VERSION, etc.. |
|
| 110 | - * |
|
| 111 | - * The VFREEBUSY object will be automatically added though. |
|
| 112 | - */ |
|
| 113 | - public function setBaseObject(Document $vcalendar) |
|
| 114 | - { |
|
| 115 | - $this->baseObject = $vcalendar; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Sets a VAVAILABILITY document. |
|
| 120 | - */ |
|
| 121 | - public function setVAvailability(Document $vcalendar) |
|
| 122 | - { |
|
| 123 | - $this->vavailability = $vcalendar; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * Sets the input objects. |
|
| 128 | - * |
|
| 129 | - * You must either specify a vcalendar object as a string, or as the parse |
|
| 130 | - * Component. |
|
| 131 | - * It's also possible to specify multiple objects as an array. |
|
| 132 | - * |
|
| 133 | - * @param mixed $objects |
|
| 134 | - */ |
|
| 135 | - public function setObjects($objects) |
|
| 136 | - { |
|
| 137 | - if (!is_array($objects)) { |
|
| 138 | - $objects = [$objects]; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - $this->objects = []; |
|
| 142 | - foreach ($objects as $object) { |
|
| 143 | - if (is_string($object) || is_resource($object)) { |
|
| 144 | - $this->objects[] = Reader::read($object); |
|
| 145 | - } elseif ($object instanceof Component) { |
|
| 146 | - $this->objects[] = $object; |
|
| 147 | - } else { |
|
| 148 | - throw new \InvalidArgumentException('You can only pass strings or \\Sabre\\VObject\\Component arguments to setObjects'); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Sets the time range. |
|
| 155 | - * |
|
| 156 | - * Any freebusy object falling outside of this time range will be ignored. |
|
| 157 | - * |
|
| 158 | - * @param DateTimeInterface $start |
|
| 159 | - * @param DateTimeInterface $end |
|
| 160 | - */ |
|
| 161 | - public function setTimeRange(DateTimeInterface $start = null, DateTimeInterface $end = null) |
|
| 162 | - { |
|
| 163 | - if (!$start) { |
|
| 164 | - $start = new DateTimeImmutable(Settings::$minDate); |
|
| 165 | - } |
|
| 166 | - if (!$end) { |
|
| 167 | - $end = new DateTimeImmutable(Settings::$maxDate); |
|
| 168 | - } |
|
| 169 | - $this->start = $start; |
|
| 170 | - $this->end = $end; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Sets the reference timezone for floating times. |
|
| 175 | - */ |
|
| 176 | - public function setTimeZone(DateTimeZone $timeZone) |
|
| 177 | - { |
|
| 178 | - $this->timeZone = $timeZone; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * Parses the input data and returns a correct VFREEBUSY object, wrapped in |
|
| 183 | - * a VCALENDAR. |
|
| 184 | - * |
|
| 185 | - * @return Component |
|
| 186 | - */ |
|
| 187 | - public function getResult() |
|
| 188 | - { |
|
| 189 | - $fbData = new FreeBusyData( |
|
| 190 | - $this->start->getTimeStamp(), |
|
| 191 | - $this->end->getTimeStamp() |
|
| 192 | - ); |
|
| 193 | - if ($this->vavailability) { |
|
| 194 | - $this->calculateAvailability($fbData, $this->vavailability); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $this->calculateBusy($fbData, $this->objects); |
|
| 198 | - |
|
| 199 | - return $this->generateFreeBusyCalendar($fbData); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - /** |
|
| 203 | - * This method takes a VAVAILABILITY component and figures out all the |
|
| 204 | - * available times. |
|
| 205 | - */ |
|
| 206 | - protected function calculateAvailability(FreeBusyData $fbData, VCalendar $vavailability) |
|
| 207 | - { |
|
| 208 | - $vavailComps = iterator_to_array($vavailability->VAVAILABILITY); |
|
| 209 | - usort( |
|
| 210 | - $vavailComps, |
|
| 211 | - function ($a, $b) { |
|
| 212 | - // We need to order the components by priority. Priority 1 |
|
| 213 | - // comes first, up until priority 9. Priority 0 comes after |
|
| 214 | - // priority 9. No priority implies priority 0. |
|
| 215 | - // |
|
| 216 | - // Yes, I'm serious. |
|
| 217 | - $priorityA = isset($a->PRIORITY) ? (int) $a->PRIORITY->getValue() : 0; |
|
| 218 | - $priorityB = isset($b->PRIORITY) ? (int) $b->PRIORITY->getValue() : 0; |
|
| 219 | - |
|
| 220 | - if (0 === $priorityA) { |
|
| 221 | - $priorityA = 10; |
|
| 222 | - } |
|
| 223 | - if (0 === $priorityB) { |
|
| 224 | - $priorityB = 10; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - return $priorityA - $priorityB; |
|
| 228 | - } |
|
| 229 | - ); |
|
| 230 | - |
|
| 231 | - // Now we go over all the VAVAILABILITY components and figure if |
|
| 232 | - // there's any we don't need to consider. |
|
| 233 | - // |
|
| 234 | - // This is can be because of one of two reasons: either the |
|
| 235 | - // VAVAILABILITY component falls outside the time we are interested in, |
|
| 236 | - // or a different VAVAILABILITY component with a higher priority has |
|
| 237 | - // already completely covered the time-range. |
|
| 238 | - $old = $vavailComps; |
|
| 239 | - $new = []; |
|
| 240 | - |
|
| 241 | - foreach ($old as $vavail) { |
|
| 242 | - list($compStart, $compEnd) = $vavail->getEffectiveStartEnd(); |
|
| 243 | - |
|
| 244 | - // We don't care about datetimes that are earlier or later than the |
|
| 245 | - // start and end of the freebusy report, so this gets normalized |
|
| 246 | - // first. |
|
| 247 | - if (is_null($compStart) || $compStart < $this->start) { |
|
| 248 | - $compStart = $this->start; |
|
| 249 | - } |
|
| 250 | - if (is_null($compEnd) || $compEnd > $this->end) { |
|
| 251 | - $compEnd = $this->end; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // If the item fell out of the timerange, we can just skip it. |
|
| 255 | - if ($compStart > $this->end || $compEnd < $this->start) { |
|
| 256 | - continue; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - // Going through our existing list of components to see if there's |
|
| 260 | - // a higher priority component that already fully covers this one. |
|
| 261 | - foreach ($new as $higherVavail) { |
|
| 262 | - list($higherStart, $higherEnd) = $higherVavail->getEffectiveStartEnd(); |
|
| 263 | - if ( |
|
| 264 | - (is_null($higherStart) || $higherStart < $compStart) && |
|
| 265 | - (is_null($higherEnd) || $higherEnd > $compEnd) |
|
| 266 | - ) { |
|
| 267 | - // Component is fully covered by a higher priority |
|
| 268 | - // component. We can skip this component. |
|
| 269 | - continue 2; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // We're keeping it! |
|
| 274 | - $new[] = $vavail; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // Lastly, we need to traverse the remaining components and fill in the |
|
| 278 | - // freebusydata slots. |
|
| 279 | - // |
|
| 280 | - // We traverse the components in reverse, because we want the higher |
|
| 281 | - // priority components to override the lower ones. |
|
| 282 | - foreach (array_reverse($new) as $vavail) { |
|
| 283 | - $busyType = isset($vavail->BUSYTYPE) ? strtoupper($vavail->BUSYTYPE) : 'BUSY-UNAVAILABLE'; |
|
| 284 | - list($vavailStart, $vavailEnd) = $vavail->getEffectiveStartEnd(); |
|
| 285 | - |
|
| 286 | - // Making the component size no larger than the requested free-busy |
|
| 287 | - // report range. |
|
| 288 | - if (!$vavailStart || $vavailStart < $this->start) { |
|
| 289 | - $vavailStart = $this->start; |
|
| 290 | - } |
|
| 291 | - if (!$vavailEnd || $vavailEnd > $this->end) { |
|
| 292 | - $vavailEnd = $this->end; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // Marking the entire time range of the VAVAILABILITY component as |
|
| 296 | - // busy. |
|
| 297 | - $fbData->add( |
|
| 298 | - $vavailStart->getTimeStamp(), |
|
| 299 | - $vavailEnd->getTimeStamp(), |
|
| 300 | - $busyType |
|
| 301 | - ); |
|
| 302 | - |
|
| 303 | - // Looping over the AVAILABLE components. |
|
| 304 | - if (isset($vavail->AVAILABLE)) { |
|
| 305 | - foreach ($vavail->AVAILABLE as $available) { |
|
| 306 | - list($availStart, $availEnd) = $available->getEffectiveStartEnd(); |
|
| 307 | - $fbData->add( |
|
| 308 | - $availStart->getTimeStamp(), |
|
| 309 | - $availEnd->getTimeStamp(), |
|
| 310 | - 'FREE' |
|
| 311 | - ); |
|
| 312 | - |
|
| 313 | - if ($available->RRULE) { |
|
| 314 | - // Our favourite thing: recurrence!! |
|
| 315 | - |
|
| 316 | - $rruleIterator = new Recur\RRuleIterator( |
|
| 317 | - $available->RRULE->getValue(), |
|
| 318 | - $availStart |
|
| 319 | - ); |
|
| 320 | - $rruleIterator->fastForward($vavailStart); |
|
| 321 | - |
|
| 322 | - $startEndDiff = $availStart->diff($availEnd); |
|
| 323 | - |
|
| 324 | - while ($rruleIterator->valid()) { |
|
| 325 | - $recurStart = $rruleIterator->current(); |
|
| 326 | - $recurEnd = $recurStart->add($startEndDiff); |
|
| 327 | - |
|
| 328 | - if ($recurStart > $vavailEnd) { |
|
| 329 | - // We're beyond the legal timerange. |
|
| 330 | - break; |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - if ($recurEnd > $vavailEnd) { |
|
| 334 | - // Truncating the end if it exceeds the |
|
| 335 | - // VAVAILABILITY end. |
|
| 336 | - $recurEnd = $vavailEnd; |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - $fbData->add( |
|
| 340 | - $recurStart->getTimeStamp(), |
|
| 341 | - $recurEnd->getTimeStamp(), |
|
| 342 | - 'FREE' |
|
| 343 | - ); |
|
| 344 | - |
|
| 345 | - $rruleIterator->next(); |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * This method takes an array of iCalendar objects and applies its busy |
|
| 355 | - * times on fbData. |
|
| 356 | - * |
|
| 357 | - * @param VCalendar[] $objects |
|
| 358 | - */ |
|
| 359 | - protected function calculateBusy(FreeBusyData $fbData, array $objects) |
|
| 360 | - { |
|
| 361 | - foreach ($objects as $key => $object) { |
|
| 362 | - foreach ($object->getBaseComponents() as $component) { |
|
| 363 | - switch ($component->name) { |
|
| 364 | - case 'VEVENT': |
|
| 365 | - $FBTYPE = 'BUSY'; |
|
| 366 | - if (isset($component->TRANSP) && ('TRANSPARENT' === strtoupper($component->TRANSP))) { |
|
| 367 | - break; |
|
| 368 | - } |
|
| 369 | - if (isset($component->STATUS)) { |
|
| 370 | - $status = strtoupper($component->STATUS); |
|
| 371 | - if ('CANCELLED' === $status) { |
|
| 372 | - break; |
|
| 373 | - } |
|
| 374 | - if ('TENTATIVE' === $status) { |
|
| 375 | - $FBTYPE = 'BUSY-TENTATIVE'; |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - $times = []; |
|
| 380 | - |
|
| 381 | - if ($component->RRULE) { |
|
| 382 | - try { |
|
| 383 | - $iterator = new EventIterator($object, (string) $component->UID, $this->timeZone); |
|
| 384 | - } catch (NoInstancesException $e) { |
|
| 385 | - // This event is recurring, but it doesn't have a single |
|
| 386 | - // instance. We are skipping this event from the output |
|
| 387 | - // entirely. |
|
| 388 | - unset($this->objects[$key]); |
|
| 389 | - break; |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - if ($this->start) { |
|
| 393 | - $iterator->fastForward($this->start); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - $maxRecurrences = Settings::$maxRecurrences; |
|
| 397 | - |
|
| 398 | - while ($iterator->valid() && --$maxRecurrences) { |
|
| 399 | - $startTime = $iterator->getDTStart(); |
|
| 400 | - if ($this->end && $startTime > $this->end) { |
|
| 401 | - break; |
|
| 402 | - } |
|
| 403 | - $times[] = [ |
|
| 404 | - $iterator->getDTStart(), |
|
| 405 | - $iterator->getDTEnd(), |
|
| 406 | - ]; |
|
| 407 | - |
|
| 408 | - $iterator->next(); |
|
| 409 | - } |
|
| 410 | - } else { |
|
| 411 | - $startTime = $component->DTSTART->getDateTime($this->timeZone); |
|
| 412 | - if ($this->end && $startTime > $this->end) { |
|
| 413 | - break; |
|
| 414 | - } |
|
| 415 | - $endTime = null; |
|
| 416 | - if (isset($component->DTEND)) { |
|
| 417 | - $endTime = $component->DTEND->getDateTime($this->timeZone); |
|
| 418 | - } elseif (isset($component->DURATION)) { |
|
| 419 | - $duration = DateTimeParser::parseDuration((string) $component->DURATION); |
|
| 420 | - $endTime = clone $startTime; |
|
| 421 | - $endTime = $endTime->add($duration); |
|
| 422 | - } elseif (!$component->DTSTART->hasTime()) { |
|
| 423 | - $endTime = clone $startTime; |
|
| 424 | - $endTime = $endTime->modify('+1 day'); |
|
| 425 | - } else { |
|
| 426 | - // The event had no duration (0 seconds) |
|
| 427 | - break; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - $times[] = [$startTime, $endTime]; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - foreach ($times as $time) { |
|
| 434 | - if ($this->end && $time[0] > $this->end) { |
|
| 435 | - break; |
|
| 436 | - } |
|
| 437 | - if ($this->start && $time[1] < $this->start) { |
|
| 438 | - break; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - $fbData->add( |
|
| 442 | - $time[0]->getTimeStamp(), |
|
| 443 | - $time[1]->getTimeStamp(), |
|
| 444 | - $FBTYPE |
|
| 445 | - ); |
|
| 446 | - } |
|
| 447 | - break; |
|
| 448 | - |
|
| 449 | - case 'VFREEBUSY': |
|
| 450 | - foreach ($component->FREEBUSY as $freebusy) { |
|
| 451 | - $fbType = isset($freebusy['FBTYPE']) ? strtoupper($freebusy['FBTYPE']) : 'BUSY'; |
|
| 452 | - |
|
| 453 | - // Skipping intervals marked as 'free' |
|
| 454 | - if ('FREE' === $fbType) { |
|
| 455 | - continue; |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - $values = explode(',', $freebusy); |
|
| 459 | - foreach ($values as $value) { |
|
| 460 | - list($startTime, $endTime) = explode('/', $value); |
|
| 461 | - $startTime = DateTimeParser::parseDateTime($startTime); |
|
| 462 | - |
|
| 463 | - if ('P' === substr($endTime, 0, 1) || '-P' === substr($endTime, 0, 2)) { |
|
| 464 | - $duration = DateTimeParser::parseDuration($endTime); |
|
| 465 | - $endTime = clone $startTime; |
|
| 466 | - $endTime = $endTime->add($duration); |
|
| 467 | - } else { |
|
| 468 | - $endTime = DateTimeParser::parseDateTime($endTime); |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - if ($this->start && $this->start > $endTime) { |
|
| 472 | - continue; |
|
| 473 | - } |
|
| 474 | - if ($this->end && $this->end < $startTime) { |
|
| 475 | - continue; |
|
| 476 | - } |
|
| 477 | - $fbData->add( |
|
| 478 | - $startTime->getTimeStamp(), |
|
| 479 | - $endTime->getTimeStamp(), |
|
| 480 | - $fbType |
|
| 481 | - ); |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - break; |
|
| 485 | - } |
|
| 486 | - } |
|
| 487 | - } |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - /** |
|
| 491 | - * This method takes a FreeBusyData object and generates the VCALENDAR |
|
| 492 | - * object associated with it. |
|
| 493 | - * |
|
| 494 | - * @return VCalendar |
|
| 495 | - */ |
|
| 496 | - protected function generateFreeBusyCalendar(FreeBusyData $fbData) |
|
| 497 | - { |
|
| 498 | - if ($this->baseObject) { |
|
| 499 | - $calendar = $this->baseObject; |
|
| 500 | - } else { |
|
| 501 | - $calendar = new VCalendar(); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - $vfreebusy = $calendar->createComponent('VFREEBUSY'); |
|
| 505 | - $calendar->add($vfreebusy); |
|
| 506 | - |
|
| 507 | - if ($this->start) { |
|
| 508 | - $dtstart = $calendar->createProperty('DTSTART'); |
|
| 509 | - $dtstart->setDateTime($this->start); |
|
| 510 | - $vfreebusy->add($dtstart); |
|
| 511 | - } |
|
| 512 | - if ($this->end) { |
|
| 513 | - $dtend = $calendar->createProperty('DTEND'); |
|
| 514 | - $dtend->setDateTime($this->end); |
|
| 515 | - $vfreebusy->add($dtend); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - $tz = new \DateTimeZone('UTC'); |
|
| 519 | - $dtstamp = $calendar->createProperty('DTSTAMP'); |
|
| 520 | - $dtstamp->setDateTime(new DateTimeImmutable('now', $tz)); |
|
| 521 | - $vfreebusy->add($dtstamp); |
|
| 522 | - |
|
| 523 | - foreach ($fbData->getData() as $busyTime) { |
|
| 524 | - $busyType = strtoupper($busyTime['type']); |
|
| 525 | - |
|
| 526 | - // Ignoring all the FREE parts, because those are already assumed. |
|
| 527 | - if ('FREE' === $busyType) { |
|
| 528 | - continue; |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - $busyTime[0] = new \DateTimeImmutable('@'.$busyTime['start'], $tz); |
|
| 532 | - $busyTime[1] = new \DateTimeImmutable('@'.$busyTime['end'], $tz); |
|
| 533 | - |
|
| 534 | - $prop = $calendar->createProperty( |
|
| 535 | - 'FREEBUSY', |
|
| 536 | - $busyTime[0]->format('Ymd\\THis\\Z').'/'.$busyTime[1]->format('Ymd\\THis\\Z') |
|
| 537 | - ); |
|
| 538 | - |
|
| 539 | - // Only setting FBTYPE if it's not BUSY, because BUSY is the |
|
| 540 | - // default anyway. |
|
| 541 | - if ('BUSY' !== $busyType) { |
|
| 542 | - $prop['FBTYPE'] = $busyType; |
|
| 543 | - } |
|
| 544 | - $vfreebusy->add($prop); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - return $calendar; |
|
| 548 | - } |
|
| 28 | + /** |
|
| 29 | + * Input objects. |
|
| 30 | + * |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + protected $objects = []; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Start of range. |
|
| 37 | + * |
|
| 38 | + * @var DateTimeInterface|null |
|
| 39 | + */ |
|
| 40 | + protected $start; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * End of range. |
|
| 44 | + * |
|
| 45 | + * @var DateTimeInterface|null |
|
| 46 | + */ |
|
| 47 | + protected $end; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * VCALENDAR object. |
|
| 51 | + * |
|
| 52 | + * @var Document |
|
| 53 | + */ |
|
| 54 | + protected $baseObject; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Reference timezone. |
|
| 58 | + * |
|
| 59 | + * When we are calculating busy times, and we come across so-called |
|
| 60 | + * floating times (times without a timezone), we use the reference timezone |
|
| 61 | + * instead. |
|
| 62 | + * |
|
| 63 | + * This is also used for all-day events. |
|
| 64 | + * |
|
| 65 | + * This defaults to UTC. |
|
| 66 | + * |
|
| 67 | + * @var DateTimeZone |
|
| 68 | + */ |
|
| 69 | + protected $timeZone; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * A VAVAILABILITY document. |
|
| 73 | + * |
|
| 74 | + * If this is set, its information will be included when calculating |
|
| 75 | + * freebusy time. |
|
| 76 | + * |
|
| 77 | + * @var Document |
|
| 78 | + */ |
|
| 79 | + protected $vavailability; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Creates the generator. |
|
| 83 | + * |
|
| 84 | + * Check the setTimeRange and setObjects methods for details about the |
|
| 85 | + * arguments. |
|
| 86 | + * |
|
| 87 | + * @param DateTimeInterface $start |
|
| 88 | + * @param DateTimeInterface $end |
|
| 89 | + * @param mixed $objects |
|
| 90 | + * @param DateTimeZone $timeZone |
|
| 91 | + */ |
|
| 92 | + public function __construct(DateTimeInterface $start = null, DateTimeInterface $end = null, $objects = null, DateTimeZone $timeZone = null) |
|
| 93 | + { |
|
| 94 | + $this->setTimeRange($start, $end); |
|
| 95 | + |
|
| 96 | + if ($objects) { |
|
| 97 | + $this->setObjects($objects); |
|
| 98 | + } |
|
| 99 | + if (is_null($timeZone)) { |
|
| 100 | + $timeZone = new DateTimeZone('UTC'); |
|
| 101 | + } |
|
| 102 | + $this->setTimeZone($timeZone); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Sets the VCALENDAR object. |
|
| 107 | + * |
|
| 108 | + * If this is set, it will not be generated for you. You are responsible |
|
| 109 | + * for setting things like the METHOD, CALSCALE, VERSION, etc.. |
|
| 110 | + * |
|
| 111 | + * The VFREEBUSY object will be automatically added though. |
|
| 112 | + */ |
|
| 113 | + public function setBaseObject(Document $vcalendar) |
|
| 114 | + { |
|
| 115 | + $this->baseObject = $vcalendar; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Sets a VAVAILABILITY document. |
|
| 120 | + */ |
|
| 121 | + public function setVAvailability(Document $vcalendar) |
|
| 122 | + { |
|
| 123 | + $this->vavailability = $vcalendar; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * Sets the input objects. |
|
| 128 | + * |
|
| 129 | + * You must either specify a vcalendar object as a string, or as the parse |
|
| 130 | + * Component. |
|
| 131 | + * It's also possible to specify multiple objects as an array. |
|
| 132 | + * |
|
| 133 | + * @param mixed $objects |
|
| 134 | + */ |
|
| 135 | + public function setObjects($objects) |
|
| 136 | + { |
|
| 137 | + if (!is_array($objects)) { |
|
| 138 | + $objects = [$objects]; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + $this->objects = []; |
|
| 142 | + foreach ($objects as $object) { |
|
| 143 | + if (is_string($object) || is_resource($object)) { |
|
| 144 | + $this->objects[] = Reader::read($object); |
|
| 145 | + } elseif ($object instanceof Component) { |
|
| 146 | + $this->objects[] = $object; |
|
| 147 | + } else { |
|
| 148 | + throw new \InvalidArgumentException('You can only pass strings or \\Sabre\\VObject\\Component arguments to setObjects'); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Sets the time range. |
|
| 155 | + * |
|
| 156 | + * Any freebusy object falling outside of this time range will be ignored. |
|
| 157 | + * |
|
| 158 | + * @param DateTimeInterface $start |
|
| 159 | + * @param DateTimeInterface $end |
|
| 160 | + */ |
|
| 161 | + public function setTimeRange(DateTimeInterface $start = null, DateTimeInterface $end = null) |
|
| 162 | + { |
|
| 163 | + if (!$start) { |
|
| 164 | + $start = new DateTimeImmutable(Settings::$minDate); |
|
| 165 | + } |
|
| 166 | + if (!$end) { |
|
| 167 | + $end = new DateTimeImmutable(Settings::$maxDate); |
|
| 168 | + } |
|
| 169 | + $this->start = $start; |
|
| 170 | + $this->end = $end; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Sets the reference timezone for floating times. |
|
| 175 | + */ |
|
| 176 | + public function setTimeZone(DateTimeZone $timeZone) |
|
| 177 | + { |
|
| 178 | + $this->timeZone = $timeZone; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * Parses the input data and returns a correct VFREEBUSY object, wrapped in |
|
| 183 | + * a VCALENDAR. |
|
| 184 | + * |
|
| 185 | + * @return Component |
|
| 186 | + */ |
|
| 187 | + public function getResult() |
|
| 188 | + { |
|
| 189 | + $fbData = new FreeBusyData( |
|
| 190 | + $this->start->getTimeStamp(), |
|
| 191 | + $this->end->getTimeStamp() |
|
| 192 | + ); |
|
| 193 | + if ($this->vavailability) { |
|
| 194 | + $this->calculateAvailability($fbData, $this->vavailability); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $this->calculateBusy($fbData, $this->objects); |
|
| 198 | + |
|
| 199 | + return $this->generateFreeBusyCalendar($fbData); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + /** |
|
| 203 | + * This method takes a VAVAILABILITY component and figures out all the |
|
| 204 | + * available times. |
|
| 205 | + */ |
|
| 206 | + protected function calculateAvailability(FreeBusyData $fbData, VCalendar $vavailability) |
|
| 207 | + { |
|
| 208 | + $vavailComps = iterator_to_array($vavailability->VAVAILABILITY); |
|
| 209 | + usort( |
|
| 210 | + $vavailComps, |
|
| 211 | + function ($a, $b) { |
|
| 212 | + // We need to order the components by priority. Priority 1 |
|
| 213 | + // comes first, up until priority 9. Priority 0 comes after |
|
| 214 | + // priority 9. No priority implies priority 0. |
|
| 215 | + // |
|
| 216 | + // Yes, I'm serious. |
|
| 217 | + $priorityA = isset($a->PRIORITY) ? (int) $a->PRIORITY->getValue() : 0; |
|
| 218 | + $priorityB = isset($b->PRIORITY) ? (int) $b->PRIORITY->getValue() : 0; |
|
| 219 | + |
|
| 220 | + if (0 === $priorityA) { |
|
| 221 | + $priorityA = 10; |
|
| 222 | + } |
|
| 223 | + if (0 === $priorityB) { |
|
| 224 | + $priorityB = 10; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + return $priorityA - $priorityB; |
|
| 228 | + } |
|
| 229 | + ); |
|
| 230 | + |
|
| 231 | + // Now we go over all the VAVAILABILITY components and figure if |
|
| 232 | + // there's any we don't need to consider. |
|
| 233 | + // |
|
| 234 | + // This is can be because of one of two reasons: either the |
|
| 235 | + // VAVAILABILITY component falls outside the time we are interested in, |
|
| 236 | + // or a different VAVAILABILITY component with a higher priority has |
|
| 237 | + // already completely covered the time-range. |
|
| 238 | + $old = $vavailComps; |
|
| 239 | + $new = []; |
|
| 240 | + |
|
| 241 | + foreach ($old as $vavail) { |
|
| 242 | + list($compStart, $compEnd) = $vavail->getEffectiveStartEnd(); |
|
| 243 | + |
|
| 244 | + // We don't care about datetimes that are earlier or later than the |
|
| 245 | + // start and end of the freebusy report, so this gets normalized |
|
| 246 | + // first. |
|
| 247 | + if (is_null($compStart) || $compStart < $this->start) { |
|
| 248 | + $compStart = $this->start; |
|
| 249 | + } |
|
| 250 | + if (is_null($compEnd) || $compEnd > $this->end) { |
|
| 251 | + $compEnd = $this->end; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // If the item fell out of the timerange, we can just skip it. |
|
| 255 | + if ($compStart > $this->end || $compEnd < $this->start) { |
|
| 256 | + continue; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + // Going through our existing list of components to see if there's |
|
| 260 | + // a higher priority component that already fully covers this one. |
|
| 261 | + foreach ($new as $higherVavail) { |
|
| 262 | + list($higherStart, $higherEnd) = $higherVavail->getEffectiveStartEnd(); |
|
| 263 | + if ( |
|
| 264 | + (is_null($higherStart) || $higherStart < $compStart) && |
|
| 265 | + (is_null($higherEnd) || $higherEnd > $compEnd) |
|
| 266 | + ) { |
|
| 267 | + // Component is fully covered by a higher priority |
|
| 268 | + // component. We can skip this component. |
|
| 269 | + continue 2; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // We're keeping it! |
|
| 274 | + $new[] = $vavail; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // Lastly, we need to traverse the remaining components and fill in the |
|
| 278 | + // freebusydata slots. |
|
| 279 | + // |
|
| 280 | + // We traverse the components in reverse, because we want the higher |
|
| 281 | + // priority components to override the lower ones. |
|
| 282 | + foreach (array_reverse($new) as $vavail) { |
|
| 283 | + $busyType = isset($vavail->BUSYTYPE) ? strtoupper($vavail->BUSYTYPE) : 'BUSY-UNAVAILABLE'; |
|
| 284 | + list($vavailStart, $vavailEnd) = $vavail->getEffectiveStartEnd(); |
|
| 285 | + |
|
| 286 | + // Making the component size no larger than the requested free-busy |
|
| 287 | + // report range. |
|
| 288 | + if (!$vavailStart || $vavailStart < $this->start) { |
|
| 289 | + $vavailStart = $this->start; |
|
| 290 | + } |
|
| 291 | + if (!$vavailEnd || $vavailEnd > $this->end) { |
|
| 292 | + $vavailEnd = $this->end; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // Marking the entire time range of the VAVAILABILITY component as |
|
| 296 | + // busy. |
|
| 297 | + $fbData->add( |
|
| 298 | + $vavailStart->getTimeStamp(), |
|
| 299 | + $vavailEnd->getTimeStamp(), |
|
| 300 | + $busyType |
|
| 301 | + ); |
|
| 302 | + |
|
| 303 | + // Looping over the AVAILABLE components. |
|
| 304 | + if (isset($vavail->AVAILABLE)) { |
|
| 305 | + foreach ($vavail->AVAILABLE as $available) { |
|
| 306 | + list($availStart, $availEnd) = $available->getEffectiveStartEnd(); |
|
| 307 | + $fbData->add( |
|
| 308 | + $availStart->getTimeStamp(), |
|
| 309 | + $availEnd->getTimeStamp(), |
|
| 310 | + 'FREE' |
|
| 311 | + ); |
|
| 312 | + |
|
| 313 | + if ($available->RRULE) { |
|
| 314 | + // Our favourite thing: recurrence!! |
|
| 315 | + |
|
| 316 | + $rruleIterator = new Recur\RRuleIterator( |
|
| 317 | + $available->RRULE->getValue(), |
|
| 318 | + $availStart |
|
| 319 | + ); |
|
| 320 | + $rruleIterator->fastForward($vavailStart); |
|
| 321 | + |
|
| 322 | + $startEndDiff = $availStart->diff($availEnd); |
|
| 323 | + |
|
| 324 | + while ($rruleIterator->valid()) { |
|
| 325 | + $recurStart = $rruleIterator->current(); |
|
| 326 | + $recurEnd = $recurStart->add($startEndDiff); |
|
| 327 | + |
|
| 328 | + if ($recurStart > $vavailEnd) { |
|
| 329 | + // We're beyond the legal timerange. |
|
| 330 | + break; |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + if ($recurEnd > $vavailEnd) { |
|
| 334 | + // Truncating the end if it exceeds the |
|
| 335 | + // VAVAILABILITY end. |
|
| 336 | + $recurEnd = $vavailEnd; |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + $fbData->add( |
|
| 340 | + $recurStart->getTimeStamp(), |
|
| 341 | + $recurEnd->getTimeStamp(), |
|
| 342 | + 'FREE' |
|
| 343 | + ); |
|
| 344 | + |
|
| 345 | + $rruleIterator->next(); |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * This method takes an array of iCalendar objects and applies its busy |
|
| 355 | + * times on fbData. |
|
| 356 | + * |
|
| 357 | + * @param VCalendar[] $objects |
|
| 358 | + */ |
|
| 359 | + protected function calculateBusy(FreeBusyData $fbData, array $objects) |
|
| 360 | + { |
|
| 361 | + foreach ($objects as $key => $object) { |
|
| 362 | + foreach ($object->getBaseComponents() as $component) { |
|
| 363 | + switch ($component->name) { |
|
| 364 | + case 'VEVENT': |
|
| 365 | + $FBTYPE = 'BUSY'; |
|
| 366 | + if (isset($component->TRANSP) && ('TRANSPARENT' === strtoupper($component->TRANSP))) { |
|
| 367 | + break; |
|
| 368 | + } |
|
| 369 | + if (isset($component->STATUS)) { |
|
| 370 | + $status = strtoupper($component->STATUS); |
|
| 371 | + if ('CANCELLED' === $status) { |
|
| 372 | + break; |
|
| 373 | + } |
|
| 374 | + if ('TENTATIVE' === $status) { |
|
| 375 | + $FBTYPE = 'BUSY-TENTATIVE'; |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + $times = []; |
|
| 380 | + |
|
| 381 | + if ($component->RRULE) { |
|
| 382 | + try { |
|
| 383 | + $iterator = new EventIterator($object, (string) $component->UID, $this->timeZone); |
|
| 384 | + } catch (NoInstancesException $e) { |
|
| 385 | + // This event is recurring, but it doesn't have a single |
|
| 386 | + // instance. We are skipping this event from the output |
|
| 387 | + // entirely. |
|
| 388 | + unset($this->objects[$key]); |
|
| 389 | + break; |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + if ($this->start) { |
|
| 393 | + $iterator->fastForward($this->start); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + $maxRecurrences = Settings::$maxRecurrences; |
|
| 397 | + |
|
| 398 | + while ($iterator->valid() && --$maxRecurrences) { |
|
| 399 | + $startTime = $iterator->getDTStart(); |
|
| 400 | + if ($this->end && $startTime > $this->end) { |
|
| 401 | + break; |
|
| 402 | + } |
|
| 403 | + $times[] = [ |
|
| 404 | + $iterator->getDTStart(), |
|
| 405 | + $iterator->getDTEnd(), |
|
| 406 | + ]; |
|
| 407 | + |
|
| 408 | + $iterator->next(); |
|
| 409 | + } |
|
| 410 | + } else { |
|
| 411 | + $startTime = $component->DTSTART->getDateTime($this->timeZone); |
|
| 412 | + if ($this->end && $startTime > $this->end) { |
|
| 413 | + break; |
|
| 414 | + } |
|
| 415 | + $endTime = null; |
|
| 416 | + if (isset($component->DTEND)) { |
|
| 417 | + $endTime = $component->DTEND->getDateTime($this->timeZone); |
|
| 418 | + } elseif (isset($component->DURATION)) { |
|
| 419 | + $duration = DateTimeParser::parseDuration((string) $component->DURATION); |
|
| 420 | + $endTime = clone $startTime; |
|
| 421 | + $endTime = $endTime->add($duration); |
|
| 422 | + } elseif (!$component->DTSTART->hasTime()) { |
|
| 423 | + $endTime = clone $startTime; |
|
| 424 | + $endTime = $endTime->modify('+1 day'); |
|
| 425 | + } else { |
|
| 426 | + // The event had no duration (0 seconds) |
|
| 427 | + break; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + $times[] = [$startTime, $endTime]; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + foreach ($times as $time) { |
|
| 434 | + if ($this->end && $time[0] > $this->end) { |
|
| 435 | + break; |
|
| 436 | + } |
|
| 437 | + if ($this->start && $time[1] < $this->start) { |
|
| 438 | + break; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + $fbData->add( |
|
| 442 | + $time[0]->getTimeStamp(), |
|
| 443 | + $time[1]->getTimeStamp(), |
|
| 444 | + $FBTYPE |
|
| 445 | + ); |
|
| 446 | + } |
|
| 447 | + break; |
|
| 448 | + |
|
| 449 | + case 'VFREEBUSY': |
|
| 450 | + foreach ($component->FREEBUSY as $freebusy) { |
|
| 451 | + $fbType = isset($freebusy['FBTYPE']) ? strtoupper($freebusy['FBTYPE']) : 'BUSY'; |
|
| 452 | + |
|
| 453 | + // Skipping intervals marked as 'free' |
|
| 454 | + if ('FREE' === $fbType) { |
|
| 455 | + continue; |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + $values = explode(',', $freebusy); |
|
| 459 | + foreach ($values as $value) { |
|
| 460 | + list($startTime, $endTime) = explode('/', $value); |
|
| 461 | + $startTime = DateTimeParser::parseDateTime($startTime); |
|
| 462 | + |
|
| 463 | + if ('P' === substr($endTime, 0, 1) || '-P' === substr($endTime, 0, 2)) { |
|
| 464 | + $duration = DateTimeParser::parseDuration($endTime); |
|
| 465 | + $endTime = clone $startTime; |
|
| 466 | + $endTime = $endTime->add($duration); |
|
| 467 | + } else { |
|
| 468 | + $endTime = DateTimeParser::parseDateTime($endTime); |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + if ($this->start && $this->start > $endTime) { |
|
| 472 | + continue; |
|
| 473 | + } |
|
| 474 | + if ($this->end && $this->end < $startTime) { |
|
| 475 | + continue; |
|
| 476 | + } |
|
| 477 | + $fbData->add( |
|
| 478 | + $startTime->getTimeStamp(), |
|
| 479 | + $endTime->getTimeStamp(), |
|
| 480 | + $fbType |
|
| 481 | + ); |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + break; |
|
| 485 | + } |
|
| 486 | + } |
|
| 487 | + } |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + /** |
|
| 491 | + * This method takes a FreeBusyData object and generates the VCALENDAR |
|
| 492 | + * object associated with it. |
|
| 493 | + * |
|
| 494 | + * @return VCalendar |
|
| 495 | + */ |
|
| 496 | + protected function generateFreeBusyCalendar(FreeBusyData $fbData) |
|
| 497 | + { |
|
| 498 | + if ($this->baseObject) { |
|
| 499 | + $calendar = $this->baseObject; |
|
| 500 | + } else { |
|
| 501 | + $calendar = new VCalendar(); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + $vfreebusy = $calendar->createComponent('VFREEBUSY'); |
|
| 505 | + $calendar->add($vfreebusy); |
|
| 506 | + |
|
| 507 | + if ($this->start) { |
|
| 508 | + $dtstart = $calendar->createProperty('DTSTART'); |
|
| 509 | + $dtstart->setDateTime($this->start); |
|
| 510 | + $vfreebusy->add($dtstart); |
|
| 511 | + } |
|
| 512 | + if ($this->end) { |
|
| 513 | + $dtend = $calendar->createProperty('DTEND'); |
|
| 514 | + $dtend->setDateTime($this->end); |
|
| 515 | + $vfreebusy->add($dtend); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + $tz = new \DateTimeZone('UTC'); |
|
| 519 | + $dtstamp = $calendar->createProperty('DTSTAMP'); |
|
| 520 | + $dtstamp->setDateTime(new DateTimeImmutable('now', $tz)); |
|
| 521 | + $vfreebusy->add($dtstamp); |
|
| 522 | + |
|
| 523 | + foreach ($fbData->getData() as $busyTime) { |
|
| 524 | + $busyType = strtoupper($busyTime['type']); |
|
| 525 | + |
|
| 526 | + // Ignoring all the FREE parts, because those are already assumed. |
|
| 527 | + if ('FREE' === $busyType) { |
|
| 528 | + continue; |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + $busyTime[0] = new \DateTimeImmutable('@'.$busyTime['start'], $tz); |
|
| 532 | + $busyTime[1] = new \DateTimeImmutable('@'.$busyTime['end'], $tz); |
|
| 533 | + |
|
| 534 | + $prop = $calendar->createProperty( |
|
| 535 | + 'FREEBUSY', |
|
| 536 | + $busyTime[0]->format('Ymd\\THis\\Z').'/'.$busyTime[1]->format('Ymd\\THis\\Z') |
|
| 537 | + ); |
|
| 538 | + |
|
| 539 | + // Only setting FBTYPE if it's not BUSY, because BUSY is the |
|
| 540 | + // default anyway. |
|
| 541 | + if ('BUSY' !== $busyType) { |
|
| 542 | + $prop['FBTYPE'] = $busyType; |
|
| 543 | + } |
|
| 544 | + $vfreebusy->add($prop); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + return $calendar; |
|
| 548 | + } |
|
| 549 | 549 | } |
@@ -8,94 +8,94 @@ |
||
| 8 | 8 | * @license http://sabre.io/license/ Modified BSD License |
| 9 | 9 | */ |
| 10 | 10 | return [ |
| 11 | - 'Dateline' => 'Etc/GMT-12', |
|
| 12 | - 'Samoa' => 'Pacific/Apia', |
|
| 13 | - 'Hawaiian' => 'Pacific/Honolulu', |
|
| 14 | - 'Alaskan' => 'America/Anchorage', |
|
| 15 | - 'Pacific' => 'America/Los_Angeles', |
|
| 16 | - 'Pacific Standard Time' => 'America/Los_Angeles', |
|
| 17 | - 'Mexico Standard Time 2' => 'America/Chihuahua', |
|
| 18 | - 'Mountain' => 'America/Denver', |
|
| 19 | - // 'Mountain Standard Time' => 'America/Chihuahua', // conflict with windows timezones. |
|
| 20 | - 'US Mountain' => 'America/Phoenix', |
|
| 21 | - 'Canada Central' => 'America/Edmonton', |
|
| 22 | - 'Central America' => 'America/Guatemala', |
|
| 23 | - 'Central' => 'America/Chicago', |
|
| 24 | - // 'Central Standard Time' => 'America/Mexico_City', // conflict with windows timezones. |
|
| 25 | - 'Mexico' => 'America/Mexico_City', |
|
| 26 | - 'Eastern' => 'America/New_York', |
|
| 27 | - 'SA Pacific' => 'America/Bogota', |
|
| 28 | - 'US Eastern' => 'America/Indiana/Indianapolis', |
|
| 29 | - 'Venezuela' => 'America/Caracas', |
|
| 30 | - 'Atlantic' => 'America/Halifax', |
|
| 31 | - 'Central Brazilian' => 'America/Manaus', |
|
| 32 | - 'Pacific SA' => 'America/Santiago', |
|
| 33 | - 'SA Western' => 'America/La_Paz', |
|
| 34 | - 'Newfoundland' => 'America/St_Johns', |
|
| 35 | - 'Argentina' => 'America/Argentina/Buenos_Aires', |
|
| 36 | - 'E. South America' => 'America/Belem', |
|
| 37 | - 'Greenland' => 'America/Godthab', |
|
| 38 | - 'Montevideo' => 'America/Montevideo', |
|
| 39 | - 'SA Eastern' => 'America/Belem', |
|
| 40 | - // 'Mid-Atlantic' => 'Etc/GMT-2', // conflict with windows timezones. |
|
| 41 | - 'Azores' => 'Atlantic/Azores', |
|
| 42 | - 'Cape Verde' => 'Atlantic/Cape_Verde', |
|
| 43 | - 'Greenwich' => 'Atlantic/Reykjavik', // No I'm serious.. Greenwich is not GMT. |
|
| 44 | - 'Morocco' => 'Africa/Casablanca', |
|
| 45 | - 'Central Europe' => 'Europe/Prague', |
|
| 46 | - 'Central European' => 'Europe/Sarajevo', |
|
| 47 | - 'Romance' => 'Europe/Paris', |
|
| 48 | - 'W. Central Africa' => 'Africa/Lagos', // Best guess |
|
| 49 | - 'W. Europe' => 'Europe/Amsterdam', |
|
| 50 | - 'E. Europe' => 'Europe/Minsk', |
|
| 51 | - 'Egypt' => 'Africa/Cairo', |
|
| 52 | - 'FLE' => 'Europe/Helsinki', |
|
| 53 | - 'GTB' => 'Europe/Athens', |
|
| 54 | - 'Israel' => 'Asia/Jerusalem', |
|
| 55 | - 'Jordan' => 'Asia/Amman', |
|
| 56 | - 'Middle East' => 'Asia/Beirut', |
|
| 57 | - 'Namibia' => 'Africa/Windhoek', |
|
| 58 | - 'South Africa' => 'Africa/Harare', |
|
| 59 | - 'Arab' => 'Asia/Kuwait', |
|
| 60 | - 'Arabic' => 'Asia/Baghdad', |
|
| 61 | - 'E. Africa' => 'Africa/Nairobi', |
|
| 62 | - 'Georgian' => 'Asia/Tbilisi', |
|
| 63 | - 'Russian' => 'Europe/Moscow', |
|
| 64 | - 'Iran' => 'Asia/Tehran', |
|
| 65 | - 'Arabian' => 'Asia/Muscat', |
|
| 66 | - 'Armenian' => 'Asia/Yerevan', |
|
| 67 | - 'Azerbijan' => 'Asia/Baku', |
|
| 68 | - 'Caucasus' => 'Asia/Yerevan', |
|
| 69 | - 'Mauritius' => 'Indian/Mauritius', |
|
| 70 | - 'Afghanistan' => 'Asia/Kabul', |
|
| 71 | - 'Ekaterinburg' => 'Asia/Yekaterinburg', |
|
| 72 | - 'Pakistan' => 'Asia/Karachi', |
|
| 73 | - 'West Asia' => 'Asia/Tashkent', |
|
| 74 | - 'India' => 'Asia/Calcutta', |
|
| 75 | - 'Sri Lanka' => 'Asia/Colombo', |
|
| 76 | - 'Nepal' => 'Asia/Kathmandu', |
|
| 77 | - 'Central Asia' => 'Asia/Dhaka', |
|
| 78 | - 'N. Central Asia' => 'Asia/Almaty', |
|
| 79 | - 'Myanmar' => 'Asia/Rangoon', |
|
| 80 | - 'North Asia' => 'Asia/Krasnoyarsk', |
|
| 81 | - 'SE Asia' => 'Asia/Bangkok', |
|
| 82 | - 'China' => 'Asia/Shanghai', |
|
| 83 | - 'North Asia East' => 'Asia/Irkutsk', |
|
| 84 | - 'Singapore' => 'Asia/Singapore', |
|
| 85 | - 'Taipei' => 'Asia/Taipei', |
|
| 86 | - 'W. Australia' => 'Australia/Perth', |
|
| 87 | - 'Korea' => 'Asia/Seoul', |
|
| 88 | - 'Tokyo' => 'Asia/Tokyo', |
|
| 89 | - 'Yakutsk' => 'Asia/Yakutsk', |
|
| 90 | - 'AUS Central' => 'Australia/Darwin', |
|
| 91 | - 'Cen. Australia' => 'Australia/Adelaide', |
|
| 92 | - 'AUS Eastern' => 'Australia/Sydney', |
|
| 93 | - 'E. Australia' => 'Australia/Brisbane', |
|
| 94 | - 'Tasmania' => 'Australia/Hobart', |
|
| 95 | - 'Vladivostok' => 'Asia/Vladivostok', |
|
| 96 | - 'West Pacific' => 'Pacific/Guam', |
|
| 97 | - 'Central Pacific' => 'Asia/Magadan', |
|
| 98 | - 'Fiji' => 'Pacific/Fiji', |
|
| 99 | - 'New Zealand' => 'Pacific/Auckland', |
|
| 100 | - 'Tonga' => 'Pacific/Tongatapu', |
|
| 11 | + 'Dateline' => 'Etc/GMT-12', |
|
| 12 | + 'Samoa' => 'Pacific/Apia', |
|
| 13 | + 'Hawaiian' => 'Pacific/Honolulu', |
|
| 14 | + 'Alaskan' => 'America/Anchorage', |
|
| 15 | + 'Pacific' => 'America/Los_Angeles', |
|
| 16 | + 'Pacific Standard Time' => 'America/Los_Angeles', |
|
| 17 | + 'Mexico Standard Time 2' => 'America/Chihuahua', |
|
| 18 | + 'Mountain' => 'America/Denver', |
|
| 19 | + // 'Mountain Standard Time' => 'America/Chihuahua', // conflict with windows timezones. |
|
| 20 | + 'US Mountain' => 'America/Phoenix', |
|
| 21 | + 'Canada Central' => 'America/Edmonton', |
|
| 22 | + 'Central America' => 'America/Guatemala', |
|
| 23 | + 'Central' => 'America/Chicago', |
|
| 24 | + // 'Central Standard Time' => 'America/Mexico_City', // conflict with windows timezones. |
|
| 25 | + 'Mexico' => 'America/Mexico_City', |
|
| 26 | + 'Eastern' => 'America/New_York', |
|
| 27 | + 'SA Pacific' => 'America/Bogota', |
|
| 28 | + 'US Eastern' => 'America/Indiana/Indianapolis', |
|
| 29 | + 'Venezuela' => 'America/Caracas', |
|
| 30 | + 'Atlantic' => 'America/Halifax', |
|
| 31 | + 'Central Brazilian' => 'America/Manaus', |
|
| 32 | + 'Pacific SA' => 'America/Santiago', |
|
| 33 | + 'SA Western' => 'America/La_Paz', |
|
| 34 | + 'Newfoundland' => 'America/St_Johns', |
|
| 35 | + 'Argentina' => 'America/Argentina/Buenos_Aires', |
|
| 36 | + 'E. South America' => 'America/Belem', |
|
| 37 | + 'Greenland' => 'America/Godthab', |
|
| 38 | + 'Montevideo' => 'America/Montevideo', |
|
| 39 | + 'SA Eastern' => 'America/Belem', |
|
| 40 | + // 'Mid-Atlantic' => 'Etc/GMT-2', // conflict with windows timezones. |
|
| 41 | + 'Azores' => 'Atlantic/Azores', |
|
| 42 | + 'Cape Verde' => 'Atlantic/Cape_Verde', |
|
| 43 | + 'Greenwich' => 'Atlantic/Reykjavik', // No I'm serious.. Greenwich is not GMT. |
|
| 44 | + 'Morocco' => 'Africa/Casablanca', |
|
| 45 | + 'Central Europe' => 'Europe/Prague', |
|
| 46 | + 'Central European' => 'Europe/Sarajevo', |
|
| 47 | + 'Romance' => 'Europe/Paris', |
|
| 48 | + 'W. Central Africa' => 'Africa/Lagos', // Best guess |
|
| 49 | + 'W. Europe' => 'Europe/Amsterdam', |
|
| 50 | + 'E. Europe' => 'Europe/Minsk', |
|
| 51 | + 'Egypt' => 'Africa/Cairo', |
|
| 52 | + 'FLE' => 'Europe/Helsinki', |
|
| 53 | + 'GTB' => 'Europe/Athens', |
|
| 54 | + 'Israel' => 'Asia/Jerusalem', |
|
| 55 | + 'Jordan' => 'Asia/Amman', |
|
| 56 | + 'Middle East' => 'Asia/Beirut', |
|
| 57 | + 'Namibia' => 'Africa/Windhoek', |
|
| 58 | + 'South Africa' => 'Africa/Harare', |
|
| 59 | + 'Arab' => 'Asia/Kuwait', |
|
| 60 | + 'Arabic' => 'Asia/Baghdad', |
|
| 61 | + 'E. Africa' => 'Africa/Nairobi', |
|
| 62 | + 'Georgian' => 'Asia/Tbilisi', |
|
| 63 | + 'Russian' => 'Europe/Moscow', |
|
| 64 | + 'Iran' => 'Asia/Tehran', |
|
| 65 | + 'Arabian' => 'Asia/Muscat', |
|
| 66 | + 'Armenian' => 'Asia/Yerevan', |
|
| 67 | + 'Azerbijan' => 'Asia/Baku', |
|
| 68 | + 'Caucasus' => 'Asia/Yerevan', |
|
| 69 | + 'Mauritius' => 'Indian/Mauritius', |
|
| 70 | + 'Afghanistan' => 'Asia/Kabul', |
|
| 71 | + 'Ekaterinburg' => 'Asia/Yekaterinburg', |
|
| 72 | + 'Pakistan' => 'Asia/Karachi', |
|
| 73 | + 'West Asia' => 'Asia/Tashkent', |
|
| 74 | + 'India' => 'Asia/Calcutta', |
|
| 75 | + 'Sri Lanka' => 'Asia/Colombo', |
|
| 76 | + 'Nepal' => 'Asia/Kathmandu', |
|
| 77 | + 'Central Asia' => 'Asia/Dhaka', |
|
| 78 | + 'N. Central Asia' => 'Asia/Almaty', |
|
| 79 | + 'Myanmar' => 'Asia/Rangoon', |
|
| 80 | + 'North Asia' => 'Asia/Krasnoyarsk', |
|
| 81 | + 'SE Asia' => 'Asia/Bangkok', |
|
| 82 | + 'China' => 'Asia/Shanghai', |
|
| 83 | + 'North Asia East' => 'Asia/Irkutsk', |
|
| 84 | + 'Singapore' => 'Asia/Singapore', |
|
| 85 | + 'Taipei' => 'Asia/Taipei', |
|
| 86 | + 'W. Australia' => 'Australia/Perth', |
|
| 87 | + 'Korea' => 'Asia/Seoul', |
|
| 88 | + 'Tokyo' => 'Asia/Tokyo', |
|
| 89 | + 'Yakutsk' => 'Asia/Yakutsk', |
|
| 90 | + 'AUS Central' => 'Australia/Darwin', |
|
| 91 | + 'Cen. Australia' => 'Australia/Adelaide', |
|
| 92 | + 'AUS Eastern' => 'Australia/Sydney', |
|
| 93 | + 'E. Australia' => 'Australia/Brisbane', |
|
| 94 | + 'Tasmania' => 'Australia/Hobart', |
|
| 95 | + 'Vladivostok' => 'Asia/Vladivostok', |
|
| 96 | + 'West Pacific' => 'Pacific/Guam', |
|
| 97 | + 'Central Pacific' => 'Asia/Magadan', |
|
| 98 | + 'Fiji' => 'Pacific/Fiji', |
|
| 99 | + 'New Zealand' => 'Pacific/Auckland', |
|
| 100 | + 'Tonga' => 'Pacific/Tongatapu', |
|
| 101 | 101 | ]; |
@@ -12,83 +12,83 @@ |
||
| 12 | 12 | * @license http://sabre.io/license/ Modified BSD License |
| 13 | 13 | */ |
| 14 | 14 | return [ |
| 15 | - 'Universal Coordinated Time' => 'UTC', |
|
| 16 | - 'Casablanca, Monrovia' => 'Africa/Casablanca', |
|
| 17 | - 'Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London' => 'Europe/Lisbon', |
|
| 18 | - 'Greenwich Mean Time; Dublin, Edinburgh, London' => 'Europe/London', |
|
| 19 | - 'Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna' => 'Europe/Berlin', |
|
| 20 | - 'Belgrade, Pozsony, Budapest, Ljubljana, Prague' => 'Europe/Prague', |
|
| 21 | - 'Brussels, Copenhagen, Madrid, Paris' => 'Europe/Paris', |
|
| 22 | - 'Paris, Madrid, Brussels, Copenhagen' => 'Europe/Paris', |
|
| 23 | - 'Prague, Central Europe' => 'Europe/Prague', |
|
| 24 | - 'Sarajevo, Skopje, Sofija, Vilnius, Warsaw, Zagreb' => 'Europe/Sarajevo', |
|
| 25 | - 'West Central Africa' => 'Africa/Luanda', // This was a best guess |
|
| 26 | - 'Athens, Istanbul, Minsk' => 'Europe/Athens', |
|
| 27 | - 'Bucharest' => 'Europe/Bucharest', |
|
| 28 | - 'Cairo' => 'Africa/Cairo', |
|
| 29 | - 'Harare, Pretoria' => 'Africa/Harare', |
|
| 30 | - 'Helsinki, Riga, Tallinn' => 'Europe/Helsinki', |
|
| 31 | - 'Israel, Jerusalem Standard Time' => 'Asia/Jerusalem', |
|
| 32 | - 'Baghdad' => 'Asia/Baghdad', |
|
| 33 | - 'Arab, Kuwait, Riyadh' => 'Asia/Kuwait', |
|
| 34 | - 'Moscow, St. Petersburg, Volgograd' => 'Europe/Moscow', |
|
| 35 | - 'East Africa, Nairobi' => 'Africa/Nairobi', |
|
| 36 | - 'Tehran' => 'Asia/Tehran', |
|
| 37 | - 'Abu Dhabi, Muscat' => 'Asia/Muscat', // Best guess |
|
| 38 | - 'Baku, Tbilisi, Yerevan' => 'Asia/Baku', |
|
| 39 | - 'Kabul' => 'Asia/Kabul', |
|
| 40 | - 'Ekaterinburg' => 'Asia/Yekaterinburg', |
|
| 41 | - 'Islamabad, Karachi, Tashkent' => 'Asia/Karachi', |
|
| 42 | - 'Kolkata, Chennai, Mumbai, New Delhi, India Standard Time' => 'Asia/Calcutta', |
|
| 43 | - 'Kathmandu, Nepal' => 'Asia/Kathmandu', |
|
| 44 | - 'Almaty, Novosibirsk, North Central Asia' => 'Asia/Almaty', |
|
| 45 | - 'Astana, Dhaka' => 'Asia/Dhaka', |
|
| 46 | - 'Sri Jayawardenepura, Sri Lanka' => 'Asia/Colombo', |
|
| 47 | - 'Rangoon' => 'Asia/Rangoon', |
|
| 48 | - 'Bangkok, Hanoi, Jakarta' => 'Asia/Bangkok', |
|
| 49 | - 'Krasnoyarsk' => 'Asia/Krasnoyarsk', |
|
| 50 | - 'Beijing, Chongqing, Hong Kong SAR, Urumqi' => 'Asia/Shanghai', |
|
| 51 | - 'Irkutsk, Ulaan Bataar' => 'Asia/Irkutsk', |
|
| 52 | - 'Kuala Lumpur, Singapore' => 'Asia/Singapore', |
|
| 53 | - 'Perth, Western Australia' => 'Australia/Perth', |
|
| 54 | - 'Taipei' => 'Asia/Taipei', |
|
| 55 | - 'Osaka, Sapporo, Tokyo' => 'Asia/Tokyo', |
|
| 56 | - 'Seoul, Korea Standard time' => 'Asia/Seoul', |
|
| 57 | - 'Yakutsk' => 'Asia/Yakutsk', |
|
| 58 | - 'Adelaide, Central Australia' => 'Australia/Adelaide', |
|
| 59 | - 'Darwin' => 'Australia/Darwin', |
|
| 60 | - 'Brisbane, East Australia' => 'Australia/Brisbane', |
|
| 61 | - 'Canberra, Melbourne, Sydney, Hobart (year 2000 only)' => 'Australia/Sydney', |
|
| 62 | - 'Guam, Port Moresby' => 'Pacific/Guam', |
|
| 63 | - 'Hobart, Tasmania' => 'Australia/Hobart', |
|
| 64 | - 'Vladivostok' => 'Asia/Vladivostok', |
|
| 65 | - 'Magadan, Solomon Is., New Caledonia' => 'Asia/Magadan', |
|
| 66 | - 'Auckland, Wellington' => 'Pacific/Auckland', |
|
| 67 | - 'Fiji Islands, Kamchatka, Marshall Is.' => 'Pacific/Fiji', |
|
| 68 | - 'Nuku\'alofa, Tonga' => 'Pacific/Tongatapu', |
|
| 69 | - 'Azores' => 'Atlantic/Azores', |
|
| 70 | - 'Cape Verde Is.' => 'Atlantic/Cape_Verde', |
|
| 71 | - 'Mid-Atlantic' => 'America/Noronha', |
|
| 72 | - 'Brasilia' => 'America/Sao_Paulo', // Best guess |
|
| 73 | - 'Buenos Aires' => 'America/Argentina/Buenos_Aires', |
|
| 74 | - 'Greenland' => 'America/Godthab', |
|
| 75 | - 'Newfoundland' => 'America/St_Johns', |
|
| 76 | - 'Atlantic Time (Canada)' => 'America/Halifax', |
|
| 77 | - 'Caracas, La Paz' => 'America/Caracas', |
|
| 78 | - 'Santiago' => 'America/Santiago', |
|
| 79 | - 'Bogota, Lima, Quito' => 'America/Bogota', |
|
| 80 | - 'Eastern Time (US & Canada)' => 'America/New_York', |
|
| 81 | - 'Indiana (East)' => 'America/Indiana/Indianapolis', |
|
| 82 | - 'Central America' => 'America/Guatemala', |
|
| 83 | - 'Central Time (US & Canada)' => 'America/Chicago', |
|
| 84 | - 'Mexico City, Tegucigalpa' => 'America/Mexico_City', |
|
| 85 | - 'Saskatchewan' => 'America/Edmonton', |
|
| 86 | - 'Arizona' => 'America/Phoenix', |
|
| 87 | - 'Mountain Time (US & Canada)' => 'America/Denver', // Best guess |
|
| 88 | - 'Pacific Time (US & Canada)' => 'America/Los_Angeles', // Best guess |
|
| 89 | - 'Pacific Time (US & Canada); Tijuana' => 'America/Los_Angeles', // Best guess |
|
| 90 | - 'Alaska' => 'America/Anchorage', |
|
| 91 | - 'Hawaii' => 'Pacific/Honolulu', |
|
| 92 | - 'Midway Island, Samoa' => 'Pacific/Midway', |
|
| 93 | - 'Eniwetok, Kwajalein, Dateline Time' => 'Pacific/Kwajalein', |
|
| 15 | + 'Universal Coordinated Time' => 'UTC', |
|
| 16 | + 'Casablanca, Monrovia' => 'Africa/Casablanca', |
|
| 17 | + 'Greenwich Mean Time: Dublin, Edinburgh, Lisbon, London' => 'Europe/Lisbon', |
|
| 18 | + 'Greenwich Mean Time; Dublin, Edinburgh, London' => 'Europe/London', |
|
| 19 | + 'Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna' => 'Europe/Berlin', |
|
| 20 | + 'Belgrade, Pozsony, Budapest, Ljubljana, Prague' => 'Europe/Prague', |
|
| 21 | + 'Brussels, Copenhagen, Madrid, Paris' => 'Europe/Paris', |
|
| 22 | + 'Paris, Madrid, Brussels, Copenhagen' => 'Europe/Paris', |
|
| 23 | + 'Prague, Central Europe' => 'Europe/Prague', |
|
| 24 | + 'Sarajevo, Skopje, Sofija, Vilnius, Warsaw, Zagreb' => 'Europe/Sarajevo', |
|
| 25 | + 'West Central Africa' => 'Africa/Luanda', // This was a best guess |
|
| 26 | + 'Athens, Istanbul, Minsk' => 'Europe/Athens', |
|
| 27 | + 'Bucharest' => 'Europe/Bucharest', |
|
| 28 | + 'Cairo' => 'Africa/Cairo', |
|
| 29 | + 'Harare, Pretoria' => 'Africa/Harare', |
|
| 30 | + 'Helsinki, Riga, Tallinn' => 'Europe/Helsinki', |
|
| 31 | + 'Israel, Jerusalem Standard Time' => 'Asia/Jerusalem', |
|
| 32 | + 'Baghdad' => 'Asia/Baghdad', |
|
| 33 | + 'Arab, Kuwait, Riyadh' => 'Asia/Kuwait', |
|
| 34 | + 'Moscow, St. Petersburg, Volgograd' => 'Europe/Moscow', |
|
| 35 | + 'East Africa, Nairobi' => 'Africa/Nairobi', |
|
| 36 | + 'Tehran' => 'Asia/Tehran', |
|
| 37 | + 'Abu Dhabi, Muscat' => 'Asia/Muscat', // Best guess |
|
| 38 | + 'Baku, Tbilisi, Yerevan' => 'Asia/Baku', |
|
| 39 | + 'Kabul' => 'Asia/Kabul', |
|
| 40 | + 'Ekaterinburg' => 'Asia/Yekaterinburg', |
|
| 41 | + 'Islamabad, Karachi, Tashkent' => 'Asia/Karachi', |
|
| 42 | + 'Kolkata, Chennai, Mumbai, New Delhi, India Standard Time' => 'Asia/Calcutta', |
|
| 43 | + 'Kathmandu, Nepal' => 'Asia/Kathmandu', |
|
| 44 | + 'Almaty, Novosibirsk, North Central Asia' => 'Asia/Almaty', |
|
| 45 | + 'Astana, Dhaka' => 'Asia/Dhaka', |
|
| 46 | + 'Sri Jayawardenepura, Sri Lanka' => 'Asia/Colombo', |
|
| 47 | + 'Rangoon' => 'Asia/Rangoon', |
|
| 48 | + 'Bangkok, Hanoi, Jakarta' => 'Asia/Bangkok', |
|
| 49 | + 'Krasnoyarsk' => 'Asia/Krasnoyarsk', |
|
| 50 | + 'Beijing, Chongqing, Hong Kong SAR, Urumqi' => 'Asia/Shanghai', |
|
| 51 | + 'Irkutsk, Ulaan Bataar' => 'Asia/Irkutsk', |
|
| 52 | + 'Kuala Lumpur, Singapore' => 'Asia/Singapore', |
|
| 53 | + 'Perth, Western Australia' => 'Australia/Perth', |
|
| 54 | + 'Taipei' => 'Asia/Taipei', |
|
| 55 | + 'Osaka, Sapporo, Tokyo' => 'Asia/Tokyo', |
|
| 56 | + 'Seoul, Korea Standard time' => 'Asia/Seoul', |
|
| 57 | + 'Yakutsk' => 'Asia/Yakutsk', |
|
| 58 | + 'Adelaide, Central Australia' => 'Australia/Adelaide', |
|
| 59 | + 'Darwin' => 'Australia/Darwin', |
|
| 60 | + 'Brisbane, East Australia' => 'Australia/Brisbane', |
|
| 61 | + 'Canberra, Melbourne, Sydney, Hobart (year 2000 only)' => 'Australia/Sydney', |
|
| 62 | + 'Guam, Port Moresby' => 'Pacific/Guam', |
|
| 63 | + 'Hobart, Tasmania' => 'Australia/Hobart', |
|
| 64 | + 'Vladivostok' => 'Asia/Vladivostok', |
|
| 65 | + 'Magadan, Solomon Is., New Caledonia' => 'Asia/Magadan', |
|
| 66 | + 'Auckland, Wellington' => 'Pacific/Auckland', |
|
| 67 | + 'Fiji Islands, Kamchatka, Marshall Is.' => 'Pacific/Fiji', |
|
| 68 | + 'Nuku\'alofa, Tonga' => 'Pacific/Tongatapu', |
|
| 69 | + 'Azores' => 'Atlantic/Azores', |
|
| 70 | + 'Cape Verde Is.' => 'Atlantic/Cape_Verde', |
|
| 71 | + 'Mid-Atlantic' => 'America/Noronha', |
|
| 72 | + 'Brasilia' => 'America/Sao_Paulo', // Best guess |
|
| 73 | + 'Buenos Aires' => 'America/Argentina/Buenos_Aires', |
|
| 74 | + 'Greenland' => 'America/Godthab', |
|
| 75 | + 'Newfoundland' => 'America/St_Johns', |
|
| 76 | + 'Atlantic Time (Canada)' => 'America/Halifax', |
|
| 77 | + 'Caracas, La Paz' => 'America/Caracas', |
|
| 78 | + 'Santiago' => 'America/Santiago', |
|
| 79 | + 'Bogota, Lima, Quito' => 'America/Bogota', |
|
| 80 | + 'Eastern Time (US & Canada)' => 'America/New_York', |
|
| 81 | + 'Indiana (East)' => 'America/Indiana/Indianapolis', |
|
| 82 | + 'Central America' => 'America/Guatemala', |
|
| 83 | + 'Central Time (US & Canada)' => 'America/Chicago', |
|
| 84 | + 'Mexico City, Tegucigalpa' => 'America/Mexico_City', |
|
| 85 | + 'Saskatchewan' => 'America/Edmonton', |
|
| 86 | + 'Arizona' => 'America/Phoenix', |
|
| 87 | + 'Mountain Time (US & Canada)' => 'America/Denver', // Best guess |
|
| 88 | + 'Pacific Time (US & Canada)' => 'America/Los_Angeles', // Best guess |
|
| 89 | + 'Pacific Time (US & Canada); Tijuana' => 'America/Los_Angeles', // Best guess |
|
| 90 | + 'Alaska' => 'America/Anchorage', |
|
| 91 | + 'Hawaii' => 'Pacific/Honolulu', |
|
| 92 | + 'Midway Island, Samoa' => 'Pacific/Midway', |
|
| 93 | + 'Eniwetok, Kwajalein, Dateline Time' => 'Pacific/Kwajalein', |
|
| 94 | 94 | ]; |
@@ -15,32 +15,32 @@ |
||
| 15 | 15 | * @license http://sabre.io/license/ Modified BSD License |
| 16 | 16 | */ |
| 17 | 17 | return [ |
| 18 | - 'CST6CDT' => 'America/Chicago', |
|
| 19 | - 'Cuba' => 'America/Havana', |
|
| 20 | - 'Egypt' => 'Africa/Cairo', |
|
| 21 | - 'Eire' => 'Europe/Dublin', |
|
| 22 | - 'EST5EDT' => 'America/New_York', |
|
| 23 | - 'Factory' => 'UTC', |
|
| 24 | - 'GB-Eire' => 'Europe/London', |
|
| 25 | - 'GMT0' => 'UTC', |
|
| 26 | - 'Greenwich' => 'UTC', |
|
| 27 | - 'Hongkong' => 'Asia/Hong_Kong', |
|
| 28 | - 'Iceland' => 'Atlantic/Reykjavik', |
|
| 29 | - 'Iran' => 'Asia/Tehran', |
|
| 30 | - 'Israel' => 'Asia/Jerusalem', |
|
| 31 | - 'Jamaica' => 'America/Jamaica', |
|
| 32 | - 'Japan' => 'Asia/Tokyo', |
|
| 33 | - 'Kwajalein' => 'Pacific/Kwajalein', |
|
| 34 | - 'Libya' => 'Africa/Tripoli', |
|
| 35 | - 'MST7MDT' => 'America/Denver', |
|
| 36 | - 'Navajo' => 'America/Denver', |
|
| 37 | - 'NZ-CHAT' => 'Pacific/Chatham', |
|
| 38 | - 'Poland' => 'Europe/Warsaw', |
|
| 39 | - 'Portugal' => 'Europe/Lisbon', |
|
| 40 | - 'PST8PDT' => 'America/Los_Angeles', |
|
| 41 | - 'Singapore' => 'Asia/Singapore', |
|
| 42 | - 'Turkey' => 'Europe/Istanbul', |
|
| 43 | - 'Universal' => 'UTC', |
|
| 44 | - 'W-SU' => 'Europe/Moscow', |
|
| 45 | - 'Zulu' => 'UTC', |
|
| 18 | + 'CST6CDT' => 'America/Chicago', |
|
| 19 | + 'Cuba' => 'America/Havana', |
|
| 20 | + 'Egypt' => 'Africa/Cairo', |
|
| 21 | + 'Eire' => 'Europe/Dublin', |
|
| 22 | + 'EST5EDT' => 'America/New_York', |
|
| 23 | + 'Factory' => 'UTC', |
|
| 24 | + 'GB-Eire' => 'Europe/London', |
|
| 25 | + 'GMT0' => 'UTC', |
|
| 26 | + 'Greenwich' => 'UTC', |
|
| 27 | + 'Hongkong' => 'Asia/Hong_Kong', |
|
| 28 | + 'Iceland' => 'Atlantic/Reykjavik', |
|
| 29 | + 'Iran' => 'Asia/Tehran', |
|
| 30 | + 'Israel' => 'Asia/Jerusalem', |
|
| 31 | + 'Jamaica' => 'America/Jamaica', |
|
| 32 | + 'Japan' => 'Asia/Tokyo', |
|
| 33 | + 'Kwajalein' => 'Pacific/Kwajalein', |
|
| 34 | + 'Libya' => 'Africa/Tripoli', |
|
| 35 | + 'MST7MDT' => 'America/Denver', |
|
| 36 | + 'Navajo' => 'America/Denver', |
|
| 37 | + 'NZ-CHAT' => 'Pacific/Chatham', |
|
| 38 | + 'Poland' => 'Europe/Warsaw', |
|
| 39 | + 'Portugal' => 'Europe/Lisbon', |
|
| 40 | + 'PST8PDT' => 'America/Los_Angeles', |
|
| 41 | + 'Singapore' => 'Asia/Singapore', |
|
| 42 | + 'Turkey' => 'Europe/Istanbul', |
|
| 43 | + 'Universal' => 'UTC', |
|
| 44 | + 'W-SU' => 'Europe/Moscow', |
|
| 45 | + 'Zulu' => 'UTC', |
|
| 46 | 46 | ]; |
@@ -16,137 +16,137 @@ |
||
| 16 | 16 | * @license http://sabre.io/license/ Modified BSD License |
| 17 | 17 | */ |
| 18 | 18 | return [ |
| 19 | - 'Africa/Asmera', |
|
| 20 | - 'Africa/Timbuktu', |
|
| 21 | - 'America/Argentina/ComodRivadavia', |
|
| 22 | - 'America/Atka', |
|
| 23 | - 'America/Buenos_Aires', |
|
| 24 | - 'America/Catamarca', |
|
| 25 | - 'America/Coral_Harbour', |
|
| 26 | - 'America/Cordoba', |
|
| 27 | - 'America/Ensenada', |
|
| 28 | - 'America/Fort_Wayne', |
|
| 29 | - 'America/Indianapolis', |
|
| 30 | - 'America/Jujuy', |
|
| 31 | - 'America/Knox_IN', |
|
| 32 | - 'America/Louisville', |
|
| 33 | - 'America/Mendoza', |
|
| 34 | - 'America/Montreal', |
|
| 35 | - 'America/Porto_Acre', |
|
| 36 | - 'America/Rosario', |
|
| 37 | - 'America/Shiprock', |
|
| 38 | - 'America/Virgin', |
|
| 39 | - 'Antarctica/South_Pole', |
|
| 40 | - 'Asia/Ashkhabad', |
|
| 41 | - 'Asia/Calcutta', |
|
| 42 | - 'Asia/Chungking', |
|
| 43 | - 'Asia/Dacca', |
|
| 44 | - 'Asia/Istanbul', |
|
| 45 | - 'Asia/Katmandu', |
|
| 46 | - 'Asia/Macao', |
|
| 47 | - 'Asia/Saigon', |
|
| 48 | - 'Asia/Tel_Aviv', |
|
| 49 | - 'Asia/Thimbu', |
|
| 50 | - 'Asia/Ujung_Pandang', |
|
| 51 | - 'Asia/Ulan_Bator', |
|
| 52 | - 'Atlantic/Faeroe', |
|
| 53 | - 'Atlantic/Jan_Mayen', |
|
| 54 | - 'Australia/ACT', |
|
| 55 | - 'Australia/Canberra', |
|
| 56 | - 'Australia/LHI', |
|
| 57 | - 'Australia/North', |
|
| 58 | - 'Australia/NSW', |
|
| 59 | - 'Australia/Queensland', |
|
| 60 | - 'Australia/South', |
|
| 61 | - 'Australia/Tasmania', |
|
| 62 | - 'Australia/Victoria', |
|
| 63 | - 'Australia/West', |
|
| 64 | - 'Australia/Yancowinna', |
|
| 65 | - 'Brazil/Acre', |
|
| 66 | - 'Brazil/DeNoronha', |
|
| 67 | - 'Brazil/East', |
|
| 68 | - 'Brazil/West', |
|
| 69 | - 'Canada/Atlantic', |
|
| 70 | - 'Canada/Central', |
|
| 71 | - 'Canada/Eastern', |
|
| 72 | - 'Canada/Mountain', |
|
| 73 | - 'Canada/Newfoundland', |
|
| 74 | - 'Canada/Pacific', |
|
| 75 | - 'Canada/Saskatchewan', |
|
| 76 | - 'Canada/Yukon', |
|
| 77 | - 'CET', |
|
| 78 | - 'Chile/Continental', |
|
| 79 | - 'Chile/EasterIsland', |
|
| 80 | - 'EET', |
|
| 81 | - 'EST', |
|
| 82 | - 'Etc/GMT', |
|
| 83 | - 'Etc/GMT+0', |
|
| 84 | - 'Etc/GMT+1', |
|
| 85 | - 'Etc/GMT+10', |
|
| 86 | - 'Etc/GMT+11', |
|
| 87 | - 'Etc/GMT+12', |
|
| 88 | - 'Etc/GMT+2', |
|
| 89 | - 'Etc/GMT+3', |
|
| 90 | - 'Etc/GMT+4', |
|
| 91 | - 'Etc/GMT+5', |
|
| 92 | - 'Etc/GMT+6', |
|
| 93 | - 'Etc/GMT+7', |
|
| 94 | - 'Etc/GMT+8', |
|
| 95 | - 'Etc/GMT+9', |
|
| 96 | - 'Etc/GMT-0', |
|
| 97 | - 'Etc/GMT-1', |
|
| 98 | - 'Etc/GMT-10', |
|
| 99 | - 'Etc/GMT-11', |
|
| 100 | - 'Etc/GMT-12', |
|
| 101 | - 'Etc/GMT-13', |
|
| 102 | - 'Etc/GMT-14', |
|
| 103 | - 'Etc/GMT-2', |
|
| 104 | - 'Etc/GMT-3', |
|
| 105 | - 'Etc/GMT-4', |
|
| 106 | - 'Etc/GMT-5', |
|
| 107 | - 'Etc/GMT-6', |
|
| 108 | - 'Etc/GMT-7', |
|
| 109 | - 'Etc/GMT-8', |
|
| 110 | - 'Etc/GMT-9', |
|
| 111 | - 'Etc/GMT0', |
|
| 112 | - 'Etc/Greenwich', |
|
| 113 | - 'Etc/UCT', |
|
| 114 | - 'Etc/Universal', |
|
| 115 | - 'Etc/UTC', |
|
| 116 | - 'Etc/Zulu', |
|
| 117 | - 'Europe/Belfast', |
|
| 118 | - 'Europe/Nicosia', |
|
| 119 | - 'Europe/Tiraspol', |
|
| 120 | - 'GB', |
|
| 121 | - 'GMT', |
|
| 122 | - 'GMT+0', |
|
| 123 | - 'GMT-0', |
|
| 124 | - 'HST', |
|
| 125 | - 'MET', |
|
| 126 | - 'Mexico/BajaNorte', |
|
| 127 | - 'Mexico/BajaSur', |
|
| 128 | - 'Mexico/General', |
|
| 129 | - 'MST', |
|
| 130 | - 'NZ', |
|
| 131 | - 'Pacific/Ponape', |
|
| 132 | - 'Pacific/Samoa', |
|
| 133 | - 'Pacific/Truk', |
|
| 134 | - 'Pacific/Yap', |
|
| 135 | - 'PRC', |
|
| 136 | - 'ROC', |
|
| 137 | - 'ROK', |
|
| 138 | - 'UCT', |
|
| 139 | - 'US/Alaska', |
|
| 140 | - 'US/Aleutian', |
|
| 141 | - 'US/Arizona', |
|
| 142 | - 'US/Central', |
|
| 143 | - 'US/East-Indiana', |
|
| 144 | - 'US/Eastern', |
|
| 145 | - 'US/Hawaii', |
|
| 146 | - 'US/Indiana-Starke', |
|
| 147 | - 'US/Michigan', |
|
| 148 | - 'US/Mountain', |
|
| 149 | - 'US/Pacific', |
|
| 150 | - 'US/Samoa', |
|
| 151 | - 'WET', |
|
| 19 | + 'Africa/Asmera', |
|
| 20 | + 'Africa/Timbuktu', |
|
| 21 | + 'America/Argentina/ComodRivadavia', |
|
| 22 | + 'America/Atka', |
|
| 23 | + 'America/Buenos_Aires', |
|
| 24 | + 'America/Catamarca', |
|
| 25 | + 'America/Coral_Harbour', |
|
| 26 | + 'America/Cordoba', |
|
| 27 | + 'America/Ensenada', |
|
| 28 | + 'America/Fort_Wayne', |
|
| 29 | + 'America/Indianapolis', |
|
| 30 | + 'America/Jujuy', |
|
| 31 | + 'America/Knox_IN', |
|
| 32 | + 'America/Louisville', |
|
| 33 | + 'America/Mendoza', |
|
| 34 | + 'America/Montreal', |
|
| 35 | + 'America/Porto_Acre', |
|
| 36 | + 'America/Rosario', |
|
| 37 | + 'America/Shiprock', |
|
| 38 | + 'America/Virgin', |
|
| 39 | + 'Antarctica/South_Pole', |
|
| 40 | + 'Asia/Ashkhabad', |
|
| 41 | + 'Asia/Calcutta', |
|
| 42 | + 'Asia/Chungking', |
|
| 43 | + 'Asia/Dacca', |
|
| 44 | + 'Asia/Istanbul', |
|
| 45 | + 'Asia/Katmandu', |
|
| 46 | + 'Asia/Macao', |
|
| 47 | + 'Asia/Saigon', |
|
| 48 | + 'Asia/Tel_Aviv', |
|
| 49 | + 'Asia/Thimbu', |
|
| 50 | + 'Asia/Ujung_Pandang', |
|
| 51 | + 'Asia/Ulan_Bator', |
|
| 52 | + 'Atlantic/Faeroe', |
|
| 53 | + 'Atlantic/Jan_Mayen', |
|
| 54 | + 'Australia/ACT', |
|
| 55 | + 'Australia/Canberra', |
|
| 56 | + 'Australia/LHI', |
|
| 57 | + 'Australia/North', |
|
| 58 | + 'Australia/NSW', |
|
| 59 | + 'Australia/Queensland', |
|
| 60 | + 'Australia/South', |
|
| 61 | + 'Australia/Tasmania', |
|
| 62 | + 'Australia/Victoria', |
|
| 63 | + 'Australia/West', |
|
| 64 | + 'Australia/Yancowinna', |
|
| 65 | + 'Brazil/Acre', |
|
| 66 | + 'Brazil/DeNoronha', |
|
| 67 | + 'Brazil/East', |
|
| 68 | + 'Brazil/West', |
|
| 69 | + 'Canada/Atlantic', |
|
| 70 | + 'Canada/Central', |
|
| 71 | + 'Canada/Eastern', |
|
| 72 | + 'Canada/Mountain', |
|
| 73 | + 'Canada/Newfoundland', |
|
| 74 | + 'Canada/Pacific', |
|
| 75 | + 'Canada/Saskatchewan', |
|
| 76 | + 'Canada/Yukon', |
|
| 77 | + 'CET', |
|
| 78 | + 'Chile/Continental', |
|
| 79 | + 'Chile/EasterIsland', |
|
| 80 | + 'EET', |
|
| 81 | + 'EST', |
|
| 82 | + 'Etc/GMT', |
|
| 83 | + 'Etc/GMT+0', |
|
| 84 | + 'Etc/GMT+1', |
|
| 85 | + 'Etc/GMT+10', |
|
| 86 | + 'Etc/GMT+11', |
|
| 87 | + 'Etc/GMT+12', |
|
| 88 | + 'Etc/GMT+2', |
|
| 89 | + 'Etc/GMT+3', |
|
| 90 | + 'Etc/GMT+4', |
|
| 91 | + 'Etc/GMT+5', |
|
| 92 | + 'Etc/GMT+6', |
|
| 93 | + 'Etc/GMT+7', |
|
| 94 | + 'Etc/GMT+8', |
|
| 95 | + 'Etc/GMT+9', |
|
| 96 | + 'Etc/GMT-0', |
|
| 97 | + 'Etc/GMT-1', |
|
| 98 | + 'Etc/GMT-10', |
|
| 99 | + 'Etc/GMT-11', |
|
| 100 | + 'Etc/GMT-12', |
|
| 101 | + 'Etc/GMT-13', |
|
| 102 | + 'Etc/GMT-14', |
|
| 103 | + 'Etc/GMT-2', |
|
| 104 | + 'Etc/GMT-3', |
|
| 105 | + 'Etc/GMT-4', |
|
| 106 | + 'Etc/GMT-5', |
|
| 107 | + 'Etc/GMT-6', |
|
| 108 | + 'Etc/GMT-7', |
|
| 109 | + 'Etc/GMT-8', |
|
| 110 | + 'Etc/GMT-9', |
|
| 111 | + 'Etc/GMT0', |
|
| 112 | + 'Etc/Greenwich', |
|
| 113 | + 'Etc/UCT', |
|
| 114 | + 'Etc/Universal', |
|
| 115 | + 'Etc/UTC', |
|
| 116 | + 'Etc/Zulu', |
|
| 117 | + 'Europe/Belfast', |
|
| 118 | + 'Europe/Nicosia', |
|
| 119 | + 'Europe/Tiraspol', |
|
| 120 | + 'GB', |
|
| 121 | + 'GMT', |
|
| 122 | + 'GMT+0', |
|
| 123 | + 'GMT-0', |
|
| 124 | + 'HST', |
|
| 125 | + 'MET', |
|
| 126 | + 'Mexico/BajaNorte', |
|
| 127 | + 'Mexico/BajaSur', |
|
| 128 | + 'Mexico/General', |
|
| 129 | + 'MST', |
|
| 130 | + 'NZ', |
|
| 131 | + 'Pacific/Ponape', |
|
| 132 | + 'Pacific/Samoa', |
|
| 133 | + 'Pacific/Truk', |
|
| 134 | + 'Pacific/Yap', |
|
| 135 | + 'PRC', |
|
| 136 | + 'ROC', |
|
| 137 | + 'ROK', |
|
| 138 | + 'UCT', |
|
| 139 | + 'US/Alaska', |
|
| 140 | + 'US/Aleutian', |
|
| 141 | + 'US/Arizona', |
|
| 142 | + 'US/Central', |
|
| 143 | + 'US/East-Indiana', |
|
| 144 | + 'US/Eastern', |
|
| 145 | + 'US/Hawaii', |
|
| 146 | + 'US/Indiana-Starke', |
|
| 147 | + 'US/Michigan', |
|
| 148 | + 'US/Mountain', |
|
| 149 | + 'US/Pacific', |
|
| 150 | + 'US/Samoa', |
|
| 151 | + 'WET', |
|
| 152 | 152 | ]; |
@@ -14,62 +14,62 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | trait PHPUnitAssertions |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * This method tests whether two vcards or icalendar objects are |
|
| 19 | - * semantically identical. |
|
| 20 | - * |
|
| 21 | - * It supports objects being supplied as strings, streams or |
|
| 22 | - * Sabre\VObject\Component instances. |
|
| 23 | - * |
|
| 24 | - * PRODID is removed from both objects as this is often changes and would |
|
| 25 | - * just get in the way. |
|
| 26 | - * |
|
| 27 | - * CALSCALE will automatically get removed if it's set to GREGORIAN. |
|
| 28 | - * |
|
| 29 | - * Any property that has the value **ANY** will be treated as a wildcard. |
|
| 30 | - * |
|
| 31 | - * @param resource|string|Component $expected |
|
| 32 | - * @param resource|string|Component $actual |
|
| 33 | - * @param string $message |
|
| 34 | - */ |
|
| 35 | - public function assertVObjectEqualsVObject($expected, $actual, $message = '') |
|
| 36 | - { |
|
| 37 | - $getObj = function ($input) { |
|
| 38 | - if (is_resource($input)) { |
|
| 39 | - $input = stream_get_contents($input); |
|
| 40 | - } |
|
| 41 | - if (is_string($input)) { |
|
| 42 | - $input = Reader::read($input); |
|
| 43 | - } |
|
| 44 | - if (!$input instanceof Component) { |
|
| 45 | - $this->fail('Input must be a string, stream or VObject component'); |
|
| 46 | - } |
|
| 47 | - unset($input->PRODID); |
|
| 48 | - if ($input instanceof Component\VCalendar && 'GREGORIAN' === (string) $input->CALSCALE) { |
|
| 49 | - unset($input->CALSCALE); |
|
| 50 | - } |
|
| 17 | + /** |
|
| 18 | + * This method tests whether two vcards or icalendar objects are |
|
| 19 | + * semantically identical. |
|
| 20 | + * |
|
| 21 | + * It supports objects being supplied as strings, streams or |
|
| 22 | + * Sabre\VObject\Component instances. |
|
| 23 | + * |
|
| 24 | + * PRODID is removed from both objects as this is often changes and would |
|
| 25 | + * just get in the way. |
|
| 26 | + * |
|
| 27 | + * CALSCALE will automatically get removed if it's set to GREGORIAN. |
|
| 28 | + * |
|
| 29 | + * Any property that has the value **ANY** will be treated as a wildcard. |
|
| 30 | + * |
|
| 31 | + * @param resource|string|Component $expected |
|
| 32 | + * @param resource|string|Component $actual |
|
| 33 | + * @param string $message |
|
| 34 | + */ |
|
| 35 | + public function assertVObjectEqualsVObject($expected, $actual, $message = '') |
|
| 36 | + { |
|
| 37 | + $getObj = function ($input) { |
|
| 38 | + if (is_resource($input)) { |
|
| 39 | + $input = stream_get_contents($input); |
|
| 40 | + } |
|
| 41 | + if (is_string($input)) { |
|
| 42 | + $input = Reader::read($input); |
|
| 43 | + } |
|
| 44 | + if (!$input instanceof Component) { |
|
| 45 | + $this->fail('Input must be a string, stream or VObject component'); |
|
| 46 | + } |
|
| 47 | + unset($input->PRODID); |
|
| 48 | + if ($input instanceof Component\VCalendar && 'GREGORIAN' === (string) $input->CALSCALE) { |
|
| 49 | + unset($input->CALSCALE); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - return $input; |
|
| 53 | - }; |
|
| 52 | + return $input; |
|
| 53 | + }; |
|
| 54 | 54 | |
| 55 | - $expected = $getObj($expected)->serialize(); |
|
| 56 | - $actual = $getObj($actual)->serialize(); |
|
| 55 | + $expected = $getObj($expected)->serialize(); |
|
| 56 | + $actual = $getObj($actual)->serialize(); |
|
| 57 | 57 | |
| 58 | - // Finding wildcards in expected. |
|
| 59 | - preg_match_all('|^([A-Z]+):\\*\\*ANY\\*\\*\r$|m', $expected, $matches, PREG_SET_ORDER); |
|
| 58 | + // Finding wildcards in expected. |
|
| 59 | + preg_match_all('|^([A-Z]+):\\*\\*ANY\\*\\*\r$|m', $expected, $matches, PREG_SET_ORDER); |
|
| 60 | 60 | |
| 61 | - foreach ($matches as $match) { |
|
| 62 | - $actual = preg_replace( |
|
| 63 | - '|^'.preg_quote($match[1], '|').':(.*)\r$|m', |
|
| 64 | - $match[1].':**ANY**'."\r", |
|
| 65 | - $actual |
|
| 66 | - ); |
|
| 67 | - } |
|
| 61 | + foreach ($matches as $match) { |
|
| 62 | + $actual = preg_replace( |
|
| 63 | + '|^'.preg_quote($match[1], '|').':(.*)\r$|m', |
|
| 64 | + $match[1].':**ANY**'."\r", |
|
| 65 | + $actual |
|
| 66 | + ); |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - $this->assertEquals( |
|
| 70 | - $expected, |
|
| 71 | - $actual, |
|
| 72 | - $message |
|
| 73 | - ); |
|
| 74 | - } |
|
| 69 | + $this->assertEquals( |
|
| 70 | + $expected, |
|
| 71 | + $actual, |
|
| 72 | + $message |
|
| 73 | + ); |
|
| 74 | + } |
|
| 75 | 75 | } |
@@ -21,54 +21,54 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class VCard implements SplitterInterface |
| 23 | 23 | { |
| 24 | - /** |
|
| 25 | - * File handle. |
|
| 26 | - * |
|
| 27 | - * @var resource |
|
| 28 | - */ |
|
| 29 | - protected $input; |
|
| 24 | + /** |
|
| 25 | + * File handle. |
|
| 26 | + * |
|
| 27 | + * @var resource |
|
| 28 | + */ |
|
| 29 | + protected $input; |
|
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * Persistent parser. |
|
| 33 | - * |
|
| 34 | - * @var MimeDir |
|
| 35 | - */ |
|
| 36 | - protected $parser; |
|
| 31 | + /** |
|
| 32 | + * Persistent parser. |
|
| 33 | + * |
|
| 34 | + * @var MimeDir |
|
| 35 | + */ |
|
| 36 | + protected $parser; |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Constructor. |
|
| 40 | - * |
|
| 41 | - * The splitter should receive an readable file stream as its input. |
|
| 42 | - * |
|
| 43 | - * @param resource $input |
|
| 44 | - * @param int $options parser options, see the OPTIONS constants |
|
| 45 | - */ |
|
| 46 | - public function __construct($input, $options = 0) |
|
| 47 | - { |
|
| 48 | - $this->input = $input; |
|
| 49 | - $this->parser = new MimeDir($input, $options); |
|
| 50 | - } |
|
| 38 | + /** |
|
| 39 | + * Constructor. |
|
| 40 | + * |
|
| 41 | + * The splitter should receive an readable file stream as its input. |
|
| 42 | + * |
|
| 43 | + * @param resource $input |
|
| 44 | + * @param int $options parser options, see the OPTIONS constants |
|
| 45 | + */ |
|
| 46 | + public function __construct($input, $options = 0) |
|
| 47 | + { |
|
| 48 | + $this->input = $input; |
|
| 49 | + $this->parser = new MimeDir($input, $options); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Every time getNext() is called, a new object will be parsed, until we |
|
| 54 | - * hit the end of the stream. |
|
| 55 | - * |
|
| 56 | - * When the end is reached, null will be returned. |
|
| 57 | - * |
|
| 58 | - * @return \Sabre\VObject\Component|null |
|
| 59 | - */ |
|
| 60 | - public function getNext() |
|
| 61 | - { |
|
| 62 | - try { |
|
| 63 | - $object = $this->parser->parse(); |
|
| 52 | + /** |
|
| 53 | + * Every time getNext() is called, a new object will be parsed, until we |
|
| 54 | + * hit the end of the stream. |
|
| 55 | + * |
|
| 56 | + * When the end is reached, null will be returned. |
|
| 57 | + * |
|
| 58 | + * @return \Sabre\VObject\Component|null |
|
| 59 | + */ |
|
| 60 | + public function getNext() |
|
| 61 | + { |
|
| 62 | + try { |
|
| 63 | + $object = $this->parser->parse(); |
|
| 64 | 64 | |
| 65 | - if (!$object instanceof VObject\Component\VCard) { |
|
| 66 | - throw new VObject\ParseException('The supplied input contained non-VCARD data.'); |
|
| 67 | - } |
|
| 68 | - } catch (VObject\EofException $e) { |
|
| 69 | - return; |
|
| 70 | - } |
|
| 65 | + if (!$object instanceof VObject\Component\VCard) { |
|
| 66 | + throw new VObject\ParseException('The supplied input contained non-VCARD data.'); |
|
| 67 | + } |
|
| 68 | + } catch (VObject\EofException $e) { |
|
| 69 | + return; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - return $object; |
|
| 73 | - } |
|
| 72 | + return $object; |
|
| 73 | + } |
|
| 74 | 74 | } |