Source
$pattern = $pattern_Y.'(-'.$pattern_m.'(-'.$pattern_d.'( +'.$pattern_H.'(:'.$pattern_i.'(:'.$pattern_s.')?)?)?)?)?';
<?php
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
/**
* A parser for absolute time in "YYYY[-MM[-DD]][ hh[:mm[:ss]]]" format.
*/
class CAbsoluteTimeParser extends CParser {
/**
* Full date in "YYYY-MM-DD hh:mm:ss" format.
*
* @var string $date
*/
private $date;
/**
* @var array $tokens
*/
private $tokens;
/**
* 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->tokens = [];
$this->length = 0;
$this->match = '';
$this->date = '';
$p = $pos;
if (!$this->parseAbsoluteTime($source, $p)) {
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;
}
/**
* Parse absolute time.
*
* @param string $source
* @param int $pos
*