annotate plugins/libcalendaring/lib/Sabre/VObject/Property/MultiDateTime.php @ 38:ac106d4c8961 default tip

flip /etc/roundcube to point here
author Charlie Root
date Sat, 29 Dec 2018 05:39:53 -0500
parents 888e774ee983
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\Property;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
4
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
5 use Sabre\VObject;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
6
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
7 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
8 * Multi-DateTime property
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
9 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
10 * This element is used for iCalendar properties such as the EXDATE property.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
11 * It basically provides a few helper functions that make it easier to deal
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
12 * with these. It supports both DATE-TIME and DATE values.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
13 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
14 * In order to use this correctly, you must call setDateTimes and getDateTimes
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
15 * to retrieve and modify dates respectively.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
16 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
17 * If you use the 'value' or properties directly, this object does not keep
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
18 * reference and results might appear incorrectly.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
19 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
20 * @copyright Copyright (C) 2007-2013 fruux GmbH (https://fruux.com/).
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
21 * @author Evert Pot (http://evertpot.com/)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
22 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
23 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
24 class MultiDateTime extends VObject\Property {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
25
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
26 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
27 * DateTime representation
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
28 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
29 * @var DateTime[]
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
30 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
31 protected $dateTimes;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
32
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
33 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
34 * dateType
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
35 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
36 * This is one of the Sabre\VObject\Property\DateTime constants.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
37 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
38 * @var int
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
39 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
40 protected $dateType;
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 * Updates the value
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
44 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
45 * @param array $dt Must be an array of DateTime objects.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
46 * @param int $dateType
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
47 * @return void
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
48 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
49 public function setDateTimes(array $dt, $dateType = VObject\Property\DateTime::LOCALTZ) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
50
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
51 foreach($dt as $i)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
52 if (!$i instanceof \DateTime)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
53 throw new \InvalidArgumentException('You must pass an array of DateTime objects');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
54
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
55 $this->offsetUnset('VALUE');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
56 $this->offsetUnset('TZID');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
57 switch($dateType) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
58
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
59 case DateTime::LOCAL :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
60 $val = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
61 foreach($dt as $i) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
62 $val[] = $i->format('Ymd\\THis');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
63 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
64 $this->setValue(implode(',',$val));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
65 $this->offsetSet('VALUE','DATE-TIME');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
66 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
67 case DateTime::UTC :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
68 $val = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
69 foreach($dt as $i) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
70 $i->setTimeZone(new \DateTimeZone('UTC'));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
71 $val[] = $i->format('Ymd\\THis\\Z');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
72 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
73 $this->setValue(implode(',',$val));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
74 $this->offsetSet('VALUE','DATE-TIME');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
75 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
76 case DateTime::LOCALTZ :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
77 $val = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
78 foreach($dt as $i) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
79 $val[] = $i->format('Ymd\\THis');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
80 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
81 $this->setValue(implode(',',$val));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
82 $this->offsetSet('VALUE','DATE-TIME');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
83 $this->offsetSet('TZID', $dt[0]->getTimeZone()->getName());
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
84 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
85 case DateTime::DATE :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
86 $val = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
87 foreach($dt as $i) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
88 $val[] = $i->format('Ymd');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
89 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
90 $this->setValue(implode(',',$val));
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
91 $this->offsetSet('VALUE','DATE');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
92 break;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
93 default :
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
94 throw new \InvalidArgumentException('You must pass a valid dateType constant');
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
95
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
96 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
97 $this->dateTimes = $dt;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
98 $this->dateType = $dateType;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
99
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
100 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
101
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
102 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
103 * Returns the current DateTime value.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
104 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
105 * If no value was set, this method returns null.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
106 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
107 * @return array|null
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
108 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
109 public function getDateTimes() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
110
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
111 if ($this->dateTimes)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
112 return $this->dateTimes;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
113
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
114 $dts = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
115
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
116 if (!$this->value) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
117 $this->dateTimes = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
118 $this->dateType = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
119 return null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
120 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
121
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
122 foreach(explode(',',$this->value) as $val) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
123 list(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
124 $type,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
125 $dt
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
126 ) = DateTime::parseData($val, $this);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
127 $dts[] = $dt;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
128 $this->dateType = $type;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
129 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
130 $this->dateTimes = $dts;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
131 return $this->dateTimes;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
132
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
133 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
134
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
135 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
136 * Returns the type of Date format.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
137 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
138 * This method returns one of the format constants. If no date was set,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
139 * this method will return null.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
140 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
141 * @return int|null
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
142 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
143 public function getDateType() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
144
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
145 if ($this->dateType)
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
146 return $this->dateType;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
147
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
148 if (!$this->value) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
149 $this->dateTimes = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
150 $this->dateType = null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
151 return null;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
152 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
153
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
154 $dts = array();
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
155 foreach(explode(',',$this->value) as $val) {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
156 list(
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
157 $type,
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
158 $dt
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
159 ) = DateTime::parseData($val, $this);
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
160 $dts[] = $dt;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
161 $this->dateType = $type;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
162 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
163 $this->dateTimes = $dts;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
164 return $this->dateType;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
165
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
166 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
167
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
168 /**
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
169 * This method will return true, if the property had a date and a time, as
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
170 * opposed to only a date.
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
171 *
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
172 * @return bool
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
173 */
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
174 public function hasTime() {
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
175
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
176 return $this->getDateType()!==DateTime::DATE;
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
177
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
178 }
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
179
888e774ee983 libcalendar plugin as distributed
Charlie Root
parents:
diff changeset
180 }