Skip to content

Commit

Permalink
RE: #212 - support every month's last day
Browse files Browse the repository at this point in the history
  • Loading branch information
u01jmg3 committed Apr 2, 2019
1 parent f740b51 commit 1b11a16
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
14 changes: 14 additions & 0 deletions examples/ICal.ics
Original file line number Diff line number Diff line change
Expand Up @@ -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:[email protected]
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
Expand Down
10 changes: 6 additions & 4 deletions src/ICal/ICal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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}";
Expand Down

0 comments on commit 1b11a16

Please sign in to comment.