本文整理汇总了PHP中Sabre\VObject\DateTimeParser::parse方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTimeParser::parse方法的具体用法?PHP DateTimeParser::parse怎么用?PHP DateTimeParser::parse使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Sabre\VObject\DateTimeParser
的用法示例。
在下文中一共展示了DateTimeParser::parse方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isFree
/**
* Checks based on the contained FREEBUSY information, if a timeslot is
* available.
*
* @param DateTime $start
* @param Datetime $end
* @return bool
*/
public function isFree(\DateTime $start, \Datetime $end)
{
foreach ($this->select('FREEBUSY') as $freebusy) {
// We are only interested in FBTYPE=BUSY (the default),
// FBTYPE=BUSY-TENTATIVE or FBTYPE=BUSY-UNAVAILABLE.
if (isset($freebusy['FBTYPE']) && strtoupper(substr((string) $freebusy['FBTYPE'], 0, 4)) !== 'BUSY') {
continue;
}
// The freebusy component can hold more than 1 value, separated by
// commas.
$periods = explode(',', (string) $freebusy);
foreach ($periods as $period) {
// Every period is formatted as [start]/[end]. The start is an
// absolute UTC time, the end may be an absolute UTC time, or
// duration (relative) value.
list($busyStart, $busyEnd) = explode('/', $period);
$busyStart = VObject\DateTimeParser::parse($busyStart);
$busyEnd = VObject\DateTimeParser::parse($busyEnd);
if ($busyEnd instanceof \DateInterval) {
$tmp = clone $busyStart;
$tmp->add($busyEnd);
$busyEnd = $tmp;
}
if ($start < $busyEnd && $end > $busyStart) {
return false;
}
}
}
return true;
}
示例2: next
/**
* Goes on to the next iteration.
*
* @return void
*/
public function next()
{
$this->counter++;
if (!$this->valid()) {
return;
}
$this->currentDate = DateTimeParser::parse($this->dates[$this->counter - 1]);
}
示例3: testParseICalendarDate
function testParseICalendarDate()
{
$dateTime = DateTimeParser::parseDate('20100316');
$expected = new DateTime('2010-03-16 00:00:00', new DateTimeZone('UTC'));
$this->assertEquals($expected, $dateTime);
$dateTime = DateTimeParser::parse('20100316');
$this->assertEquals($expected, $dateTime);
}
示例4: next
/**
* Goes on to the next iteration.
*
* @return void
*/
function next()
{
$this->counter++;
if (!$this->valid()) {
return;
}
$this->currentDate = DateTimeParser::parse($this->dates[$this->counter - 1], $this->startDate->getTimezone());
}
示例5: parseRRule
/**
* This method receives a string from an RRULE property, and populates this
* class with all the values.
*
* @param string|array $rrule
* @return void
*/
protected function parseRRule($rrule)
{
if (is_string($rrule)) {
$rrule = Property\ICalendar\Recur::stringToArray($rrule);
}
foreach ($rrule as $key => $value) {
$key = strtoupper($key);
switch ($key) {
case 'FREQ':
$value = strtolower($value);
if (!in_array($value, array('secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly', 'yearly'))) {
throw new InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
}
$this->frequency = $value;
break;
case 'UNTIL':
$this->until = DateTimeParser::parse($value, $this->startDate->getTimezone());
// In some cases events are generated with an UNTIL=
// parameter before the actual start of the event.
//
// Not sure why this is happening. We assume that the
// intention was that the event only recurs once.
//
// So we are modifying the parameter so our code doesn't
// break.
if ($this->until < $this->startDate) {
$this->until = $this->startDate;
}
break;
case 'INTERVAL':
// No break
// No break
case 'COUNT':
$val = (int) $value;
if ($val < 1) {
throw new \InvalidArgumentException(strtoupper($key) . ' in RRULE must be a positive integer!');
}
$key = strtolower($key);
$this->{$key} = $val;
break;
case 'BYSECOND':
$this->bySecond = (array) $value;
break;
case 'BYMINUTE':
$this->byMinute = (array) $value;
break;
case 'BYHOUR':
$this->byHour = (array) $value;
break;
case 'BYDAY':
$value = (array) $value;
foreach ($value as $part) {
if (!preg_match('#^ (-|\\+)? ([1-5])? (MO|TU|WE|TH|FR|SA|SU) $# xi', $part)) {
throw new \InvalidArgumentException('Invalid part in BYDAY clause: ' . $part);
}
}
$this->byDay = $value;
break;
case 'BYMONTHDAY':
$this->byMonthDay = (array) $value;
break;
case 'BYYEARDAY':
$this->byYearDay = (array) $value;
break;
case 'BYWEEKNO':
$this->byWeekNo = (array) $value;
break;
case 'BYMONTH':
$this->byMonth = (array) $value;
break;
case 'BYSETPOS':
$this->bySetPos = (array) $value;
break;
case 'WKST':
$this->weekStart = strtoupper($value);
break;
default:
throw new \InvalidArgumentException('Not supported: ' . strtoupper($key));
}
}
}
示例6: parseEventForAttendee
/**
* Parse an event update for an attendee.
*
* This function figures out if we need to send a reply to an organizer.
*
* @param VCalendar $calendar
* @param array $eventInfo
* @param array $oldEventInfo
* @param string $attendee
* @return Message[]
*/
protected function parseEventForAttendee(VCalendar $calendar, array $eventInfo, array $oldEventInfo, $attendee)
{
if ($this->scheduleAgentServerRules && $eventInfo['organizerScheduleAgent'] === 'CLIENT') {
return array();
}
// Don't bother generating messages for events that have already been
// cancelled.
if ($eventInfo['status'] === 'CANCELLED') {
return array();
}
$instances = array();
foreach ($oldEventInfo['attendees'][$attendee]['instances'] as $instance) {
$instances[$instance['id']] = array('id' => $instance['id'], 'oldstatus' => $instance['partstat'], 'newstatus' => null);
}
foreach ($eventInfo['attendees'][$attendee]['instances'] as $instance) {
if (isset($instances[$instance['id']])) {
$instances[$instance['id']]['newstatus'] = $instance['partstat'];
} else {
$instances[$instance['id']] = array('id' => $instance['id'], 'oldstatus' => null, 'newstatus' => $instance['partstat']);
}
}
// We need to also look for differences in EXDATE. If there are new
// items in EXDATE, it means that an attendee deleted instances of an
// event, which means we need to send DECLINED specifically for those
// instances.
// We only need to do that though, if the master event is not declined.
if ($instances['master']['newstatus'] !== 'DECLINED') {
foreach ($eventInfo['exdate'] as $exDate) {
if (!in_array($exDate, $oldEventInfo['exdate'])) {
if (isset($instances[$exDate])) {
$instances[$exDate]['newstatus'] = 'DECLINED';
} else {
$instances[$exDate] = array('id' => $exDate, 'oldstatus' => null, 'newstatus' => 'DECLINED');
}
}
}
}
// Gathering a few extra properties for each instance.
foreach ($instances as $recurId => $instanceInfo) {
if (isset($eventInfo['instances'][$recurId])) {
$instances[$recurId]['dtstart'] = clone $eventInfo['instances'][$recurId]->DTSTART;
} else {
$instances[$recurId]['dtstart'] = $recurId;
}
}
$message = new Message();
$message->uid = $eventInfo['uid'];
$message->method = 'REPLY';
$message->component = 'VEVENT';
$message->sequence = $eventInfo['sequence'];
$message->sender = $attendee;
$message->senderName = $eventInfo['attendees'][$attendee]['name'];
$message->recipient = $eventInfo['organizer'];
$message->recipientName = $eventInfo['organizerName'];
$icalMsg = new VCalendar();
$icalMsg->METHOD = 'REPLY';
$hasReply = false;
foreach ($instances as $instance) {
if ($instance['oldstatus'] == $instance['newstatus'] && $eventInfo['organizerForceSend'] !== 'REPLY') {
// Skip
continue;
}
$event = $icalMsg->add('VEVENT', array('UID' => $message->uid, 'SEQUENCE' => $message->sequence));
$summary = isset($calendar->VEVENT->SUMMARY) ? $calendar->VEVENT->SUMMARY->getValue() : '';
// Adding properties from the correct source instance
if (isset($eventInfo['instances'][$instance['id']])) {
$instanceObj = $eventInfo['instances'][$instance['id']];
$event->add(clone $instanceObj->DTSTART);
if (isset($instanceObj->SUMMARY)) {
$event->add('SUMMARY', $instanceObj->SUMMARY->getValue());
} elseif ($summary) {
$event->add('SUMMARY', $summary);
}
} else {
// This branch of the code is reached, when a reply is
// generated for an instance of a recurring event, through the
// fact that the instance has disappeared by showing up in
// EXDATE
$dt = DateTimeParser::parse($instance['id'], $eventInfo['timezone']);
// Treat is as a DATE field
if (strlen($instance['id']) <= 8) {
$recur = $event->add('DTSTART', $dt, array('VALUE' => 'DATE'));
} else {
$recur = $event->add('DTSTART', $dt);
}
if ($summary) {
$event->add('SUMMARY', $summary);
}
}
//.........这里部分代码省略.........
示例7: DateTime
/**
* Check if a datetime with year > 4000 will not throw an exception. iOS seems to use 45001231T235959 in yearly recurring events
*/
function testParseICalendarDateTimeGreaterThan4000()
{
$dateTime = DateTimeParser::parseDateTime('45001231T235959');
$expected = new DateTime('4500-12-31 23:59:59', new DateTimeZone('UTC'));
$this->assertEquals($expected, $dateTime);
$dateTime = DateTimeParser::parse('45001231T235959');
$this->assertEquals($expected, $dateTime);
}
示例8: getDenormalizedData
/**
* Parses some information from calendar objects, used for optimized
* calendar-queries.
*
* Returns an array with the following keys:
* * etag
* * size
* * componentType
* * firstOccurence
* * lastOccurence
*
* @param string $calendarData
* @return array
*/
protected function getDenormalizedData($calendarData)
{
$vObject = VObject\Reader::read($calendarData);
$componentType = null;
$component = null;
$firstOccurence = null;
$lastOccurence = null;
foreach ($vObject->getComponents() as $component) {
if ($component->name !== 'VTIMEZONE') {
$componentType = $component->name;
break;
}
}
if (!$componentType) {
throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component');
}
if ($componentType === 'VEVENT') {
$firstOccurence = $component->DTSTART->getDateTime()->getTimeStamp();
// Finding the last occurence is a bit harder
if (!isset($component->RRULE)) {
if (isset($component->DTEND)) {
$lastOccurence = $component->DTEND->getDateTime()->getTimeStamp();
} elseif (isset($component->DURATION)) {
$endDate = clone $component->DTSTART->getDateTime();
$endDate->add(VObject\DateTimeParser::parse($component->DURATION->getValue()));
$lastOccurence = $endDate->getTimeStamp();
} elseif (!$component->DTSTART->hasTime()) {
$endDate = clone $component->DTSTART->getDateTime();
$endDate->modify('+1 day');
$lastOccurence = $endDate->getTimeStamp();
} else {
$lastOccurence = $firstOccurence;
}
} else {
$it = new VObject\RecurrenceIterator($vObject, (string) $component->UID);
$maxDate = new \DateTime(self::MAX_DATE);
if ($it->isInfinite()) {
$lastOccurence = $maxDate->getTimeStamp();
} else {
$end = $it->getDtEnd();
while ($it->valid() && $end < $maxDate) {
$end = $it->getDtEnd();
$it->next();
}
$lastOccurence = $end->getTimeStamp();
}
}
}
return array('etag' => md5($calendarData), 'size' => strlen($calendarData), 'componentType' => $componentType, 'firstOccurence' => $firstOccurence, 'lastOccurence' => $lastOccurence);
}
示例9: getDateTimes
/**
* Returns multiple date-time values.
*
* If no timezone information is known, because it's either an all-day
* property or floating time, we will use the DateTimeZone argument to
* figure out the exact date.
*
* @param DateTimeZone $timeZone
*
* @return DateTimeImmutable[]
* @return \DateTime[]
*/
function getDateTimes(DateTimeZone $timeZone = null)
{
// Does the property have a TZID?
$tzid = $this['TZID'];
if ($tzid) {
$timeZone = TimeZoneUtil::getTimeZone((string) $tzid, $this->root);
}
$dts = [];
foreach ($this->getParts() as $part) {
$dts[] = DateTimeParser::parse($part, $timeZone);
}
return $dts;
}
示例10: getDenormalizedData
/**
* Parses some information from calendar objects, used for optimized
* calendar-queries.
*
* Returns an array with the following keys:
* * etag - An md5 checksum of the object without the quotes.
* * size - Size of the object in bytes
* * componentType - VEVENT, VTODO or VJOURNAL
* * firstOccurence
* * lastOccurence
* * uid - value of the UID property
*
* @param string $calendarData
* @return array
*/
public function getDenormalizedData($calendarData)
{
$vObject = Reader::read($calendarData);
$componentType = null;
$component = null;
$firstOccurrence = null;
$lastOccurrence = null;
$uid = null;
$classification = self::CLASSIFICATION_PUBLIC;
foreach ($vObject->getComponents() as $component) {
if ($component->name !== 'VTIMEZONE') {
$componentType = $component->name;
$uid = (string) $component->UID;
break;
}
}
if (!$componentType) {
throw new \Sabre\DAV\Exception\BadRequest('Calendar objects must have a VJOURNAL, VEVENT or VTODO component');
}
if ($componentType === 'VEVENT' && $component->DTSTART) {
$firstOccurrence = $component->DTSTART->getDateTime()->getTimeStamp();
// Finding the last occurrence is a bit harder
if (!isset($component->RRULE)) {
if (isset($component->DTEND)) {
$lastOccurrence = $component->DTEND->getDateTime()->getTimeStamp();
} elseif (isset($component->DURATION)) {
$endDate = clone $component->DTSTART->getDateTime();
$endDate->add(DateTimeParser::parse($component->DURATION->getValue()));
$lastOccurrence = $endDate->getTimeStamp();
} elseif (!$component->DTSTART->hasTime()) {
$endDate = clone $component->DTSTART->getDateTime();
$endDate->modify('+1 day');
$lastOccurrence = $endDate->getTimeStamp();
} else {
$lastOccurrence = $firstOccurrence;
}
} else {
$it = new EventIterator($vObject, (string) $component->UID);
$maxDate = new \DateTime(self::MAX_DATE);
if ($it->isInfinite()) {
$lastOccurrence = $maxDate->getTimeStamp();
} else {
$end = $it->getDtEnd();
while ($it->valid() && $end < $maxDate) {
$end = $it->getDtEnd();
$it->next();
}
$lastOccurrence = $end->getTimeStamp();
}
}
}
if ($component->CLASS) {
$classification = CalDavBackend::CLASSIFICATION_PRIVATE;
switch ($component->CLASS->getValue()) {
case 'PUBLIC':
$classification = CalDavBackend::CLASSIFICATION_PUBLIC;
break;
case 'CONFIDENTIAL':
$classification = CalDavBackend::CLASSIFICATION_CONFIDENTIAL;
break;
}
}
return ['etag' => md5($calendarData), 'size' => strlen($calendarData), 'componentType' => $componentType, 'firstOccurence' => is_null($firstOccurrence) ? null : max(0, $firstOccurrence), 'lastOccurence' => $lastOccurrence, 'uid' => $uid, 'classification' => $classification];
}
示例11: _parse_freebusy
/**
* Parse the given vfreebusy component into an array representation
*/
private function _parse_freebusy($ve)
{
$this->freebusy = array('_type' => 'freebusy', 'periods' => array());
$seen = array();
foreach ($ve->children() as $prop) {
if (!$prop instanceof VObject\Property) {
continue;
}
switch ($prop->name) {
case 'CREATED':
case 'LAST-MODIFIED':
case 'DTSTAMP':
case 'DTSTART':
case 'DTEND':
$propmap = array('DTSTART' => 'start', 'DTEND' => 'end', 'CREATED' => 'created', 'LAST-MODIFIED' => 'changed', 'DTSTAMP' => 'changed');
$this->freebusy[$propmap[$prop->name]] = self::convert_datetime($prop);
break;
case 'ORGANIZER':
$this->freebusy['organizer'] = preg_replace('/^mailto:/i', '', $prop->getValue());
break;
case 'FREEBUSY':
// The freebusy component can hold more than 1 value, separated by commas.
$periods = explode(',', $prop->getValue());
$fbtype = strval($prop['FBTYPE']) ?: 'BUSY';
// skip dupes
if ($seen[$prop->getValue() . ':' . $fbtype]++) {
continue;
}
foreach ($periods as $period) {
// Every period is formatted as [start]/[end]. The start is an
// absolute UTC time, the end may be an absolute UTC time, or
// duration (relative) value.
list($busyStart, $busyEnd) = explode('/', $period);
$busyStart = VObject\DateTimeParser::parse($busyStart);
$busyEnd = VObject\DateTimeParser::parse($busyEnd);
if ($busyEnd instanceof \DateInterval) {
$tmp = clone $busyStart;
$tmp->add($busyEnd);
$busyEnd = $tmp;
}
if ($busyEnd && $busyEnd > $busyStart) {
$this->freebusy['periods'][] = array($busyStart, $busyEnd, $fbtype);
}
}
break;
case 'COMMENT':
$this->freebusy['comment'] = $prop->getValue();
}
}
return $this->freebusy;
}
示例12: importVObject
/**
* Import an event from a VObject
*
* @param Sabre\VObject\Component $vobject
* @param array $attributes Extra attributes to apply to the event. Raw values should be past. No input formatting is applied.
* @param boolean $dontSave. Don't save the event. WARNING. Event can't be fully imported this way because participants and exceptions need an ID. This option is useful if you want to display info about an ICS file.
* @param boolean $importExternal This should be switched on if importing happens from external ICS calendar.
* @return Event
*/
public function importVObject(Sabre\VObject\Component $vobject, $attributes = array(), $dontSave = false, $makeSureUserParticipantExists = false, $importExternal = false)
{
$uid = (string) $vobject->uid;
if (!empty($uid)) {
$this->uuid = $uid;
}
$this->name = (string) $vobject->summary;
if (empty($this->name)) {
$this->name = \GO::t('unnamed');
}
$dtstart = $vobject->dtstart ? $vobject->dtstart->getDateTime() : new \DateTime();
$dtend = $vobject->dtend ? $vobject->dtend->getDateTime() : new \DateTime();
$substractOnEnd = 0;
//funambol sends this special parameter
// if((string) $vobject->{"X-FUNAMBOL-ALLDAY"}=="1"){
// $this->all_day_event=1;
// }else
// {
$this->all_day_event = isset($vobject->dtstart['VALUE']) && $vobject->dtstart['VALUE'] == 'DATE' ? 1 : 0;
//ios sends start and end date at 00:00 hour
//DTEND;TZID=Europe/Amsterdam:20140121T000000
//DTSTART;TZID=Europe/Amsterdam:20140120T000000
if ($dtstart->format('Hi') == "0000" && $dtend->format('Hi') == "0000") {
$this->all_day_event = true;
$substractOnEnd = 60;
}
// }
if ($this->all_day_event) {
if ($dtstart->getTimezone()->getName() == 'UTC') {
$this->_utcToLocal($dtstart);
}
if ($dtend->getTimezone()->getName() == 'UTC') {
$this->_utcToLocal($dtend);
}
}
$this->start_time = intval($dtstart->format('U'));
$this->end_time = intval($dtend->format('U')) - $substractOnEnd;
if ($vobject->duration) {
$duration = \GO\Base\VObject\Reader::parseDuration($vobject->duration);
$this->end_time = $this->start_time + $duration;
}
if ($this->end_time <= $this->start_time) {
$this->end_time = $this->start_time + 3600;
}
if ($vobject->description) {
$this->description = (string) $vobject->description;
}
if ((string) $vobject->rrule != "") {
$rrule = new \GO\Base\Util\Icalendar\Rrule();
$rrule->readIcalendarRruleString($this->start_time, (string) $vobject->rrule);
$rrule->shiftDays(true);
$this->rrule = $rrule->createRrule();
$this->repeat_end_time = $rrule->until;
} else {
$this->rrule = "";
$this->repeat_end_time = 0;
}
if ($vobject->{"last-modified"}) {
$this->mtime = intval($vobject->{"last-modified"}->getDateTime()->format('U'));
}
if ($vobject->location) {
$this->location = (string) $vobject->location;
}
//var_dump($vobject->status);
if ($vobject->status) {
$status = (string) $vobject->status;
if ($this->isValidStatus($status)) {
$this->status = $status;
}
}
if (isset($vobject->class)) {
$this->private = strtoupper($vobject->class) != 'PUBLIC';
}
$this->reminder = 0;
// if($vobject->valarm && $vobject->valarm->trigger){
//
// $type = (string) $vobject->valarm->trigger["value"];
//
//
// if($type == "DURATION") {
// $duration = \GO\Base\VObject\Reader::parseDuration($vobject->valarm->trigger);
// if($duration>0){
// $this->reminder = $duration*-1;
// }
// }else
// {
// \GO::debug("WARNING: Ignoring unsupported reminder value of type: ".$type);
// }
//
if ($vobject->valarm && $vobject->valarm->trigger) {
$date = $vobject->valarm->getEffectiveTriggerTime();
//.........这里部分代码省略.........
示例13: getDateTimes
/**
* Returns multiple date-time values.
*
* @return \DateTime[]
*/
public function getDateTimes()
{
// Finding the timezone.
$tz = $this['TZID'];
if ($tz) {
$tz = TimeZoneUtil::getTimeZone((string) $tz, $this->root);
}
$dts = array();
foreach ($this->getParts() as $part) {
$dts[] = DateTimeParser::parse($part, $tz);
}
return $dts;
}