relative_time_parser = new CRelativeTimeParser(); $this->absolute_time_parser = new CAbsoluteTimeParser(); } /** * Parse the given period. * * @param string $source Source string that needs to be parsed. * @param int $pos Position offset. */ public function parse($source, $pos = 0) { $this->length = 0; $this->match = ''; $this->time_type = self::ZBX_TIME_UNKNOWN; $p = $pos; if ($this->relative_time_parser->parse($source, $p) != self::PARSE_FAIL) { $p += $this->relative_time_parser->getLength(); $this->time_type = self::ZBX_TIME_RELATIVE; } elseif ($this->absolute_time_parser->parse($source, $p) != self::PARSE_FAIL) { $p += $this->absolute_time_parser->getLength(); $this->time_type = self::ZBX_TIME_ABSOLUTE; } else { return self::PARSE_FAIL; } $this->length = $p - $pos; $this->match = substr($source, $pos, $this->length); return isset($source[$p]) ? self::PARSE_SUCCESS_CONT : self::PARSE_SUCCESS; } public function getTimeType() { return $this->time_type; } /** * Get DateTime object with its value set to either start or end of the period derived from the date/time specified. * * @param $is_start * @param DateTimeZone|null $timezone * * @return DateTime|null */ public function getDateTime($is_start, DateTimeZone $timezone = null): ?DateTime { switch ($this->time_type) { case self::ZBX_TIME_ABSOLUTE: return $this->absolute_time_parser->getDateTime($is_start, $timezone); case self::ZBX_TIME_RELATIVE: return $this->relative_time_parser->getDateTime($is_start, $timezone); default: return null; } } }