date-works-1 2.4 KB

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