From b2a6c01e9c089855cd65c96fe9a3c98b8f6f8a2b Mon Sep 17 00:00:00 2001 From: s0600204 Date: Tue, 2 Jul 2019 23:50:21 +0100 Subject: [PATCH] Remove $useTimeZoneWithRRules class attribute The reasoning behind why this exists does not appear to be explained anywhere. Besides, I don't think it's needed. It's certainly not tested to make sure it works as intended. --- README.md | 3 +- examples/index.php | 1 - src/ICal/ICal.php | 113 +++++++------------------------------ tests/RecurrencesTest.php | 2 - tests/SingleEventsTest.php | 1 - 5 files changed, 22 insertions(+), 98 deletions(-) diff --git a/README.md b/README.md index 229c69e..59e0535 100644 --- a/README.md +++ b/README.md @@ -134,7 +134,6 @@ need to be evaluated before non-fitting events can be dropped. | `$shouldFilterByWindow` | :heavy_multiplication_x: | `false` | `true` if either `$filterDaysBefore` or `$filterDaysAfter` are set | | `$skipRecurrence` | :ballot_box_with_check: | `false` | Toggles whether to skip the parsing of recurrence rules | | `$todoCount` | :heavy_multiplication_x: | N/A | Tracks the number of todos in the current iCal feed | -| `$useTimeZoneWithRRules` | :ballot_box_with_check: | `false` | Toggles whether to use time zone info when parsing recurrence rules | | `$windowMaxTimestamp` | :heavy_multiplication_x: | `null` | If `$filterDaysBefore` or `$filterDaysAfter` are set then the events are filtered according to the window defined by this field and `$windowMinTimestamp` | | `$windowMinTimestamp` | :heavy_multiplication_x: | `null` | If `$filterDaysBefore` or `$filterDaysAfter` are set then the events are filtered according to the window defined by this field and `$windowMaxTimestamp` | @@ -163,7 +162,7 @@ need to be evaluated before non-fitting events can be dropped. | `iCalDateToUnixTimestamp` | `$icalDate` | `public` | Returns a Unix timestamp from an iCal date time format | | `iCalDateWithTimeZone` | `$event`, `$key`, `$format = DATE_TIME_FORMAT` | `public` | Returns a date adapted to the calendar time zone depending on the event `TZID` | | `doesEventStartOutsideWindow` | `$event` | `protected` | Determines whether the event start date is outside `$windowMinTimestamp` / `$windowMaxTimestamp` | -| `isExdateMatch` | `$exdate`, `$anEvent`, `$recurringOffset` | `protected` | Checks if an excluded date matches a given date by reconciling time zones | +| `isExdateMatch` | `$exdate`, `$anEvent` | `protected` | Checks if an excluded date matches a given date by reconciling time zones | | `isFileOrUrl` | `$filename` | `protected` | Checks if a filename exists as a file or URL | | `isOutOfRange` | `$calendarDate`, `$minTimestamp`, `$maxTimestamp` | `protected` | Determines whether a valid iCalendar date is within a given range | | `isValidCldrTimeZoneId` | `$timeZone` | `protected` | Checks if a time zone is a valid CLDR time zone | diff --git a/examples/index.php b/examples/index.php index f2854dd..62860f9 100644 --- a/examples/index.php +++ b/examples/index.php @@ -14,7 +14,6 @@ 'filterDaysAfter' => null, // Default value 'filterDaysBefore' => null, // Default value 'skipRecurrence' => false, // Default value - 'useTimeZoneWithRRules' => false, // Default value )); // $ical->initFile('ICal.ics'); // $ical->initUrl('https://raw.githubusercontent.com/u01jmg3/ics-parser/master/examples/ICal.ics', $username = null, $password = null, $userAgent = null); diff --git a/src/ICal/ICal.php b/src/ICal/ICal.php index 8b1ca7e..4e392ed 100644 --- a/src/ICal/ICal.php +++ b/src/ICal/ICal.php @@ -84,13 +84,6 @@ class ICal */ public $skipRecurrence = false; - /** - * Toggles whether to use time zone info when parsing recurrence rules - * - * @var boolean - */ - public $useTimeZoneWithRRules = false; - /** * Toggles whether to disable all character replacement. * @@ -248,7 +241,6 @@ class ICal 'filterDaysAfter', 'filterDaysBefore', 'skipRecurrence', - 'useTimeZoneWithRRules', ); /** @@ -1431,15 +1423,6 @@ protected function processRecurrences() while ($recurringTimestamp <= $until) { $dayRecurringTimestamp = $recurringTimestamp; - // Adjust time zone from initial event - $dayRecurringOffset = 0; - if ($this->useTimeZoneWithRRules) { - $recurringTimeZone = \DateTime::createFromFormat(self::UNIX_FORMAT, $dayRecurringTimestamp); - $recurringTimeZone->setTimezone($initialStart->getTimezone()); - $dayRecurringOffset = $recurringTimeZone->getOffset(); - $dayRecurringTimestamp += $dayRecurringOffset; - } - // Add event $anEvent['DTSTART'] = date(self::DATE_TIME_FORMAT, $dayRecurringTimestamp) . (($initialStartTimeZoneName === 'Z') ? 'Z' : ''); $anEvent['DTSTART_array'][1] = $anEvent['DTSTART']; @@ -1453,8 +1436,8 @@ protected function processRecurrences() $anEvent['DTEND_array'][1] = $anEvent['DTEND']; // Exclusions - $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent, $dayRecurringOffset) { - return self::isExdateMatch($exdate, $anEvent, $dayRecurringOffset); + $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent) { + return self::isExdateMatch($exdate, $anEvent); }); if (isset($anEvent['UID'])) { @@ -1523,15 +1506,6 @@ protected function processRecurrences() while ($weekRecurringTimestamp <= $until) { $dayRecurringTimestamp = $weekRecurringTimestamp; - // Adjust time zone from initial event - $dayRecurringOffset = 0; - if ($this->useTimeZoneWithRRules) { - $dayRecurringTimeZone = \DateTime::createFromFormat(self::UNIX_FORMAT, $dayRecurringTimestamp); - $dayRecurringTimeZone->setTimezone($initialStart->getTimezone()); - $dayRecurringOffset = $dayRecurringTimeZone->getOffset(); - $dayRecurringTimestamp += $dayRecurringOffset; - } - foreach ($weekdays as $day) { // Check if day should be added if (in_array($day, $byDays) && $dayRecurringTimestamp > $startTimestamp @@ -1550,8 +1524,8 @@ protected function processRecurrences() $anEvent['DTEND_array'][1] = $anEvent['DTEND']; // Exclusions - $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent, $dayRecurringOffset) { - return self::isExdateMatch($exdate, $anEvent, $dayRecurringOffset); + $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent) { + return self::isExdateMatch($exdate, $anEvent); }); if (isset($anEvent['UID'])) { @@ -1640,15 +1614,6 @@ protected function processRecurrences() $monthRecurringTimestamp = $monthRecurringDateTime->getTimestamp(); } - // Adjust time zone from initial event - $monthRecurringOffset = 0; - if ($this->useTimeZoneWithRRules) { - $recurringTimeZone = \DateTime::createFromFormat(self::UNIX_FORMAT, $monthRecurringTimestamp); - $recurringTimeZone->setTimezone($initialStart->getTimezone()); - $monthRecurringOffset = $recurringTimeZone->getOffset(); - $monthRecurringTimestamp += $monthRecurringOffset; - } - if (($monthRecurringTimestamp > $startTimestamp) && ($monthRecurringTimestamp <= $until)) { // Add event $anEvent['DTSTART'] = date( @@ -1666,8 +1631,8 @@ protected function processRecurrences() $anEvent['DTEND_array'][1] = $anEvent['DTEND']; // Exclusions - $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent, $monthRecurringOffset) { - return self::isExdateMatch($exdate, $anEvent, $monthRecurringOffset); + $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent) { + return self::isExdateMatch($exdate, $anEvent); }); if (isset($anEvent['UID'])) { @@ -1709,16 +1674,6 @@ protected function processRecurrences() while ($recurringTimestamp <= $until) { $monthRecurringTimestamp = $recurringTimestamp; - // Adjust time zone from initial event - $monthRecurringOffset = 0; - - if ($this->useTimeZoneWithRRules) { - $recurringTimeZone = \DateTime::createFromFormat(self::UNIX_FORMAT, $monthRecurringTimestamp); - $recurringTimeZone->setTimezone($initialStart->getTimezone()); - $monthRecurringOffset = $recurringTimeZone->getOffset(); - $monthRecurringTimestamp += $monthRecurringOffset; - } - $eventStartDesc = "{$this->convertDayOrdinalToPositive($dayNumber, $weekday, $monthRecurringTimestamp)} {$this->weekdays[$weekday]} " . date(self::DATE_TIME_FORMAT_PRETTY, $monthRecurringTimestamp); $eventStartTimestamp = strtotime($eventStartDesc); @@ -1758,8 +1713,8 @@ protected function processRecurrences() $anEvent['DTEND_array'][1] = $anEvent['DTEND']; // Exclusions - $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent, $monthRecurringOffset) { - return self::isExdateMatch($exdate, $anEvent, $monthRecurringOffset); + $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent) { + return self::isExdateMatch($exdate, $anEvent); }); if (isset($anEvent['UID'])) { @@ -1829,16 +1784,6 @@ protected function processRecurrences() while ($recurringTimestamp <= $until) { $yearRecurringTimestamp = $recurringTimestamp; - // Adjust time zone from initial event - $yearRecurringOffset = 0; - - if ($this->useTimeZoneWithRRules) { - $recurringTimeZone = \DateTime::createFromFormat(self::UNIX_FORMAT, $yearRecurringTimestamp); - $recurringTimeZone->setTimezone($initialStart->getTimezone()); - $yearRecurringOffset = $recurringTimeZone->getOffset(); - $yearRecurringTimestamp += $yearRecurringOffset; - } - foreach ($bymonths as $bymonth) { $eventStartDesc = "{$this->convertDayOrdinalToPositive($dayNumber, $weekday, $yearRecurringTimestamp)} {$this->weekdays[$weekday]}" . " {$this->monthNames[$bymonth]} " @@ -1871,8 +1816,8 @@ protected function processRecurrences() $anEvent['DTEND_array'][1] = $anEvent['DTEND']; // Exclusions - $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent, $yearRecurringOffset) { - return self::isExdateMatch($exdate, $anEvent, $yearRecurringOffset); + $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent) { + return self::isExdateMatch($exdate, $anEvent); }); if (isset($anEvent['UID'])) { @@ -1920,15 +1865,6 @@ protected function processRecurrences() while ($recurringTimestamp <= $until) { $yearRecurringTimestamp = $recurringTimestamp; - // Adjust time zone from initial event - $yearRecurringOffset = 0; - if ($this->useTimeZoneWithRRules) { - $recurringTimeZone = \DateTime::createFromFormat(self::UNIX_FORMAT, $yearRecurringTimestamp); - $recurringTimeZone->setTimezone($initialStart->getTimezone()); - $yearRecurringOffset = $recurringTimeZone->getOffset(); - $yearRecurringTimestamp += $yearRecurringOffset; - } - $eventStartDescs = array(); if (isset($rrules['BYMONTH']) && $rrules['BYMONTH'] !== '') { foreach ($bymonths as $bymonth) { @@ -1954,8 +1890,8 @@ protected function processRecurrences() $anEvent['DTEND_array'][1] = $anEvent['DTEND']; // Exclusions - $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent, $yearRecurringOffset) { - return self::isExdateMatch($exdate, $anEvent, $yearRecurringOffset); + $isExcluded = array_filter($exdates, function ($exdate) use ($anEvent) { + return self::isExdateMatch($exdate, $anEvent); }); if (isset($anEvent['UID'])) { @@ -2029,19 +1965,14 @@ protected function processDateConversions() continue; } - if ($this->useTimeZoneWithRRules && isset($anEvent['RRULE_array'][2]) && $anEvent['RRULE_array'][2] === self::RECURRENCE_EVENT) { - $events[$key]['DTSTART_tz'] = $anEvent['DTSTART']; - $events[$key]['DTEND_tz'] = isset($anEvent['DTEND']) ? $anEvent['DTEND'] : $anEvent['DTSTART']; - } else { - $events[$key]['DTSTART_tz'] = $this->iCalDateWithTimeZone($anEvent, 'DTSTART'); + $events[$key]['DTSTART_tz'] = $this->iCalDateWithTimeZone($anEvent, 'DTSTART'); - if ($this->iCalDateWithTimeZone($anEvent, 'DTEND')) { - $events[$key]['DTEND_tz'] = $this->iCalDateWithTimeZone($anEvent, 'DTEND'); - } elseif ($this->iCalDateWithTimeZone($anEvent, 'DURATION')) { - $events[$key]['DTEND_tz'] = $this->iCalDateWithTimeZone($anEvent, 'DURATION'); - } else { - $events[$key]['DTEND_tz'] = $events[$key]['DTSTART_tz']; - } + if ($this->iCalDateWithTimeZone($anEvent, 'DTEND')) { + $events[$key]['DTEND_tz'] = $this->iCalDateWithTimeZone($anEvent, 'DTEND'); + } elseif ($this->iCalDateWithTimeZone($anEvent, 'DURATION')) { + $events[$key]['DTEND_tz'] = $this->iCalDateWithTimeZone($anEvent, 'DURATION'); + } else { + $events[$key]['DTEND_tz'] = $events[$key]['DTSTART_tz']; } } @@ -2767,10 +2698,9 @@ protected function trimToRecurrenceCount(array $rrules, array $recurrenceEvents) * * @param Carbon $exdate * @param array $anEvent - * @param integer $recurringOffset * @return boolean */ - protected function isExdateMatch($exdate, array $anEvent, $recurringOffset) // phpcs:ignore Squiz.Commenting.FunctionComment.TypeHintMissing + protected function isExdateMatch($exdate, array $anEvent) // phpcs:ignore Squiz.Commenting.FunctionComment.TypeHintMissing { $searchDate = $anEvent['DTSTART']; @@ -2783,8 +2713,7 @@ protected function isExdateMatch($exdate, array $anEvent, $recurringOffset) // p } $a = new Carbon($searchDate, $timeZone); - $b = $exdate->addSeconds($recurringOffset); - return $a->eq($b); + return $a->eq($exdate); } } diff --git a/tests/RecurrencesTest.php b/tests/RecurrencesTest.php index 4952de7..8dc31f3 100644 --- a/tests/RecurrencesTest.php +++ b/tests/RecurrencesTest.php @@ -10,7 +10,6 @@ class RecurrencesTest extends TestCase // phpcs:disable Squiz.Commenting.FunctionComment // phpcs:disable Squiz.Commenting.VariableComment - private $useTimeZoneWithRRules = false; private $originalTimeZone = null; public function setUp() @@ -276,7 +275,6 @@ public function getOptions($defaultTimezone) 'filterDaysAfter' => null, // Default value 'filterDaysBefore' => null, // Default value 'skipRecurrence' => false, // Default value - 'useTimeZoneWithRRules' => $this->useTimeZoneWithRRules, // Default value: false ); return $options; diff --git a/tests/SingleEventsTest.php b/tests/SingleEventsTest.php index 6bcbea8..cee3a7f 100644 --- a/tests/SingleEventsTest.php +++ b/tests/SingleEventsTest.php @@ -119,7 +119,6 @@ public function getOptions($defaultTimezone) 'filterDaysAfter' => null, // Default value 'filterDaysBefore' => null, // Default value 'skipRecurrence' => false, // Default value - 'useTimeZoneWithRRules' => false, // Default value ); return $options;