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