Exemplo n.º 1
0
 /**
  * Parses the internal data structure to figure out what the current date
  * and time is.
  *
  * The returned array contains two elements:
  *   1. A 'DateType' constant (as defined on this class), or null.
  *   2. A DateTime object (or null)
  *
  * @param string|null $propertyValue The string to parse (yymmdd or
  *                                   ymmddThhmmss, etc..)
  * @param \Sabre\VObject\Property|null $property The instance of the
  *                                              property we're parsing.
  * @return array
  */
 public static function parseData($propertyValue, VObject\Property $property = null)
 {
     if (is_null($propertyValue)) {
         return array(null, null);
     }
     $date = '(?P<year>[1-2][0-9]{3})(?P<month>[0-1][0-9])(?P<date>[0-3][0-9])';
     $time = '(?P<hour>[0-2][0-9])(?P<minute>[0-5][0-9])(?P<second>[0-5][0-9])';
     $regex = "/^{$date}(T{$time}(?P<isutc>Z)?)?\$/";
     if (!preg_match($regex, $propertyValue, $matches)) {
         throw new \InvalidArgumentException($propertyValue . ' is not a valid \\DateTime or Date string');
     }
     if (!isset($matches['hour'])) {
         // Date-only
         return array(self::DATE, new \DateTime($matches['year'] . '-' . $matches['month'] . '-' . $matches['date'] . ' 00:00:00', new \DateTimeZone('UTC')));
     }
     $dateStr = $matches['year'] . '-' . $matches['month'] . '-' . $matches['date'] . ' ' . $matches['hour'] . ':' . $matches['minute'] . ':' . $matches['second'];
     if (isset($matches['isutc'])) {
         $dt = new \DateTime($dateStr, new \DateTimeZone('UTC'));
         $dt->setTimeZone(new \DateTimeZone('UTC'));
         return array(self::UTC, $dt);
     }
     // Finding the timezone.
     $tzid = $property['TZID'];
     if (!$tzid) {
         // This was a floating time string. This implies we use the
         // timezone from date_default_timezone_set / date.timezone ini
         // setting.
         return array(self::LOCAL, new \DateTime($dateStr));
     }
     // To look up the timezone, we must first find the VCALENDAR component.
     $root = $property;
     while ($root->parent) {
         $root = $root->parent;
     }
     if ($root->name === 'VCALENDAR') {
         $tz = VObject\TimeZoneUtil::getTimeZone((string) $tzid, $root);
     } else {
         $tz = VObject\TimeZoneUtil::getTimeZone((string) $tzid);
     }
     $dt = new \DateTime($dateStr, $tz);
     $dt->setTimeZone($tz);
     return array(self::LOCALTZ, $dt);
 }
Exemplo n.º 2
0
 /**
  * Returns multiple date-time values.
  *
  * If no timezone information is known, because it's either an all-day
  * property or floating time, we will use the DateTimeZone argument to
  * figure out the exact date.
  *
  * @param DateTimeZone $timeZone
  *
  * @return DateTimeImmutable[]
  * @return \DateTime[]
  */
 function getDateTimes(DateTimeZone $timeZone = null)
 {
     // Does the property have a TZID?
     $tzid = $this['TZID'];
     if ($tzid) {
         $timeZone = TimeZoneUtil::getTimeZone((string) $tzid, $this->root);
     }
     $dts = [];
     foreach ($this->getParts() as $part) {
         $dts[] = DateTimeParser::parse($part, $timeZone);
     }
     return $dts;
 }
Exemplo n.º 3
0
 /**
  * Returns the PHP DateTimeZone for this VTIMEZONE component.
  *
  * If we can't accurately determine the timezone, this method will return
  * UTC.
  *
  * @return \DateTimeZone
  */
 function getTimeZone()
 {
     return VObject\TimeZoneUtil::getTimeZone((string) $this->TZID, $this->root);
 }
Exemplo n.º 4
0
 /**
  * Returns multiple date-time values.
  *
  * @return \DateTime[]
  */
 public function getDateTimes()
 {
     // Finding the timezone.
     $tz = $this['TZID'];
     if ($tz) {
         $tz = TimeZoneUtil::getTimeZone((string) $tz, $this->root);
     }
     $dts = array();
     foreach ($this->getParts() as $part) {
         $dts[] = DateTimeParser::parse($part, $tz);
     }
     return $dts;
 }