summaryrefslogtreecommitdiffhomepage
path: root/testsuite/date/date-works-1
blob: cb5cea2c533ccb88e04ec372b826981cc3d9ba74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
unset LANG
unset LANGUAGE
unset LC_TIME
unset LC_ALL

dt=`busybox date -d 1:2 +%T`
test x"$dt" = x"01:02:00"

dt=`busybox date -d 1:2:3 +%T`
test x"$dt" = x"01:02:03"

host_date=/bin/date

# date (GNU coreutils) 6.10 reports:
#	date: invalid date '1.2-3:4'
# busybox 1.11.0.svn date reports:
#	date: invalid date '1/2 3:4'

# TODO: (1) compare with strings, not "host date"
# (2) implement d/m[/y] hh:mm[:ss] fmt in date applet
#hdt=`$host_date -d '1/2 3:4'`
#dt=`busybox date -d 1.2-3:4`
#test x"$hdt" = x"$dt"

#hdt=`$host_date -d '1/2 3:4:5'`
#dt=`busybox date -d 1.2-3:4:5`
#test x"$hdt" = x"$dt"

#hdt=`$host_date -d '1/2/1999 3:4'`
#dt=`busybox date -d 1999.1.2-3:4`
#test x"$hdt" = x"$dt"

#hdt=`$host_date -d '1/2/1999 3:4:5'`
#dt=`busybox date -d 1999.1.2-3:4:5`
#test x"$hdt" = x"$dt"

hdt=`$host_date -d '1999-1-2 3:4:5'`
dt=`busybox date -d '1999-1-2 3:4:5'`
test x"$hdt" = x"$dt"

# Avoiding using week day in this evaluation, as it's mostly different every year
# date (GNU coreutils) 6.10 reports:
#	date: invalid date '01231133'
dt=`busybox date -d 01231133 +%c`
dt=`echo "$dt" | cut -b5-19`
test x"$dt" = x"Jan 23 11:33:00"

# date (GNU coreutils) 6.10 reports:
#	date: invalid date '012311332000'
dt=`busybox date -d 200001231133 +%c`
test x"$dt" = x"Sun Jan 23 11:33:00 2000"

# date (GNU coreutils) 6.10 reports:
#	date: invalid date '012311332000'
dt=`busybox date -d 200001231133.30 +%c`
test x"$dt" = x"Sun Jan 23 11:33:30 2000"

lcbbd="LC_ALL=C busybox date"
wd=$(eval $lcbbd +%a)		# weekday name
mn=$(eval $lcbbd +%b)		# month name
dm=$(eval $lcbbd +%e)		# day of month, space padded
h=$(eval $lcbbd +%H)		# hour, zero padded
m=$(eval $lcbbd +%M)		# minute, zero padded
s=$(eval $lcbbd +%S)		# second, zero padded
z=$(eval $lcbbd -u +%Z)		# time zone abbreviation
y=$(eval $lcbbd +%Y)		# year

res=OK
case $wd in
	Sun)
		;;
	Mon)
		;;
	Tue)
		;;
	Wed)
		;;
	Thu)
		;;
	Fri)
		;;
	Sat)
		;;
	*)
		res=BAD
		;;
esac

case $mn in
	Jan)
		;;
	Feb)
		;;
	Mar)
		;;
	Apr)
		;;
	May)
		;;
	Jun)
		;;
	Jul)
		;;
	Aug)
		;;
	Sep)
		;;
	Oct)
		;;
	Nov)
		;;
	Dec)
		;;
	*)
		res=BAD
		;;
esac

dm=${dm# *}
[ $dm -ge 1 ] && [ $dm -le 31 ] || res=BAD
h=${h#0}
[ $h -ge 0 ] && [ $h -le 23 ] || res=BAD
m=${m#0}
[ $m -ge 0 ] && [ $m -le 59 ] || res=BAD
s=${s#0}
[ $s -ge 0 ] && [ $s -le 59 ] || res=BAD
[ $z = UTC ] || res=BAD
[ $y -ge 1970 ] || res=BAD

test x"$res" = xOK

# This should error out (by showing usage text). Testing for that
dt=`busybox date -d 012311332000.30 %+c 2>&1 | head -n 1`
test x"${dt##BusyBox * multi-call binary*}" = x""