Skip to content

Commit

Permalink
Proposed fix for #238 (#239)
Browse files Browse the repository at this point in the history
Proposed fix for #238
  • Loading branch information
u01jmg3 authored Sep 2, 2019
2 parents 183c649 + 2e2ed81 commit f551c3b
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/ICal/ICal.php
Original file line number Diff line number Diff line change
Expand Up @@ -1313,11 +1313,8 @@ protected function processRecurrences()
if (!empty($rrules['BYDAY'])) {
// setISODate below uses the ISO-8601 specification of weeks: start on
// a Monday, end on a Sunday. However, RRULEs (or the caller of the
// parser) may state an alternate WeeKSTart. In this case, we need to
// determine the point where days that ordinarily come after Monday now
// come before Monday.
// parser) may state an alternate WeeKSTart.
$wkstTransition = 7;

if (empty($rrules['WKST'])) {
if ($this->defaultWeekStart !== self::ISO_8601_WEEK_START) {
$wkstTransition = array_search($this->defaultWeekStart, array_keys($this->weekdays));
Expand All @@ -1326,11 +1323,16 @@ protected function processRecurrences()
$wkstTransition = array_search($rrules['WKST'], array_keys($this->weekdays));
}

$initialDayOfWeek = $frequencyRecurringDateTime->format('N');
$matchingDays = array_map(
function ($weekday) use ($wkstTransition) {
function ($weekday) use ($interval, $wkstTransition, $initialDayOfWeek) {
$day = array_search($weekday, array_keys($this->weekdays));
if ($day < $initialDayOfWeek) {
$day += 7;
}

if ($day >= $wkstTransition) {
$day -= 7;
$day += 7 * ($interval - 1);
}

// Ignoring alternate week starts, $day at this point will have a
Expand Down

0 comments on commit f551c3b

Please sign in to comment.