[PATCH] [RFC] parse_date: support another date input format

Alexander Shishkin virtuoso at slind.org
Mon Mar 22 14:09:04 UTC 2010


Sorry for the previous one, mondays ain't no good for me.

"%b %d %T %Y" is actually supported by the GNU date and there are scripts
out there using it:

$ date -d "Jan 7 00:00:00 2010"
Thu Jan  7 00:00:00 UTC 2010

function                                             old     new   delta
parse_datestr                                        638     685     +47
.rodata                                            42153   42165     +12
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 2/0 up/down: 59/0)               Total: 59 bytes

Signed-off-by: Alexander Shishkin <virtuoso at slind.org>
---
 libbb/time.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)

diff --git a/libbb/time.c b/libbb/time.c
index 45ae6f3..3a82644 100644
--- a/libbb/time.c
+++ b/libbb/time.c
@@ -46,6 +46,13 @@ void FAST_FUNC parse_datestr(const char *date_str, struct tm *ptm)
 					&end) >= 5) {
 			ptm->tm_year -= 1900; /* Adjust years */
 			ptm->tm_mon -= 1; /* Adjust month from 1-12 to 0-11 */
+		} else
+		/* month_name d HH:MM:SS
+		 * this is supported by the GNU make */
+		if (isalpha(date_str[0])) {
+			char *res = strptime(date_str, "%b %d %T %Y", ptm);
+			if (!res || *res)
+				bb_error_msg_and_die(bb_msg_invalid_date, date_str);
 //TODO: coreutils 6.9 also accepts "yyyy-mm-dd HH" (no minutes)
 		} else {
 			bb_error_msg_and_die(bb_msg_invalid_date, date_str);
-- 
1.6.3.3



More information about the busybox mailing list