aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2019-03-12 18:00:26 -0700
committerRob Landley <rob@landley.net>2019-03-13 18:03:41 -0500
commit7aa276db3c0f6e335914401f961d6e76587b141b (patch)
tree64c23c1765052d2e0bb09fad7a8ac9878523f0af /tests
parent1c17ba88c7f12166035f158e8733c053441e6413 (diff)
downloadtoybox-7aa276db3c0f6e335914401f961d6e76587b141b.tar.gz
date: fix various time zone/daylight time issues.
Sunday's transition in the US broke a bunch of the tests. Worse, it broke some of the QA folks' scripts. Finally, the boil that is date's handling of time zones and daylight time has come to a head... This patch fixes the newly-failing tests *and* the other tests that were checked in failing to serve as TODOs. I've resolved the test TODOs about whether implied year/century in POSIX format should mean the current year or 1900 in favor of the current year. Both busybox and coreutils agree, and Rob fixed the code recently so toybox agrees too, but without fixing the tests. I've switched tests from Europe/London to Europe/Berlin to avoid disagreements between C libraries about whether to say "GMT" or "UTC" when daylight savings is not in force. The majority of this patch implements what I'd been unsuccessfully trying to explain on the list: that to correctly implement the distinct input and output time zones (as demonstrated in the three failing tests we've been carrying around for a while), we should switch to working with time_t internally rather than struct tm. I've also added the code to temporarily switch to the input time zone (and back again). All the tests now pass.
Diffstat (limited to 'tests')
-rw-r--r--tests/date.test25
1 files changed, 12 insertions, 13 deletions
diff --git a/tests/date.test b/tests/date.test
index fd45773f..285d3dec 100644
--- a/tests/date.test
+++ b/tests/date.test
@@ -6,29 +6,29 @@
# Use a consistent TZ for these tests, but not GMT/UTC because that
# makes mistakes harder to spot.
-tz=Europe/London
+tz=Europe/Berlin
# Unix date parsing.
-testing "-d @0" "TZ=$tz date -d @0 2>&1" "Thu Jan 1 01:00:00 BST 1970\n" "" ""
+testing "-d @0" "TZ=$tz date -d @0 2>&1" "Thu Jan 1 01:00:00 CET 1970\n" "" ""
testing "-d @0x123 invalid" "TZ=$tz date -d @0x123 2>/dev/null || echo expected error" "expected error\n" "" ""
# POSIX format with 2- and 4-digit years.
# All SKIP_HOST=1 because coreutils rejects POSIX format dates supplied to -d.
-# TODO: busybox thinks this should use the current year, not 1900, which would make more sense?
+# These expected values are from running on the host without -d (not as root!).
SKIP_HOST=1 testing "-d MMDDhhmm" \
- "TZ=$tz date -d 06021234 2>&1" "Sun Jun 2 12:34:00 UTC 1900\n" "" ""
+ "TZ=$tz date -d 06021234 2>&1" "Sun Jun 2 12:34:00 CEST 2019\n" "" ""
SKIP_HOST=1 testing "-d MMDDhhmmYY.SS" \
- "TZ=$tz date -d 1110143115.30 2>&1" "Sun Nov 10 14:31:30 UTC 1915\n" "" ""
+ "TZ=$tz date -d 1110143115.30 2>&1" "Tue Nov 10 14:31:30 CET 2015\n" "" ""
# busybox thinks this is the year 603 (ISO time 0602-12-34 19:82 with out of range fields normalized).
SKIP_HOST=1 testing "-d MMDDhhmmCCYY" \
- "TZ=$tz date -d 060212341982 2>&1" "Sun Jun 2 12:34:00 UTC 1982\n" "" ""
+ "TZ=$tz date -d 060212341982 2>&1" "Wed Jun 2 12:34:00 CEST 1982\n" "" ""
SKIP_HOST=1 testing "-d MMDDhhmmCCYY.SS" \
- "TZ=$tz date -d 111014312015.30 2>&1" "Sun Nov 10 14:31:30 UTC 2015\n" "" ""
+ "TZ=$tz date -d 111014312015.30 2>&1" "Tue Nov 10 14:31:30 CET 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" "" ""
+testing "-d 1980-01-02" "TZ=$tz date -d 1980-01-02 2>&1" "Wed Jan 2 00:00:00 CET 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 CET 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 CET 1980\n" "" ""
# Reject Unix times without a leading @.
testing "Unix time missing @" "TZ=$tz date 1438053157 2>/dev/null || echo no" \
@@ -51,7 +51,6 @@ 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=\"Europe/Berlin\" 2018-01-04 08:00'" "Wed Jan 3 23:00:00 PST 2018\n" "" ""
+testing "TZ=" "TZ='America/Los_Angeles' date -d 'TZ=\"Europe/Berlin\" 2018-10-04 08:00'" "Wed Oct 3 23: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" "" ""