From 6eb5d78419299d01f500140dd9400a68725e142b Mon Sep 17 00:00:00 2001 From: Sascha Hauer Date: Fri, 11 Dec 2015 12:04:41 +0100 Subject: hwclock command: use format like the Linux tool does Print three-letter abbreviations of the days and months. With a fixup by Andrey Smirnov: | common/date.c: Fix off-by-one error | | 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 Signed-off-by: Sascha Hauer --- common/date.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'common/date.c') diff --git a/common/date.c b/common/date.c index 6b6b7ab495..129192e232 100644 --- a/common/date.c +++ b/common/date.c @@ -148,3 +148,21 @@ mktime (unsigned int year, unsigned int mon, )*60 + min /* now have minutes */ )*60 + sec; /* finally seconds */ } + +const char *time_str(struct rtc_time *tm) +{ + 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], + tm->tm_mday, + months[tm->tm_mon], + tm->tm_year + 1900, + tm->tm_hour, + tm->tm_min, + tm->tm_sec); + return buf; +} -- cgit v1.2.3