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