暂无描述

test_weekofyear.sh 757B

123456789101112131415161718192021222324252627
  1. #!/bin/bash
  2. # this just takes php's date() function as a reference to check if week of year
  3. # is calculated correctly in the range from 1970 .. 2038 by brute force...
  4. SEQ="seq"
  5. SYSTEM=`uname`
  6. if [ "$SYSTEM" = "Darwin" ]; then
  7. SEQ="jot"
  8. fi
  9. for YEAR in {1970..2038}; do
  10. for MONTH in {1..12}; do
  11. DAYS=$(cal $MONTH $YEAR | egrep "28|29|30|31" |tail -1 |awk '{print $NF}')
  12. for DAY in $( $SEQ $DAYS ); do
  13. DATE=$YEAR-$MONTH-$DAY
  14. echo -n $DATE ...
  15. NODEVAL=$(node test_weekofyear.js $DATE)
  16. PHPVAL=$(php -r "echo intval(date('W', strtotime('$DATE')));")
  17. if [ "$NODEVAL" -ne "$PHPVAL" ]; then
  18. echo "MISMATCH: node: $NODEVAL vs php: $PHPVAL for date $DATE"
  19. else
  20. echo " OK"
  21. fi
  22. done
  23. done
  24. done