Changeset View
Changeset View
Standalone View
Standalone View
src/parser/calendar/data/PhutilCalendarRecurrenceRule.php
Show First 20 Lines • Show All 164 Lines • ▼ Show 20 Lines | if ($expect === null) { | ||||
$expect = array_fuse( | $expect = array_fuse( | ||||
array( | array( | ||||
'FREQ', | 'FREQ', | ||||
'INTERVAL', | 'INTERVAL', | ||||
'BYSECOND', | 'BYSECOND', | ||||
'BYMINUTE', | 'BYMINUTE', | ||||
'BYHOUR', | 'BYHOUR', | ||||
'BYDAY', | 'BYDAY', | ||||
'BYMONTH', | |||||
'BYMONTHDAY', | 'BYMONTHDAY', | ||||
'BYYEARDAY', | 'BYYEARDAY', | ||||
'BYWEEKNO', | 'BYWEEKNO', | ||||
'BYSETPOS', | 'BYSETPOS', | ||||
'WKST', | 'WKST', | ||||
'UNTIL', | 'UNTIL', | ||||
'COUNT', | 'COUNT', | ||||
)); | )); | ||||
Show All 12 Lines | public static function newFromDictionary(array $dict) { | ||||
$rrule = id(new self()) | $rrule = id(new self()) | ||||
->setFrequency(idx($dict, 'FREQ')) | ->setFrequency(idx($dict, 'FREQ')) | ||||
->setInterval(idx($dict, 'INTERVAL', 1)) | ->setInterval(idx($dict, 'INTERVAL', 1)) | ||||
->setBySecond(idx($dict, 'BYSECOND', array())) | ->setBySecond(idx($dict, 'BYSECOND', array())) | ||||
->setByMinute(idx($dict, 'BYMINUTE', array())) | ->setByMinute(idx($dict, 'BYMINUTE', array())) | ||||
->setByHour(idx($dict, 'BYHOUR', array())) | ->setByHour(idx($dict, 'BYHOUR', array())) | ||||
->setByDay(idx($dict, 'BYDAY', array())) | ->setByDay(idx($dict, 'BYDAY', array())) | ||||
->setByMonth(idx($dict, 'BYMONTH', array())) | |||||
->setByMonthDay(idx($dict, 'BYMONTHDAY', array())) | ->setByMonthDay(idx($dict, 'BYMONTHDAY', array())) | ||||
->setByYearDay(idx($dict, 'BYYEARDAY', array())) | ->setByYearDay(idx($dict, 'BYYEARDAY', array())) | ||||
->setByWeekNumber(idx($dict, 'BYWEEKNO', array())) | ->setByWeekNumber(idx($dict, 'BYWEEKNO', array())) | ||||
->setBySetPosition(idx($dict, 'BYSETPOS', array())) | ->setBySetPosition(idx($dict, 'BYSETPOS', array())) | ||||
->setWeekStart(idx($dict, 'WKST', self::WEEKDAY_MONDAY)); | ->setWeekStart(idx($dict, 'WKST', self::WEEKDAY_MONDAY)); | ||||
$count = idx($dict, 'COUNT'); | $count = idx($dict, 'COUNT'); | ||||
if ($count) { | if ($count) { | ||||
Show All 38 Lines | foreach ($parts as $part) { | ||||
break; | break; | ||||
default: | default: | ||||
$value = explode(',', $value); | $value = explode(',', $value); | ||||
break; | break; | ||||
} | } | ||||
$dict[$key] = $value; | $dict[$key] = $value; | ||||
} | } | ||||
$int_lists = array_fuse( | |||||
array( | |||||
// NOTE: "BYDAY" is absent, and takes a list like "MO, TU, WE". | |||||
'BYSECOND', | |||||
'BYMINUTE', | |||||
'BYHOUR', | |||||
'BYMONTH', | |||||
'BYMONTHDAY', | |||||
'BYYEARDAY', | |||||
'BYWEEKNO', | |||||
'BYSETPOS', | |||||
)); | |||||
foreach ($dict as $key => $value) { | |||||
if (isset($int_lists[$key])) { | |||||
foreach ($value as $k => $v) { | |||||
if (!preg_match('/^-?\d+\z/', $v)) { | |||||
throw new Exception( | |||||
pht( | |||||
'Unexpected value "%s" in "%s" RRULE property: expected '. | |||||
'only integers.', | |||||
$v, | |||||
$key)); | |||||
} | |||||
$value[$k] = (int)$v; | |||||
} | |||||
$dict[$key] = $value; | |||||
} | |||||
} | |||||
return self::newFromDictionary($dict); | return self::newFromDictionary($dict); | ||||
} | } | ||||
private static function getAllWeekdayConstants() { | private static function getAllWeekdayConstants() { | ||||
return array_keys(self::getWeekdayIndexMap()); | return array_keys(self::getWeekdayIndexMap()); | ||||
} | } | ||||
private static function getWeekdayIndexMap() { | private static function getWeekdayIndexMap() { | ||||
▲ Show 20 Lines • Show All 1,507 Lines • Show Last 20 Lines |