Close: #18801 Jan-30 + 1m IS NOT Mar-2

Close: #18801 related to avoid this behaviour https://bugs.php.net/bug.php?id=74013
This commit is contained in:
javieralapps4up 2021-09-22 17:56:31 +02:00 committed by GitHub
parent 278ae34b5f
commit e74043d48e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -166,7 +166,33 @@ function dol_time_plus_duree($time, $duration_value, $duration_unit)
} else {
$date->add($interval);
}
//Change the behavior of PHP over data-interval when the result of this function is Feb 29 (non-leap years), 30 or Feb 31 (php returns March 1, 2 or 3 respectively)
if ($conf->global->MAIN_DATE_CHANGE_PHP_DATEINTERVAL_RESULT_FEBRUARY && $duration_unit == 'm') {
$timeyear = dol_print_date($time, '%Y');
$timemonth = dol_print_date($time, '%m');
$timetotalmonths = (($timeyear * 12) + $timemonth);
$monthsexpected = ($timetotalmonths + $duration_value);
$newtime = $date->getTimestamp();
$newtimeyear = dol_print_date($newtime, '%Y');
$newtimemonth = dol_print_date($newtime, '%m');
$newtimetotalmonths = (($newtimeyear * 12) + $newtimemonth);
if ($monthsexpected < $newtimetotalmonths) {
$newtimehours = dol_print_date($newtime, '%m');
$newtimemins = dol_print_date($newtime, '%m');
$newtimesecs = dol_print_date($newtime, '%m');
$datelim = dol_mktime($newtimehours, $newtimemins, $newtimesecs, $newtimemonth, 1, $newtimeyear);
$datelim -= (3600 * 24);
$date->setTimestamp($datelim);
}
}
return $date->getTimestamp();
}