annotate plugins/libcalendaring/lib/Sabre/VObject/Component/VEvent.php @ 4:888e774ee983

libcalendar plugin as distributed
author Charlie Root
date Sat, 13 Jan 2018 08:57:56 -0500
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
1 <?php
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
2
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
3 namespace Sabre\VObject\Component;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
4 use Sabre\VObject;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
5
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
6 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 * VEvent component
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 * This component contains some additional functionality specific for VEVENT's.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 * @author Evert Pot (http://evertpot.com/)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 class VEvent extends VObject\Component {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18 * Returns true or false depending on if the event falls in the specified
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 * time-range. This is used for filtering purposes.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 * The rules used to determine if an event falls within the specified
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 * time-range is based on the CalDAV specification.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 * @param \DateTime $start
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25 * @param \DateTime $end
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 * @return bool
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28 public function isInTimeRange(\DateTime $start, \DateTime $end) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30 if ($this->RRULE) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31 $it = new VObject\RecurrenceIterator($this);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32 $it->fastForward($start);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 // We fast-forwarded to a spot where the end-time of the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35 // recurrence instance exceeded the start of the requested
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 // time-range.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37 //
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 // If the starttime of the recurrence did not exceed the
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39 // end of the time range as well, we have a match.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40 return ($it->getDTStart() < $end && $it->getDTEnd() > $start);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
41
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
42 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
43
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 $effectiveStart = $this->DTSTART->getDateTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 if (isset($this->DTEND)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47 // The DTEND property is considered non inclusive. So for a 3 day
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 // event in july, dtstart and dtend would have to be July 1st and
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 // July 4th respectively.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50 //
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 // See:
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52 // http://tools.ietf.org/html/rfc5545#page-54
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 $effectiveEnd = $this->DTEND->getDateTime();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 } elseif (isset($this->DURATION)) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56 $effectiveEnd = clone $effectiveStart;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57 $effectiveEnd->add( VObject\DateTimeParser::parseDuration($this->DURATION) );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58 } elseif ($this->DTSTART->getDateType() == VObject\Property\DateTime::DATE) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59 $effectiveEnd = clone $effectiveStart;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60 $effectiveEnd->modify('+1 day');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 } else {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62 $effectiveEnd = clone $effectiveStart;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64 return (
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65 ($start <= $effectiveEnd) && ($end > $effectiveStart)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66 );
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70 }