Page MenuHomePhabricator

D16637.diff
No OneTemporary

D16637.diff

diff --git a/src/parser/calendar/data/PhutilCalendarRecurrenceRule.php b/src/parser/calendar/data/PhutilCalendarRecurrenceRule.php
--- a/src/parser/calendar/data/PhutilCalendarRecurrenceRule.php
+++ b/src/parser/calendar/data/PhutilCalendarRecurrenceRule.php
@@ -403,6 +403,10 @@
$this->cursorMonth -= $interval;
$this->rewindMonth();
break;
+ case self::FREQUENCY_WEEKLY:
+ $this->cursorWeek -= $interval;
+ $this->rewindWeek();
+ break;
case self::FREQUENCY_DAILY:
$this->cursorDay -= $interval;
$this->rewindDay();
@@ -672,22 +676,26 @@
$this->nextMonth();
}
+ // NOTE: We normally handle BYMONTH when iterating months, but it acts
+ // like a filter if FREQ=WEEKLY.
+
$is_dynamic = $is_daily
|| $is_weekly
|| $by_day
|| $by_monthday
|| $by_yearday
|| $by_weekno
+ || ($by_month && $is_weekly)
|| ($scale < self::SCALE_DAILY);
if ($is_dynamic) {
$weeks = $this->newDaysSet(
($is_daily ? $interval : 1),
- ($is_weekly ? $interval : 1),
$by_day,
$by_monthday,
$by_yearday,
$by_weekno,
+ $by_month,
$week_start);
} else {
// The cursor day may not actually exist in the current month, so
@@ -921,11 +929,11 @@
private function newDaysSet(
$interval_day,
- $interval_week,
$by_day,
$by_monthday,
$by_yearday,
$by_weekno,
+ $by_month,
$week_start) {
$frequency = $this->getFrequency();
@@ -1044,6 +1052,12 @@
}
}
+ if ($by_month) {
+ if (empty($by_month[$info['month']])) {
+ continue;
+ }
+ }
+
$weeks[$info['week']][] = $info;
}
@@ -1385,6 +1399,15 @@
}
}
+ private function rewindWeek() {
+ $week_start = $this->getWeekStart();
+ while ($this->cursorWeek < 1) {
+ $this->cursorYear--;
+ $year_map = $this->getYearMap($this->cursorYear, $week_start);
+ $this->cursorWeek += $year_map['weekCount'];
+ }
+ }
+
private function rewindDay() {
$week_start = $this->getWeekStart();
while ($this->cursorDay < 1) {
diff --git a/src/parser/calendar/data/__tests__/PhutilCalendarRecurrenceRuleTestCase.php b/src/parser/calendar/data/__tests__/PhutilCalendarRecurrenceRuleTestCase.php
--- a/src/parser/calendar/data/__tests__/PhutilCalendarRecurrenceRuleTestCase.php
+++ b/src/parser/calendar/data/__tests__/PhutilCalendarRecurrenceRuleTestCase.php
@@ -684,6 +684,94 @@
$expect);
}
+ public function testWeeklyRecurrenceRules() {
+ $tests = array();
+ $expect = array();
+
+ $tests[] = array();
+ $expect[] = array(
+ '19970902',
+ '19970909',
+ '19970916',
+ );
+
+ $tests[] = array(
+ 'INTERVAL' => 2,
+ );
+ $expect[] = array(
+ '19970902',
+ '19970916',
+ '19970930',
+ );
+
+ $tests[] = array(
+ 'INTERVAL' => 20,
+ );
+ $expect[] = array(
+ '19970902',
+ '19980120',
+ '19980609',
+ );
+
+ $tests[] = array(
+ 'BYMONTH' => array(1, 3),
+ );
+ $expect[] = array(
+ '19980106',
+ '19980113',
+ '19980120',
+ );
+
+ $tests[] = array(
+ 'BYDAY' => array('TU', 'TH'),
+ );
+ $expect[] = array(
+ '19970902',
+ '19970904',
+ '19970909',
+ );
+
+ $tests[] = array(
+ 'BYMONTH' => array(1, 3),
+ 'BYDAY' => array('TU', 'TH'),
+ );
+ $expect[] = array(
+ '19980101',
+ '19980106',
+ '19980108',
+ );
+
+ $tests[] = array(
+ 'BYHOUR' => array(6, 18),
+ );
+ $expect[] = array(
+ '19970902T060000Z',
+ '19970902T180000Z',
+ '19970909T060000Z',
+ );
+
+ $tests[] = array(
+ 'BYDAY' => array('TU', 'TH'),
+ 'BYHOUR' => array(6, 18),
+ 'BYSETPOS' => array(3, -3),
+ 'DTSTART' => '19970902T090000Z',
+ );
+ $expect[] = array(
+ '19970902T180000Z',
+ '19970904T060000Z',
+ '19970909T180000Z',
+ );
+
+ $this->assertRules(
+ array(
+ 'FREQ' => 'WEEKLY',
+ 'COUNT' => 3,
+ 'DTSTART' => '19970902',
+ ),
+ $tests,
+ $expect);
+ }
+
public function testDailyRecurrenceRules() {
$tests = array();
$expect = array();

File Metadata

Mime Type
text/plain
Expires
Sat, Oct 19, 11:15 PM (2 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6734257
Default Alt Text
D16637.diff (4 KB)

Event Timeline