[prev in list] [next in list] [prev in thread] [next in thread]
List: busybox
Subject: [PATCH] date: accept 'yyyy-mm-dd HH' and 'yyyy-mm-dd' date formats.
From: Bartosz Golaszewski <bartekgola () gmail ! com>
Date: 2013-05-22 20:52:59
Message-ID: 1369255979-28812-1-git-send-email-bartekgola () gmail ! com
[Download RAW message or body]
This makes busybox date more compatible with coreutils and fixes a TODO
in libbb/time.c.
Signed-off-by: Bartosz Golaszewski <bartekgola@gmail.com>
---
libbb/time.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/libbb/time.c b/libbb/time.c
index 57e14b6..3d8305d 100644
--- a/libbb/time.c
+++ b/libbb/time.c
@@ -58,7 +58,6 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
return; /* don't fall through to end == ":" check */
} else
#endif
-//TODO: coreutils 6.9 also accepts "yyyy-mm-dd HH" (no minutes)
{
bb_error_msg_and_die(bb_msg_invalid_date, date_str);
}
@@ -68,7 +67,20 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
end = '\0';
/* else end != NUL and we error out */
}
- } else if (date_str[0] == '@') {
+ } else
+ /* yyyy-mm-dd HH */
+ if ((sscanf(date_str, "%u-%u-%u %u%c", &ptm->tm_year,
+ &ptm->tm_mon, &ptm->tm_mday,
+ &ptm->tm_hour, &end) >= 4) ||
+ /* yyyy-mm-dd */
+ (sscanf(date_str, "%u-%u-%u%c", &ptm->tm_year,
+ &ptm->tm_mon, &ptm->tm_mday, &end) >= 3))
+ {
+ ptm->tm_year -= 1900; /* Adjust years */
+ ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
+ } else
+ /* unix timestamp */
+ if (date_str[0] == '@') {
time_t t = bb_strtol(date_str + 1, NULL, 10);
if (!errno) {
struct tm *lt = localtime(&t);
--
1.7.10.4
_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic