4 * Multi-DateTime property
6 * This element is used for iCalendar properties such as the EXDATE property.
7 * It basically provides a few helper functions that make it easier to deal
8 * with these. It supports both DATE-TIME and DATE values.
10 * In order to use this correctly, you must call setDateTimes and getDateTimes
11 * to retrieve and modify dates respectively.
13 * If you use the 'value' or properties directly, this object does not keep
14 * reference and results might appear incorrectly.
18 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
19 * @author Evert Pot (http://www.rooftopsolutions.nl/)
20 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
22 class Sabre_VObject_Property_MultiDateTime extends Sabre_VObject_Property {
25 * DateTime representation
34 * This is one of the Sabre_VObject_Property_DateTime constants.
43 * @param array $dt Must be an array of DateTime objects.
44 * @param int $dateType
47 public function setDateTimes(array $dt, $dateType = Sabre_VObject_Property_DateTime::LOCALTZ) {
50 if (!$i instanceof DateTime)
51 throw new InvalidArgumentException('You must pass an array of DateTime objects');
53 $this->offsetUnset('VALUE');
54 $this->offsetUnset('TZID');
57 case Sabre_VObject_Property_DateTime::LOCAL :
60 $val[] = $i->format('Ymd\\THis');
62 $this->setValue(implode(',',$val));
63 $this->offsetSet('VALUE','DATE-TIME');
65 case Sabre_VObject_Property_DateTime::UTC :
68 $i->setTimeZone(new DateTimeZone('UTC'));
69 $val[] = $i->format('Ymd\\THis\\Z');
71 $this->setValue(implode(',',$val));
72 $this->offsetSet('VALUE','DATE-TIME');
74 case Sabre_VObject_Property_DateTime::LOCALTZ :
77 $val[] = $i->format('Ymd\\THis');
79 $this->setValue(implode(',',$val));
80 $this->offsetSet('VALUE','DATE-TIME');
81 $this->offsetSet('TZID', $dt[0]->getTimeZone()->getName());
83 case Sabre_VObject_Property_DateTime::DATE :
86 $val[] = $i->format('Ymd');
88 $this->setValue(implode(',',$val));
89 $this->offsetSet('VALUE','DATE');
92 throw new InvalidArgumentException('You must pass a valid dateType constant');
95 $this->dateTimes = $dt;
96 $this->dateType = $dateType;
101 * Returns the current DateTime value.
103 * If no value was set, this method returns null.
107 public function getDateTimes() {
109 if ($this->dateTimes)
110 return $this->dateTimes;
115 $this->dateTimes = null;
116 $this->dateType = null;
120 foreach(explode(',',$this->value) as $val) {
124 ) = Sabre_VObject_Property_DateTime::parseData($val, $this);
126 $this->dateType = $type;
128 $this->dateTimes = $dts;
129 return $this->dateTimes;
134 * Returns the type of Date format.
136 * This method returns one of the format constants. If no date was set,
137 * this method will return null.
141 public function getDateType() {
144 return $this->dateType;
147 $this->dateTimes = null;
148 $this->dateType = null;
153 foreach(explode(',',$this->value) as $val) {
157 ) = Sabre_VObject_Property_DateTime::parseData($val, $this);
159 $this->dateType = $type;
161 $this->dateTimes = $dts;
162 return $this->dateType;