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