offsetUnset('VALUE'); $this->offsetUnset('TZID'); switch($dateType) { case DateTime::LOCAL : $val = array(); foreach($dt as $i) { $val[] = $i->format('Ymd\\THis'); } $this->setValue(implode(',',$val)); $this->offsetSet('VALUE','DATE-TIME'); break; case DateTime::UTC : $val = array(); foreach($dt as $i) { $i->setTimeZone(new \DateTimeZone('UTC')); $val[] = $i->format('Ymd\\THis\\Z'); } $this->setValue(implode(',',$val)); $this->offsetSet('VALUE','DATE-TIME'); break; case DateTime::LOCALTZ : $val = array(); foreach($dt as $i) { $val[] = $i->format('Ymd\\THis'); } $this->setValue(implode(',',$val)); $this->offsetSet('VALUE','DATE-TIME'); $this->offsetSet('TZID', $dt[0]->getTimeZone()->getName()); break; case DateTime::DATE : $val = array(); foreach($dt as $i) { $val[] = $i->format('Ymd'); } $this->setValue(implode(',',$val)); $this->offsetSet('VALUE','DATE'); break; default : throw new \InvalidArgumentException('You must pass a valid dateType constant'); } $this->dateTimes = $dt; $this->dateType = $dateType; } /** * Returns the current DateTime value. * * If no value was set, this method returns null. * * @return array|null */ public function getDateTimes() { if ($this->dateTimes) return $this->dateTimes; $dts = array(); if (!$this->value) { $this->dateTimes = null; $this->dateType = null; return null; } foreach(explode(',',$this->value) as $val) { list( $type, $dt ) = DateTime::parseData($val, $this); $dts[] = $dt; $this->dateType = $type; } $this->dateTimes = $dts; return $this->dateTimes; } /** * Returns the type of Date format. * * This method returns one of the format constants. If no date was set, * this method will return null. * * @return int|null */ public function getDateType() { if ($this->dateType) return $this->dateType; if (!$this->value) { $this->dateTimes = null; $this->dateType = null; return null; } $dts = array(); foreach(explode(',',$this->value) as $val) { list( $type, $dt ) = DateTime::parseData($val, $this); $dts[] = $dt; $this->dateType = $type; } $this->dateTimes = $dts; return $this->dateType; } /** * This method will return true, if the property had a date and a time, as * opposed to only a date. * * @return bool */ public function hasTime() { return $this->getDateType()!==DateTime::DATE; } }