OSDN Git Service

1d77faa559c1972565669b1c07a8e32d579c1b91
[android-x86/external-toybox.git] / tests / date.test
1 #!/bin/bash
2
3 [ -f testing.sh ] && . testing.sh
4
5 #testing "name" "command" "result" "infile" "stdin"
6
7 # Test Unix date parsing.
8 testing "-d @0" "TZ=UTC date -d @0 2>&1" "Thu Jan  1 00:00:00 GMT 1970\n" "" ""
9 testing "-d @0x123" "TZ=UTC date -d @0x123 2>&1" "date: bad date '@0x123'\n" "" ""
10
11 # Test basic date parsing.
12 # Note that toybox's -d format is not the same as coreutils'.
13 testing "-d 06021234" "TZ=UTC date -d 06021234 2>&1" "Sun Jun  2 12:34:00 UTC 1900\n" "" ""
14 testing "-d 060212341982" "TZ=UTC date -d 060212341982 2>&1" "Sun Jun  2 12:34:00 UTC 1982\n" "" ""
15 testing "-d 123" "TZ=UTC date -d 123 2>&1" "date: bad date '123'\n" "" ""
16
17 # Test parsing 2- and 4-digit years.
18 testing "-d 1110143115.30" "TZ=UTC date -d 1110143115.30 2>&1" "Sun Nov 10 14:31:30 UTC 1915\n" "" ""
19 testing "-d 111014312015.30" "TZ=UTC date -d 111014312015.30 2>&1" "Sun Nov 10 14:31:30 UTC 2015\n" "" ""
20
21 # Accidentally given a Unix time, we should trivially reject that.
22 testing "Unix time missing @" "TZ=UTC date 1438053157 2>&1" \
23   "date: bad date '1438053157'; Wed February 38 05:31:00 UTC 2057 != Sun Mar 10 05:31:00 UTC 2058\n" "" ""
24 # But some invalid dates are more subtle, like Febuary 29th in a non-leap year.
25 testing "Feb 29th" "TZ=UTC date 022900001975 2>&1" \
26   "date: bad date '022900001975'; Wed Feb 29 00:00:00 UTC 1975 != Sat Mar  1 00:00:00 UTC 1975\n" "" ""