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