3 namespace Sabre\VObject\Property;
8 * Multi-DateTime property
10 * This element is used for iCalendar properties such as the EXDATE property.
11 * It basically provides a few helper functions that make it easier to deal
12 * with these. It supports both DATE-TIME and DATE values.
14 * In order to use this correctly, you must call setDateTimes and getDateTimes
15 * to retrieve and modify dates respectively.
17 * If you use the 'value' or properties directly, this object does not keep
18 * reference and results might appear incorrectly.
20 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
21 * @author Evert Pot (http://www.rooftopsolutions.nl/)
22 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
24 class MultiDateTime extends VObject\Property {
27 * DateTime representation
36 * This is one of the Sabre\VObject\Property\DateTime constants.
45 * @param array $dt Must be an array of DateTime objects.
46 * @param int $dateType
49 public function setDateTimes(array $dt, $dateType = VObject\Property\DateTime::LOCALTZ) {
52 if (!$i instanceof \DateTime)
53 throw new \InvalidArgumentException('You must pass an array of DateTime objects');
55 $this->offsetUnset('VALUE');
56 $this->offsetUnset('TZID');
59 case DateTime::LOCAL :
62 $val[] = $i->format('Ymd\\THis');
64 $this->setValue(implode(',',$val));
65 $this->offsetSet('VALUE','DATE-TIME');
70 $i->setTimeZone(new \DateTimeZone('UTC'));
71 $val[] = $i->format('Ymd\\THis\\Z');
73 $this->setValue(implode(',',$val));
74 $this->offsetSet('VALUE','DATE-TIME');
76 case DateTime::LOCALTZ :
79 $val[] = $i->format('Ymd\\THis');
81 $this->setValue(implode(',',$val));
82 $this->offsetSet('VALUE','DATE-TIME');
83 $this->offsetSet('TZID', $dt[0]->getTimeZone()->getName());
88 $val[] = $i->format('Ymd');
90 $this->setValue(implode(',',$val));
91 $this->offsetSet('VALUE','DATE');
94 throw new \InvalidArgumentException('You must pass a valid dateType constant');
97 $this->dateTimes = $dt;
98 $this->dateType = $dateType;
103 * Returns the current DateTime value.
105 * If no value was set, this method returns null.
109 public function getDateTimes() {
111 if ($this->dateTimes)
112 return $this->dateTimes;
117 $this->dateTimes = null;
118 $this->dateType = null;
122 foreach(explode(',',$this->value) as $val) {
126 ) = DateTime::parseData($val, $this);
128 $this->dateType = $type;
130 $this->dateTimes = $dts;
131 return $this->dateTimes;
136 * Returns the type of Date format.
138 * This method returns one of the format constants. If no date was set,
139 * this method will return null.
143 public function getDateType() {
146 return $this->dateType;
149 $this->dateTimes = null;
150 $this->dateType = null;
155 foreach(explode(',',$this->value) as $val) {
159 ) = DateTime::parseData($val, $this);
161 $this->dateType = $type;
163 $this->dateTimes = $dts;
164 return $this->dateType;