Clean code for param of dol_stringtotime()

This commit is contained in:
Laurent Destailleur 2022-02-11 14:07:10 +01:00
parent 32af067e1e
commit 89ffe5baba

View File

@ -364,8 +364,8 @@ function dolSqlDateFilter($datefield, $day_date, $month_date, $year_date, $exclu
* YYYY-MM-DDTHH:MM:SSZ (RFC3339) * YYYY-MM-DDTHH:MM:SSZ (RFC3339)
* DD/MM/YY or DD/MM/YYYY (deprecated) * DD/MM/YY or DD/MM/YYYY (deprecated)
* DD/MM/YY HH:MM:SS or DD/MM/YYYY HH:MM:SS (deprecated) * DD/MM/YY HH:MM:SS or DD/MM/YYYY HH:MM:SS (deprecated)
* @param int $gm 1 =Input date is GM date, * @param int|string $gm 'gmt' or 1 =Input date is GM date,
* 0 =Input date is local date using PHP server timezone * 'tzserver' or 0 =Input date is date using PHP server timezone
* @return int Date as a timestamp * @return int Date as a timestamp
* 19700101020000 -> 7200 with gm=1 * 19700101020000 -> 7200 with gm=1
* 19700101000000 -> 0 with gm=1 * 19700101000000 -> 0 with gm=1
@ -408,7 +408,14 @@ function dol_stringtotime($string, $gm = 1)
$string = preg_replace('/([^0-9])/i', '', $string); $string = preg_replace('/([^0-9])/i', '', $string);
$tmp = $string.'000000'; $tmp = $string.'000000';
$date = dol_mktime(substr($tmp, 8, 2), substr($tmp, 10, 2), substr($tmp, 12, 2), substr($tmp, 4, 2), substr($tmp, 6, 2), substr($tmp, 0, 4), ($gm ? 1 : 0)); // Clean $gm
if ($gm === 1) {
$gm = 'gmt';
} elseif (empty($gm) || $gm === 'tzserver') {
$gm = 'tzserver';
}
$date = dol_mktime(substr($tmp, 8, 2), substr($tmp, 10, 2), substr($tmp, 12, 2), substr($tmp, 4, 2), substr($tmp, 6, 2), substr($tmp, 0, 4), $gm);
return $date; return $date;
} }