public function __construct($date = null, $dtz = null, $is_date = null) { if (!isset(self::$UTCzone)) { self::$UTCzone = new RepeatRuleTimeZone('UTC'); } $this->is_date = false; if (isset($is_date)) { $this->is_date = $is_date; } if (!isset($date)) { $date = date('Ymd\\THis'); // Floating $dtz = self::$UTCzone; } $this->tzid = null; if (is_object($date) && method_exists($date, 'GetParameterValue')) { $tzid = $date->GetParameterValue('TZID'); $actual_date = $date->Value(); if (isset($tzid)) { $dtz = new RepeatRuleTimeZone($tzid); $this->tzid = $dtz->tzid(); } else { $dtz = self::$UTCzone; if (substr($actual_date, -1) == 'Z') { $this->tzid = 'UTC'; $actual_date = substr($actual_date, 0, strlen($actual_date) - 1); } } if (strlen($actual_date) == 8) { // We allow dates without VALUE=DATE parameter, but we don't create them like that $this->is_date = true; } // $value_type = $date->GetParameterValue('VALUE'); // if ( isset($value_type) && $value_type == 'DATE' ) $this->is_date = true; $date = $actual_date; if (DEBUG_RRULE) { printf("Date%s property%s: %s%s\n", $this->is_date ? "" : "Time", isset($this->tzid) ? ' with timezone' : '', $date, isset($this->tzid) ? ' in ' . $this->tzid : ''); } } elseif (preg_match('/;TZID= ([^:;]+) (?: ;.* )? : ( \\d{8} (?:T\\d{6})? ) (Z)?/x', $date, $matches)) { $date = $matches[2]; $this->is_date = strlen($date) == 8; if (isset($matches[3]) && $matches[3] == 'Z') { $dtz = self::$UTCzone; $this->tzid = 'UTC'; } else { if (isset($matches[1]) && $matches[1] != '') { $dtz = new RepeatRuleTimeZone($matches[1]); $this->tzid = $dtz->tzid(); } else { $dtz = self::$UTCzone; $this->tzid = null; } } if (DEBUG_RRULE) { printf("Date%s property%s: %s%s\n", $this->is_date ? "" : "Time", isset($this->tzid) ? ' with timezone' : '', $date, isset($this->tzid) ? ' in ' . $this->tzid : ''); } } elseif (($dtz === null || $dtz == '') && preg_match('{;VALUE=DATE (?:;[^:]+) : ((?:[12]\\d{3}) (?:0[1-9]|1[012]) (?:0[1-9]|[12]\\d|3[01]Z?) )$}x', $date, $matches)) { $this->is_date = true; $date = $matches[1]; // Floating $dtz = self::$UTCzone; $this->tzid = null; if (DEBUG_RRULE) { printf("Floating Date value: %s\n", $date); } } elseif ($dtz === null || $dtz == '') { $dtz = self::$UTCzone; if (preg_match('/(\\d{8}(T\\d{6})?)(Z?)/', $date, $matches)) { $date = $matches[1]; $this->tzid = $matches[3] == 'Z' ? 'UTC' : null; } $this->is_date = strlen($date) == 8; if (DEBUG_RRULE) { printf("Date%s value with timezone: %s in %s\n", $this->is_date ? "" : "Time", $date, $this->tzid); } } elseif (is_string($dtz)) { $dtz = new RepeatRuleTimeZone($dtz); $this->tzid = $dtz->tzid(); $type = gettype($date); if (DEBUG_RRULE) { printf("Date%s {$type} with timezone: %s in %s\n", $this->is_date ? "" : "Time", $date, $this->tzid); } } else { $this->tzid = $dtz->getName(); $type = gettype($date); if (DEBUG_RRULE) { printf("Date%s {$type} with timezone: %s in %s\n", $this->is_date ? "" : "Time", $date, $this->tzid); } } parent::__construct($date, $dtz); if (isset($is_date)) { $this->is_date = $is_date; } return $this; }