aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-02-07 19:03:30 -0800
committerRob Landley <rob@landley.net>2019-02-11 23:21:13 -0600
commit8326fe1f7e141f49a46a57acc6221651298b42c9 (patch)
tree81e8468040d47011e16d3f236b97c84de91d4fb5 /tests
parent1a3c65c868b676c86073025465f57116d0e91881 (diff)
downloadtoybox-8326fe1f7e141f49a46a57acc6221651298b42c9.tar.gz
date: some fixes.
Add support for more input formats, primarily the ISO formats used by the AOSP build. I've improved/added to the tests a bit to cover these changes, and to explain the reasons for the various remaining test failures (none of which are regressions caused by this patch).
Diffstat (limited to 'tests')
-rw-r--r--tests/date.test49
1 files changed, 32 insertions, 17 deletions
diff --git a/tests/date.test b/tests/date.test
index 431b35ab..e0da9a44 100644
--- a/tests/date.test
+++ b/tests/date.test
@@ -4,25 +4,38 @@
#testing "name" "command" "result" "infile" "stdin"
-# Test Unix date parsing.
-testing "-d @0" "TZ=UTC date -d @0 2>&1" "Thu Jan 1 00:00:00 GMT 1970\n" "" ""
-testing "-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 "-d 06021234" "TZ=UTC date -d 06021234 2>&1" "Sun Jun 2 12:34:00 UTC 1900\n" "" ""
-testing "-d 060212341982" "TZ=UTC date -d 060212341982 2>&1" "Sun Jun 2 12:34:00 UTC 1982\n" "" ""
-testing "-d 123" "TZ=UTC date -d 123 2>&1" "date: bad date '123'\n" "" ""
-testing "-d 2018-10-04" "TZ=UTC date -d 2018-10-04 2>&1" "Thu Oct 4 00:00:00 UTC 2018\n" "" ""
-
-# Test parsing 2- and 4-digit years.
-testing "-d 1110143115.30" "TZ=UTC date -d 1110143115.30 2>&1" "Sun Nov 10 14:31:30 UTC 1915\n" "" ""
-testing "-d 111014312015.30" "TZ=UTC date -d 111014312015.30 2>&1" "Sun Nov 10 14:31:30 UTC 2015\n" "" ""
-
-# Accidentally given a Unix time, we should trivially reject that.
-testing "Unix time missing @" "TZ=UTC date 1438053157 2>/dev/null || echo no" \
+# Use a consistent TZ for these tests, but not GMT/UTC because that makes mistakes harder to spot.
+tz=Europe/London
+
+# Unix date parsing.
+testing "-d @0" "TZ=$tz date -d @0 2>&1" "Thu Jan 1 01:00:00 BST 1970\n" "" ""
+testing "-d @0x123 invalid" "TZ=$tz date -d @0x123 2>/dev/null || echo expected error" "expected error\n" "" ""
+
+# TODO: these are rejected by coreutils and interpreted differently by busybox.
+# busybox thinks this should use the current year, not 1900.
+testing "-d 06021234" "TZ=$tz date -d 06021234 2>&1" "Sun Jun 2 12:34:00 UTC 1900\n" "" ""
+# busybox thinks this is the year 603 (ISO time 0602-12-34 19:82 with out of range fields normalized).
+testing "-d 060212341982" "TZ=$tz date -d 060212341982 2>&1" "Sun Jun 2 12:34:00 UTC 1982\n" "" ""
+
+# POSIX format with 2- and 4-digit years.
+# TODO: coreutils rejects POSIX format supplied to -d.
+testing "-d 1110143115.30" "TZ=$tz date -d 1110143115.30 2>&1" "Sun Nov 10 14:31:30 UTC 1915\n" "" ""
+testing "-d 111014312015.30" "TZ=$tz date -d 111014312015.30 2>&1" "Sun Nov 10 14:31:30 UTC 2015\n" "" ""
+
+# ISO date format.
+testing "-d 1980-01-02" "TZ=$tz date -d 1980-01-02 2>&1" "Wed Jan 2 00:00:00 GMT 1980\n" "" ""
+testing "-d 1980-01-02 12:34" "TZ=$tz date -d '1980-01-02 12:34' 2>&1" "Wed Jan 2 12:34:00 GMT 1980\n" "" ""
+testing "-d 1980-01-02 12:34:56" "TZ=$tz date -d '1980-01-02 12:34:56' 2>&1" "Wed Jan 2 12:34:56 GMT 1980\n" "" ""
+
+# Reject Unix times without a leading @.
+testing "Unix time missing @" "TZ=$tz date 1438053157 2>/dev/null || echo no" \
"no\n" "" ""
+# Test just hour and minute (accepted by coreutils and busybox, presumably for setting the time).
+this_year=$(date +%Y)
+testing "-d 12:34" 'TZ=UTC date -d 12:34 | grep -q " 12:34:00 UTC $this_year" && echo OK' "OK\n" "" ""
+testing "-d 12:34:56" 'TZ=UTC date -d 12:34:56 | grep -q " 12:34:56 UTC $this_year" && echo OK' "OK\n" "" ""
+
# Test the %N extension to srtftime(3) format strings.
testing "%N" "touch -d 2012-01-23T12:34:56.123456789 f && date -r f +%Y%m%d-%H%M%S.%N" "20120123-123456.123456789\n" "" ""
testing "%1N" "touch -d 2012-01-23T12:34:56.123456789 f && date -r f +%Y%m%d-%H%M%S.%1N" "20120123-123456.1\n" "" ""
@@ -35,5 +48,7 @@ testing "just %" "touch -d 2012-01-23T12:34:56.123456789 f && date -r f +%" "%\n
rm -f f
# Test embedded TZ to take a date in one time zone and display it in another.
+# TODO: not yet working correctly in toybox.
+testing "TZ=" "TZ='America/Los_Angeles' date -d 'TZ=\"Europe/London\" 2018-01-04 08:00'" "Thu Jan 4 00:00:00 PST 2018\n" "" ""
testing "TZ=" "TZ='America/Los_Angeles' date -d 'TZ=\"Europe/London\" 2018-10-04 08:00'" "Thu Oct 4 00:00:00 PDT 2018\n" "" ""
testing "TZ= @" "TZ='America/Los_Angeles' date -d 'TZ=\"GMT\" @1533427200'" "Sat Aug 4 17:00:00 PDT 2018\n" "" ""