3
0

date-works-1 2.5 KB

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