mirror of
https://git.proxmox.com/git/pve-common
synced 2025-08-04 16:31:04 +00:00
fix #1682: handle relative years absolutely
the timegm(gmtime()) and timelocal(localtime(()) constructs are problematic in the following case: - $last is such that $year gets set to a two-digit value (e.g., the referred to timestamp is somewhere in the range of 1900-1999) - the current date is such that the value of $year gets interpreted wrongly (e.g., anything other than 1950). the exact breakage depends on the actual current date AND value of $last, since localtime/gmtime will interpret two-digit years as (perldoc Time::Local): [...] shorthand for years in the rolling "current century," defined as 50 years on either side of the current year. Thus, today, in 1999, 0 would refer to 2000, and 45 to 2045, but 55 would refer to 1955. Twenty years from now, 55 would instead refer to 2055. fix it by adding 1900 to force 4-digit $year values, as the localtime documentation suggests. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
c44ec0f663
commit
7c5eeae56a
@ -177,9 +177,13 @@ sub compute_next_event {
|
||||
|
||||
if ($utc) {
|
||||
(undef, $min, $hour, $mday, $mon, $year, $wday) = gmtime($last);
|
||||
# gmtime and timegm interpret two-digit years differently
|
||||
$year += 1900;
|
||||
$startofday = timegm(0, 0, 0, $mday, $mon, $year);
|
||||
} else {
|
||||
(undef, $min, $hour, $mday, $mon, $year, $wday) = localtime($last);
|
||||
# localtime and timelocal interpret two-digit years differently
|
||||
$year += 1900;
|
||||
$startofday = timelocal(0, 0, 0, $mday, $mon, $year);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user