From 78c77196ea0b6beb7b8be22b1041e407bdab3d6b Mon Sep 17 00:00:00 2001 From: Len Kawamoto Date: Wed, 29 Aug 2018 08:50:17 -0700 Subject: [PATCH] Off By One Error for BYSETPOS For recurring events with positive BYSETPOS values, events were showing up off by one. For example: Labor Day (as created by Zimbra) had the following RRULE: FREQ=YEARLY;INTERVAL=1;BYMONTH=9;BYDAY=MO;BYSETPOS=1 BYSETPOS is One-Based Indexing while array_slice(...) uses Zero-Based Indexing. --- functions/parse/recur_functions.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/functions/parse/recur_functions.php b/functions/parse/recur_functions.php index 82e9568..5b118b2 100644 --- a/functions/parse/recur_functions.php +++ b/functions/parse/recur_functions.php @@ -270,6 +270,13 @@ function restrict_bysetpos($times, $freq = '') { sort($times); $new_times = array(); foreach ($bysetpos as $setpos) { + // For positive values, we need to adjust for + // Zero-Based Indexing. + $nSetPos = (int)$setpos; + if ($nSetPos > 0) + { + $nSetPos -= 1; + } $new_times[] = implode('', array_slice($times, $setpos, 1)); } return $new_times;