* [PATCH] rtc: fix rtc_time64_to_tm for 3477
@ 2018-02-28 21:50 Alexandre Belloni
0 siblings, 0 replies; only message in thread
From: Alexandre Belloni @ 2018-02-28 21:50 UTC (permalink / raw)
To: linux-rtc; +Cc: linux-kernel, Alexandre Belloni
The current correction for leap years will fail in 3477. 3476-12-31 being
3477-01-00 because this is 366 leap years after 1970 and 3477 isn't a leap
year.
Fix that by looping over until days is positive or zero.
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
---
drivers/rtc/rtc-lib.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/rtc/rtc-lib.c b/drivers/rtc/rtc-lib.c
index ad5bb21908e5..4a3c0f3aab14 100644
--- a/drivers/rtc/rtc-lib.c
+++ b/drivers/rtc/rtc-lib.c
@@ -65,7 +65,7 @@ void rtc_time64_to_tm(time64_t time, struct rtc_time *tm)
days -= (year - 1970) * 365
+ LEAPS_THRU_END_OF(year - 1)
- LEAPS_THRU_END_OF(1970 - 1);
- if (days < 0) {
+ while (days < 0) {
year -= 1;
days += 365 + is_leap_year(year);
}
--
2.16.2
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2018-02-28 21:50 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-28 21:50 [PATCH] rtc: fix rtc_time64_to_tm for 3477 Alexandre Belloni
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®