Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposed fix for #238 #239

Merged
merged 1 commit into from
Sep 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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