From 7c5eeae56a3c05a0562efb62accf5c69058b8736 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20Gr=C3=BCnbichler?= Date: Wed, 28 Feb 2018 10:42:56 +0100 Subject: [PATCH] fix #1682: handle relative years absolutely MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- src/PVE/CalendarEvent.pm | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/PVE/CalendarEvent.pm b/src/PVE/CalendarEvent.pm index 77b6008..3c08eb0 100644 --- a/src/PVE/CalendarEvent.pm +++ b/src/PVE/CalendarEvent.pm @@ -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); }