]> git.proxmox.com Git - pve-common.git/commitdiff
fix #1682: handle relative years absolutely
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Wed, 28 Feb 2018 09:42:56 +0000 (10:42 +0100)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Wed, 7 Mar 2018 10:35:28 +0000 (11:35 +0100)
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>
src/PVE/CalendarEvent.pm

index 77b60080302c773bbb86a45aec43d760648ca514..3c08eb06899d2f2134eee74f84a6239df802353c 100644 (file)
@@ -177,9 +177,13 @@ sub compute_next_event {
 
        if ($utc) {
            (undef, $min, $hour, $mday, $mon, $year, $wday) = gmtime($last);
 
        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);
            $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);
        }
 
            $startofday = timelocal(0, 0, 0, $mday, $mon, $year);
        }