- Модуль: bizproc
- Путь к файлу: ~/bitrix/modules/bizproc/lib/Calc/Libs/DateLib.php
- Класс: BitrixBizprocCalcLibsDateLib
- Вызов: DateLib::callDateAdd
public function callDateAdd(Arguments $args)
{
$date = $args->getFirstSingle();
$offset = $this->getDateTimeOffset($date);
$date = $this->makeTimestamp($date);
$interval = $args->getSecondSingle();
if ($date === false || ($interval && !is_scalar($interval)))
{
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);
}