[PATCH 5/6] common/date.c: Fix off-by-one error

Andrey Smirnov andrew.smirnov at gmail.com
Wed Jan 6 22:17:34 PST 2016


As per http://pubs.opengroup.org/onlinepubs/007908775/xsh/time.h.html
'tm_wday' is zero indexed with zero representing Sunday, this is also
corroborated by the code in rtc_time_to_tm() which used 4 to represent
Thursday.

Signed-off-by: Andrey Smirnov <andrew.smirnov at gmail.com>
---
 common/date.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/common/date.c b/common/date.c
index 2f23463..129192e 100644
--- a/common/date.c
+++ b/common/date.c
@@ -151,13 +151,13 @@ mktime (unsigned int year, unsigned int mon,

 const char *time_str(struct rtc_time *tm)
 {
-	const char *weekdays[] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
+	const char *weekdays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
 	const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
 				 "Sep", "Oct", "Nov", "Dec" };
 	static char buf[128];

 	sprintf(buf, "%s %02d %s %4d %02d:%02d:%02d",
-			weekdays[tm->tm_wday - 1],
+			weekdays[tm->tm_wday],
 			tm->tm_mday,
 			months[tm->tm_mon],
 			tm->tm_year + 1900,
--
2.5.0



More information about the barebox mailing list