From 4dfe97f9ae8de71ff6cb87f0a8ce2c5e7ca79c2e Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 25 Aug 2020 19:23:19 -0400 Subject: [PATCH] Kernel: Minor tweak to now() computation Make sure the expression is evaluated as time_t so that it does the right thing after 2037, and factor things so that the constants look less magical. --- Kernel/RTC.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Kernel/RTC.cpp b/Kernel/RTC.cpp index bced1bf661..47e64ae518 100644 --- a/Kernel/RTC.cpp +++ b/Kernel/RTC.cpp @@ -104,11 +104,8 @@ time_t now() ASSERT(year >= 2018); - return years_to_days_since_epoch(year) * 86400 - + day_of_year(year, month, day) * 86400 - + hour * 3600 - + minute * 60 - + second; + time_t days_since_epoch = years_to_days_since_epoch(year) + day_of_year(year, month, day); + return ((days_since_epoch * 24 + hour) * 60 + minute) * 60 + second; } }