From bde14de86de4def78abef750f8ff5fbe2f9ff69d Mon Sep 17 00:00:00 2001 From: Daniel Peter Chokola Date: Sat, 25 Mar 2023 19:19:34 -0400 Subject: [PATCH] correct tm_year representation; include comments from `man 2 tm` --- Src/pcf8523.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/Src/pcf8523.c b/Src/pcf8523.c index cf2637e..ceb0dbe 100644 --- a/Src/pcf8523.c +++ b/Src/pcf8523.c @@ -109,13 +109,15 @@ time_t pcf8523_now(pcf8523_t *pcf8523) /* read current time */ pcf8253_read(pcf8523, PCF_REG_SECONDS, buf, 7); - t.tm_sec = bcd2bin(buf[0]); - t.tm_min = bcd2bin(buf[1]); - t.tm_hour = bcd2bin(buf[2]); - t.tm_mday = bcd2bin(buf[3]); - t.tm_wday = bcd2bin(buf[4]); /* ignored by mktime */ - t.tm_mon = bcd2bin(buf[5]); - t.tm_year = bcd2bin(buf[6]) + 2000; + t.tm_sec = bcd2bin(buf[0]); /* Seconds [0, 60] */ + t.tm_min = bcd2bin(buf[1]); /* Minutes [0, 59] */ + t.tm_hour = bcd2bin(buf[2]); /* Hour [0, 23] */ + t.tm_mday = bcd2bin(buf[3]); /* Day of the month [1, 31] */ + t.tm_wday = bcd2bin(buf[4]); /* Month [0, 11] (January = 0) */ + t.tm_yday = 0; /* Day of the year [0, 365] (Jan/01 = 0) */ + t.tm_mon = bcd2bin(buf[5]); /* Month [0, 11] (January = 0) */ + t.tm_year = bcd2bin(buf[6]) + 100; /* Year minus 1900 */ + /* tm_wday and tm_yday are ignored by mktime() */ time = mktime(&t); return time;