date: fix date-works test, add date-works-1 one (currently fails)
[oweals/busybox.git] / testsuite / date / date-works-1
1 dt=`busybox date -d 1:2 +%T`
2 test x"$dt" = x"01:02:00"
3
4 dt=`busybox date -d 1:2:3 +%T`
5 test x"$dt" = x"01:02:03"
6
7 host_date=/bin/date
8
9 # date (GNU coreutils) 6.10 reports:
10 #       date: invalid date '1.2-3:4'
11 # busybox 1.11.0.svn date reports:
12 #       date: invalid date '1/2 3:4'
13
14 hdt=`$host_date -d '1/2 3:4'`
15 dt=`busybox date -d 1.2-3:4`
16 test x"$hdt" = x"$dt"
17
18 hdt=`$host_date -d '1/2 3:4:5'`
19 dt=`busybox date -d 1.2-3:4:5`
20 test x"$hdt" = x"$dt"
21
22 hdt=`$host_date -d '1/2/1999 3:4'`
23 dt=`busybox date -d 1999.1.2-3:4`
24 test x"$hdt" = x"$dt"
25
26 hdt=`$host_date -d '1/2/1999 3:4:5'`
27 dt=`busybox date -d 1999.1.2-3:4:5`
28 test x"$hdt" = x"$dt"
29
30 hdt=`$host_date -d '1999-1-2 3:4:5'`
31 dt=`busybox date -d '1999-1-2 3:4:5'`
32 test x"$hdt" = x"$dt"
33
34 # Avoid using week day in this evaluation, as it's mostly different every year
35 # date (GNU coreutils) 6.10 reports:
36 #       date: invalid date '01231133'
37 dt=`busybox date -d 01231133 +%c`
38 dt=`echo "$dt" | cut -b5-19`
39 test x"$dt" = x"Jan 23 11:33:00"
40
41 # date (GNU coreutils) 6.10 reports:
42 #       date: invalid date '012311332000'
43 dt=`busybox date -d 012311332000 +%c`
44 test x"$dt" = x"Sun Jan 23 11:33:00 2000"
45
46 # date (GNU coreutils) 6.10 reports:
47 #       date: invalid date '012311332000'
48 dt=`busybox date -d 012311332000.30 +%c`
49 test x"$dt" = x"Sun Jan 23 11:33:30 2000"
50
51 lcbbd="LC_ALL=C busybox date"
52 wd=$(eval $lcbbd +%a)           # weekday name
53 mn=$(eval $lcbbd +%b)           # month name
54 dm=$(eval $lcbbd +%e)           # day of month, space padded
55 h=$(eval $lcbbd +%H)            # hour, zero padded
56 m=$(eval $lcbbd +%M)            # minute, zero padded
57 s=$(eval $lcbbd +%S)            # second, zero padded
58 z=$(eval $lcbbd -u +%Z)         # time zone abbreviation
59 y=$(eval $lcbbd +%Y)            # year
60
61 res=OK
62 case $wd in
63         Sun)
64                 ;;
65         Mon)
66                 ;;
67         Tue)
68                 ;;
69         Wed)
70                 ;;
71         Thu)
72                 ;;
73         Fri)
74                 ;;
75         Sat)
76                 ;;
77         *)
78                 res=BAD
79                 ;;
80 esac
81
82 case $mn in
83         Jan)
84                 ;;
85         Feb)
86                 ;;
87         Mar)
88                 ;;
89         Apr)
90                 ;;
91         May)
92                 ;;
93         Jun)
94                 ;;
95         Jul)
96                 ;;
97         Aug)
98                 ;;
99         Sep)
100                 ;;
101         Oct)
102                 ;;
103         Nov)
104                 ;;
105         Dec)
106                 ;;
107         *)
108                 res=BAD
109                 ;;
110 esac
111
112 dm=${dm# *}
113 [ $dm -ge 1 ] && [ $dm -le 31 ] || res=BAD
114 h=${h#0}
115 [ $h -ge 0 ] && [ $h -le 23 ] || res=BAD
116 m=${m#0}
117 [ $m -ge 0 ] && [ $m -le 59 ] || res=BAD
118 s=${s#0}
119 [ $s -ge 0 ] && [ $s -le 59 ] || res=BAD
120 [ $z = UTC ] || res=BAD
121 [ $y -ge 1970 ] || res=BAD
122
123 test x"$res" = xOK
124
125 if dt=`busybox date -d 012311332000.30 %+c`; then
126         echo "Expected this to fail with: \"date: invalid date '%+c'\"" >&2
127         exit 1
128 fi