]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/VObject/Component/VEvent.php
Merge branch 'master' of git://github.com/friendica/friendica-addons
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / VObject / Component / VEvent.php
1 <?php
2
3 /**
4  * VEvent component
5  *
6  * This component contains some additional functionality specific for VEVENT's.
7  *
8  * @package Sabre
9  * @subpackage VObject
10  * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
11  * @author Evert Pot (http://www.rooftopsolutions.nl/)
12  * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
13  */
14 class Sabre_VObject_Component_VEvent extends Sabre_VObject_Component {
15
16     /**
17      * Returns true or false depending on if the event falls in the specified
18      * time-range. This is used for filtering purposes.
19      *
20      * The rules used to determine if an event falls within the specified
21      * time-range is based on the CalDAV specification.
22      *
23      * @param DateTime $start
24      * @param DateTime $end
25      * @return bool
26      */
27     public function isInTimeRange(DateTime $start, DateTime $end) {
28
29         if ($this->RRULE) {
30             $it = new Sabre_VObject_RecurrenceIterator($this);
31             $it->fastForward($start);
32
33             // We fast-forwarded to a spot where the end-time of the
34             // recurrence instance exceeded the start of the requested
35             // time-range.
36             //
37             // If the starttime of the recurrence did not exceed the
38             // end of the time range as well, we have a match.
39             return ($it->getDTStart() < $end && $it->getDTEnd() > $start);
40
41         }
42
43         $effectiveStart = $this->DTSTART->getDateTime();
44         if (isset($this->DTEND)) {
45             $effectiveEnd = $this->DTEND->getDateTime();
46             // If this was an all-day event, we should just increase the
47             // end-date by 1. Otherwise the event will last until the second
48             // the date changed, by increasing this by 1 day the event lasts
49             // all of the last day as well.
50             if ($this->DTSTART->getDateType() == Sabre_VObject_Property_DateTime::DATE) {
51                 $effectiveEnd->modify('+1 day');
52             }
53         } elseif (isset($this->DURATION)) {
54             $effectiveEnd = clone $effectiveStart;
55             $effectiveEnd->add( Sabre_VObject_DateTimeParser::parseDuration($this->DURATION) );
56         } elseif ($this->DTSTART->getDateType() == Sabre_VObject_Property_DateTime::DATE) {
57             $effectiveEnd = clone $effectiveStart;
58             $effectiveEnd->modify('+1 day');
59         } else {
60             $effectiveEnd = clone $effectiveStart;
61         }
62         return (
63             ($start <= $effectiveEnd) && ($end > $effectiveStart)
64         );
65
66     }
67
68 }