Page MenuHomePhabricator

D17644.diff
No OneTemporary

D17644.diff

diff --git a/src/parser/calendar/data/PhutilCalendarRecurrenceSet.php b/src/parser/calendar/data/PhutilCalendarRecurrenceSet.php
--- a/src/parser/calendar/data/PhutilCalendarRecurrenceSet.php
+++ b/src/parser/calendar/data/PhutilCalendarRecurrenceSet.php
@@ -50,9 +50,9 @@
if ($start) {
$start = clone $start;
$start->setViewerTimezone($timezone);
- $cursor = $start->getEpoch();
+ $min_epoch = $start->getEpoch();
} else {
- $cursor = 0;
+ $min_epoch = 0;
}
if ($end) {
@@ -64,6 +64,8 @@
}
$results = array();
+ $index = 0;
+ $cursor = 0;
while (true) {
// Get the next event for each source which we don't have a future
// event for.
@@ -130,7 +132,15 @@
// skip it and move on. If it's not an exception, it does occur, so
// we record it.
if (!$is_exception) {
- $results[] = $next_source['state'];
+
+ // Only actually include this event in the results if it starts after
+ // any specified start time. We increment the index regardless, so we
+ // return results with proper offsets.
+ if ($next_source['epoch'] >= $min_epoch) {
+ $results[$index] = $next_source['state'];
+ }
+ $index++;
+
if ($limit !== null && (count($results) >= $limit)) {
break;
}
diff --git a/src/parser/calendar/data/__tests__/PhutilCalendarRecurrenceTestCase.php b/src/parser/calendar/data/__tests__/PhutilCalendarRecurrenceTestCase.php
--- a/src/parser/calendar/data/__tests__/PhutilCalendarRecurrenceTestCase.php
+++ b/src/parser/calendar/data/__tests__/PhutilCalendarRecurrenceTestCase.php
@@ -154,8 +154,8 @@
pht('Multiple lists, one result.'));
$expect = array(
- PhutilCalendarAbsoluteDateTime::newFromISO8601('20160103T120000Z'),
- PhutilCalendarAbsoluteDateTime::newFromISO8601('20160104T120000Z'),
+ 2 => PhutilCalendarAbsoluteDateTime::newFromISO8601('20160103T120000Z'),
+ 3 => PhutilCalendarAbsoluteDateTime::newFromISO8601('20160104T120000Z'),
);
$result = $date_set->getEventsBetween(
PhutilCalendarAbsoluteDateTime::newFromISO8601('20160103T120000Z'),
@@ -166,4 +166,31 @@
pht('Multiple lists, time window.'));
}
+ public function testCalendarRecurrenceOffsets() {
+ $list = array(
+ PhutilCalendarAbsoluteDateTime::newFromISO8601('20160101T120000Z'),
+ PhutilCalendarAbsoluteDateTime::newFromISO8601('20160103T120000Z'),
+ PhutilCalendarAbsoluteDateTime::newFromISO8601('20160102T120000Z'),
+ );
+
+ $source = id(new PhutilCalendarRecurrenceList())
+ ->setDates($list);
+
+ $set = id(new PhutilCalendarRecurrenceSet())
+ ->addSource($source);
+
+ $t1 = PhutilCalendarAbsoluteDateTime::newFromISO8601('20160102T120001Z');
+ $t2 = PhutilCalendarAbsoluteDateTime::newFromISO8601('20160103T120000Z');
+
+ $expect = array(
+ 2 => $t2,
+ );
+
+ $result = $set->getEventsBetween($t1, null, 0xFFFF);
+ $this->assertEqual(
+ mpull($expect, 'getISO8601'),
+ mpull($result, 'getISO8601'),
+ pht('Correct event indexes with start date.'));
+ }
+
}

File Metadata

Mime Type
text/plain
Expires
Wed, Apr 9, 9:31 AM (2 w, 1 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7720533
Default Alt Text
D17644.diff (3 KB)

Event Timeline