diff options
author | Elliott Hughes <enh@google.com> | 2015-08-11 16:06:06 -0500 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2015-08-11 16:06:06 -0500 |
commit | 05499787ca89fa4b017c2441e89020799f02e4c1 (patch) | |
tree | c8e48c77d96b47fd710238f82240126e71798981 /tests | |
parent | 7f6bb3dae7ffe5ffdf10cc2e73a803ff820ebca8 (diff) | |
download | toybox-05499787ca89fa4b017c2441e89020799f02e4c1.tar.gz |
Fix more date bugs.
Correctly and portably check for non-normal dates, and explicitly show
the "before" and "after" dates (in the format of the user's choosing).
Clear the struct tm in date_main rather than parse_default because on
one path the struct tm is actually initialized. Explicitly clear the
tm_sec field in parse_default because -- experiment shows -- that
should not be preserved. Only do the "what does this 2-digit year
mean?" dance if we actually parsed a 2-digit year. Show the right
string in the error message if strptime fails.
Also add more tests, and use UTC in the tests to avoid flakiness.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/date.test | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/tests/date.test b/tests/date.test index d72e50cf..94a41579 100644 --- a/tests/date.test +++ b/tests/date.test @@ -4,7 +4,19 @@ #testing "name" "command" "result" "infile" "stdin" +# Test Unix date parsing. +testing "date -d @0" "TZ=UTC date -d @0 2>&1" "Thu Jan 1 00:00:00 GMT 1970\n" "" "" +testing "date -d @0x123" "TZ=UTC date -d @0x123 2>&1" "date: bad date '@0x123'\n" "" "" + +# Test basic date parsing. +# Note that toybox's -d format is not the same as coreutils'. +testing "date -d 06021234" "TZ=UTC date -d 06021234 2>&1" "Sun Jun 2 12:34:00 UTC 1900\n" "" "" +testing "date -d 060212341982" "TZ=UTC date -d 060212341982 2>&1" "Sun Jun 2 12:34:00 UTC 1982\n" "" "" +testing "date -d 123" "TZ=UTC date -d 123 2>&1" "date: bad date '123'\n" "" "" + # Accidentally given a Unix time, we should trivially reject that. -testing "date Unix time" "date 1438053157 2>&1" "date: bad date '1438053157'\n" "" "" +testing "date Unix time missing @" "TZ=UTC date 1438053157 2>&1" \ + "date: bad date '1438053157'; Tue February 38 05:31:00 UTC 2057 != Sun Mar 10 05:31:00 UTC 2058\n" "" "" # But some invalid dates are more subtle, like Febuary 29th in a non-leap year. -testing "date Feb 29th" "date 022900001975 2>&1" "date: bad date +testing "date Feb 29th" "TZ=UTC date 022900001975 2>&1" \ + "date: bad date '022900001975'; Tue Feb 29 00:00:00 UTC 2075 != Fri Mar 1 00:00:00 UTC 2075\n" "" "" |