/** * Helper method to correctly interpret an all-day date value */ public static function convert_datetime($prop, $as_array = false) { if (empty($prop)) { return $as_array ? array() : null; } else { if ($prop instanceof VObject\Property\MultiDateTime) { $dt = array(); $dateonly = $prop->getDateType() & VObject\Property\DateTime::DATE; foreach ($prop->getDateTimes() as $item) { $item->_dateonly = $dateonly; $dt[] = $item; } } else { if ($prop instanceof VObject\Property\ICalendar\DateTime) { //$dt = $prop->getDateTime(); $dt = new DateTime($prop->getValue()); } else { if ($prop instanceof VObject\Property && ($prop['VALUE'] == 'DATE' || $prop['VALUE'] == 'DATE-TIME')) { $dt = new DateTime($prop->getValue()); } else { if ($prop instanceof VObject\Property && $prop['VALUE'] == 'PERIOD') { $dt = array(); foreach (explode(',', $prop->getValue()) as $val) { try { list($start, $end) = explode('/', $val); list($type, $item) = VObject\Property\DateTime::parseData($start, $prop); $item->_dateonly = $type & VObject\Property\DateTime::DATE; $dt[] = $item; } catch (Exception $e) { // ignore single date parse errors } } } else { if ($prop instanceof DateTime) { $dt = $prop; } } } } } } // force return value to array if requested if ($as_array && !is_array($dt)) { $dt = empty($dt) ? array() : array($dt); } return $dt; }
/** * 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; }