diff options
author | Elliott Hughes <enh@google.com> | 2020-08-27 09:37:25 -0700 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2020-08-27 22:58:43 -0500 |
commit | d1a446687a9c1072c254beffceda1c4d724035bc (patch) | |
tree | 6294d0aaa7fdb9d9e7e203f62c3387bb212f38d3 | |
parent | 314917a5c522a463d45a007702cf29a39f4028b4 (diff) | |
download | toybox-d1a446687a9c1072c254beffceda1c4d724035bc.tar.gz |
xparsedate: support default date(1) output format.
This round trip occurs in practice with $KBUILD_BUILD_TIMESTAMP in
kernel builds.
-rw-r--r-- | lib/xwrap.c | 1 | ||||
-rw-r--r-- | tests/date.test | 4 |
2 files changed, 5 insertions, 0 deletions
diff --git a/lib/xwrap.c b/lib/xwrap.c index 1bc929f1..cf7fc42a 100644 --- a/lib/xwrap.c +++ b/lib/xwrap.c @@ -967,6 +967,7 @@ void xparsedate(char *str, time_t *t, unsigned *nano, int endian) // Formats with seconds come first. Posix can't agree on whether 12 digits // has year before (touch -t) or year after (date), so support both. char *s = str, *p, *oldtz = 0, *formats[] = {"%Y-%m-%d %T", "%Y-%m-%dT%T", + "%a %b %e %H:%M:%S %Z %Y", // date(1) output format in POSIX/C locale. "%H:%M:%S", "%Y-%m-%d %H:%M", "%Y-%m-%d", "%H:%M", "%m%d%H%M", endian ? "%m%d%H%M%y" : "%y%m%d%H%M", endian ? "%m%d%H%M%C%y" : "%C%y%m%d%H%M"}; diff --git a/tests/date.test b/tests/date.test index 7dd125d7..9240131a 100644 --- a/tests/date.test +++ b/tests/date.test @@ -73,3 +73,7 @@ testing "tz +08" \ "date -u -d 2020-08-01T12:34:56+08" "Sat Aug 1 04:34:56 UTC 2020\n" "" "" testing "tz +008" \ "date -u -d 2020-08-01T12:34:56+008" "Sat Aug 1 12:26:56 UTC 2020\n" "" "" + +# Can we parse date's own output format? +testing "round trip" 'TZ=$tz date -d "$(TZ=$tz date -d @1598476818)"' \ + "Wed Aug 26 23:20:18 CEST 2020\n" "" "" |