- Модуль: bizproc
- Путь к файлу: ~/bitrix/modules/bizproc/classes/general/calc.php
- Класс: CBPCalc
- Вызов: CBPCalc::functionDateAdd
private function functionDateAdd($args)
{
if (!is_array($args))
{
$args = [$args];
}
$ar = $this->ArrgsToArray($args);
$date = array_shift($ar);
$offset = $this->getDateTimeOffset($date);
$interval = array_shift($ar);
if (($date = $this->makeTimestamp($date)) === false)
{
return null;
}
if (empty($interval))
{
return $date; // new BizprocBaseTypeValueDateTime($date, $offset);
}
// 1Y2M3D4H5I6S, -4 days 5 hours, 1month, 5h
$interval = trim($interval);
$bMinus = false;
if (mb_substr($interval, 0, 1) === "-")
{
$interval = mb_substr($interval, 1);
$bMinus = true;
}
static $arMap = ["y" => "YYYY", "year" => "YYYY", "years" => "YYYY",
"m" => "MM", "month" => "MM", "months" => "MM",
"d" => "DD", "day" => "DD", "days" => "DD",
"h" => "HH", "hour" => "HH", "hours" => "HH",
"i" => "MI", "min" => "MI", "minute" => "MI", "minutes" => "MI",
"s" => "SS", "sec" => "SS", "second" => "SS", "seconds" => "SS",
];
$arInterval = [];
while (preg_match('/s*([d]+)s*([a-z]+)s*/i', $interval, $match))
{
$match2 = mb_strtolower($match[2]);
if (array_key_exists($match2, $arMap))
{
$arInterval[$arMap[$match2]] = ($bMinus ? -intval($match[1]) : intval($match[1]));
}
$p = mb_strpos($interval, $match[0]);
$interval = mb_substr($interval, $p + mb_strlen($match[0]));
}
$date += $offset; // to server
$newDate = AddToTimeStamp($arInterval, $date);
$newDate -= $offset; // to user timezone
return new BizprocBaseTypeValueDateTime($newDate, $offset);
}