]> git.mxchange.org Git - friendica-addons.git/blob - dav/SabreDAV/lib/Sabre/VObject/Component/VTodo.php
Move friendica-specific parts into an own subdirectory
[friendica-addons.git] / dav / SabreDAV / lib / Sabre / VObject / Component / VTodo.php
1 <?php
2
3 /**
4  * VTodo component
5  *
6  * This component contains some additional functionality specific for VTODOs.
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_VTodo 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         $dtstart = isset($this->DTSTART)?$this->DTSTART->getDateTime():null;
30         $duration = isset($this->DURATION)?Sabre_VObject_DateTimeParser::parseDuration($this->DURATION):null;
31         $due = isset($this->DUE)?$this->DUE->getDateTime():null;
32         $completed = isset($this->COMPLETED)?$this->COMPLETED->getDateTime():null;
33         $created = isset($this->CREATED)?$this->CREATED->getDateTime():null;
34
35         if ($dtstart) {
36             if ($duration) {
37                 $effectiveEnd = clone $dtstart;
38                 $effectiveEnd->add($duration);
39                 return $start <= $effectiveEnd && $end > $dtstart;
40             } elseif ($due) {
41                 return
42                     ($start < $due || $start <= $dtstart) &&
43                     ($end > $dtstart || $end >= $due);
44             } else {
45                 return $start <= $dtstart && $end > $dtstart;
46             }
47         }
48         if ($due) {
49             return ($start < $due && $end >= $due);
50         }
51         if ($completed && $created) {
52             return
53                 ($start <= $created || $start <= $completed) &&
54                 ($end >= $created || $end >= $completed);
55         }
56         if ($completed) {
57             return ($start <= $completed && $end >= $completed);
58         }
59         if ($created) {
60             return ($end > $created);
61         }
62         return true;
63
64     }
65
66 }