mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 1/7] hwclock command: use format like the Linux tool does
Date: Mon, 14 Dec 2015 12:43:25 +0100	[thread overview]
Message-ID: <1450093411-13885-1-git-send-email-s.hauer@pengutronix.de> (raw)

Print three-letter abbreviations of the days and months.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/hwclock.c |  4 +---
 common/date.c      | 18 ++++++++++++++++++
 include/rtc.h      |  2 ++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/commands/hwclock.c b/commands/hwclock.c
index a1f5293..49569a9 100644
--- a/commands/hwclock.c
+++ b/commands/hwclock.c
@@ -138,9 +138,7 @@ static int do_hwclock(int argc, char *argv[])
 		snprintf(t, 12, "%lu", time);
 		setenv(env_name, t);
 	} else {
-		printf("%02d:%02d:%02d %02d-%02d-%04d\n",
-			tm.tm_hour, tm.tm_min, tm.tm_sec,
-			tm.tm_mday, tm.tm_mon + 1, tm.tm_year + 1900);
+		printf("%s\n", time_str(&tm));
 	}
 
 	return 0;
diff --git a/common/date.c b/common/date.c
index 6b6b7ab..33fb9ec 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[] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" };
+	const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug",
+				 "Sep", "Okt", "Nov", "Dec" };
+	static char buf[128];
+
+	sprintf(buf, "%s %02d %s %4d %02d:%02d:%02d",
+			weekdays[tm->tm_wday - 1],
+			tm->tm_mday,
+			months[tm->tm_mon],
+			tm->tm_year + 1900,
+			tm->tm_hour,
+			tm->tm_min,
+			tm->tm_sec);
+	return buf;
+}
\ No newline at end of file
diff --git a/include/rtc.h b/include/rtc.h
index e2414fb..600dc46 100644
--- a/include/rtc.h
+++ b/include/rtc.h
@@ -55,4 +55,6 @@ unsigned long mktime (unsigned int, unsigned int, unsigned int,
 
 extern struct rtc_device *rtc_lookup(const char *name);
 
+const char *time_str(struct rtc_time *tm);
+
 #endif	/* _RTC_H_ */
-- 
2.6.2


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

             reply	other threads:[~2015-12-14 11:43 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-14 11:43 Sascha Hauer [this message]
2015-12-14 11:43 ` [PATCH 2/7] hwclock command: forward return value of rtc_set_time Sascha Hauer
2015-12-14 11:43 ` [PATCH 3/7] rtc: Check time for validity before passing it to the rtc driver Sascha Hauer
2015-12-14 11:43 ` [PATCH 4/7] rtc: Fill in weekdays before setting time Sascha Hauer
2015-12-14 11:43 ` [PATCH 5/7] net: Add SNTP support Sascha Hauer
2015-12-14 11:43 ` [PATCH 6/7] hwclock: Allow to set hwclock from sntp Sascha Hauer
2015-12-14 11:43 ` [PATCH 7/7] rtc: Add Abracon driver Sascha Hauer
2015-12-14 11:54 ` [PATCH 1/7] hwclock command: use format like the Linux tool does Fabio Estevam
2015-12-14 12:02   ` Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1450093411-13885-1-git-send-email-s.hauer@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox