From 1b11a16fe45241d025e5158e1888f98239c6762d Mon Sep 17 00:00:00 2001 From: Jonathan Goode Date: Tue, 2 Apr 2019 23:44:41 +0100 Subject: [PATCH] RE: #212 - support every month's last day --- examples/ICal.ics | 14 ++++++++++++++ src/ICal/ICal.php | 10 ++++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/examples/ICal.ics b/examples/ICal.ics index f7ebd84..117a14b 100644 --- a/examples/ICal.ics +++ b/examples/ICal.ics @@ -229,6 +229,20 @@ SUMMARY;LANGUAGE=en-gb:BYSETPOS First weekday of every month TRANSP:TRANSPARENT END:VEVENT BEGIN:VEVENT +DTSTART;VALUE=DATE:20190131 +DTEND;VALUE=DATE:20190131 +DTSTAMP;TZID="GMT Standard Time":20190121T195741Z +RRULE:FREQ=MONTHLY;INTERVAL=1;BYDAY=SU,MO,TU,WE,TH,FR,SA;BYSETPOS=-1 +UID:4dnsuc3nknin15kv25cn7ridssx@google.com +CREATED:20190119T142059Z +DESCRIPTION;LANGUAGE=en-gb:BYSETPOS Last day of every month +LAST-MODIFIED:20190409T150000Z +SEQUENCE:0 +STATUS:CONFIRMED +SUMMARY;LANGUAGE=en-gb:BYSETPOS Last day of every month +TRANSP:TRANSPARENT +END:VEVENT +BEGIN:VEVENT DTSTART;VALUE=DATE:20170301 DTEND;VALUE=DATE:20170301 DTSTAMP;TZID="GMT Standard Time":20170121T195741Z diff --git a/src/ICal/ICal.php b/src/ICal/ICal.php index acb1730..1ad0ec2 100644 --- a/src/ICal/ICal.php +++ b/src/ICal/ICal.php @@ -1292,7 +1292,9 @@ protected function processRecurrences() $byDaysCounted = array_count_values(explode(',', $rrules['BYDAY'])); - if ($byDaysCounted == array_count_values(array_slice($this->weeks['MO'], 0, 5))) { + if ($byDaysCounted == array_count_values($this->weeks['MO'])) { + $weekday = 'day'; + } elseif ($byDaysCounted == array_count_values(array_slice($this->weeks['MO'], 0, 5))) { $weekday = 'weekday'; } } @@ -1743,7 +1745,7 @@ protected function processRecurrences() } while ($eventStartTimestamp <= $lastDayTimestamp); // Move forwards - $recurringTimestamp = strtotime($offset, $recurringTimestamp); + $recurringTimestamp = strtotime($offset, Carbon::createFromTimestamp($recurringTimestamp)->day(1)->timestamp); } } @@ -2483,8 +2485,8 @@ protected function convertDayOrdinalToPositive($dayNumber, $weekday, $timestamp) $dayOrdinals = $this->dayOrdinals; - if ($dayNumber >= 1) { - $dayOrdinal = $dayOrdinals[$dayNumber]; + if ($dayNumber >= -1) { + $dayOrdinal = $dayNumber === -1 ? 'last' : $dayOrdinals[$dayNumber]; if ($weekday === 'weekday') { $dayOrdinal = "-1 day {$dayOrdinal}";