123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- #! /bin/sh
- # -----------------------------------------------------
- # init
- # -----------------------------------------------------
- # exit on error
- set -e
- # program name and location:
- call="$0 $*"
- case $0 in
- /* ) script=$0 ;;
- * ) script="`/bin/pwd`/$0" ;;
- esac
- bindir=`/usr/bin/dirname ${script}`
- prog=`/bin/basename ${script}`
- # -----------------------------------------------------
- # help
- # -----------------------------------------------------
- DisplayHelp ()
- {
- ${PAGER:-less} << EOF
- NAME
- $prog - return number of days between two dates
- USAGE
- $prog <ccyymmdd1> <ccyymmdd2>
-
- EOF
- exit 0
- }
- # err 'help text'
- err ()
- {
- echo "$1" 1>&2
- }
- # errit <exit-status>
- errit ()
- {
- err "$prog - ERROR - in call : ${call}"
- err "$prog - ERROR - use '$prog --help' for more info."
- exit $1
- }
- # -----------------------------------------------------
- # arguments
- # -----------------------------------------------------
- day1=''
- day2=''
- # extract arguments
- for arg in "$@" ; do
- case ${arg} in
- -h | --help ) DisplayHelp ;;
- * ) # task or (one of the) location(s)
- if [ -z "${day1}" ]; then
- day1=${arg}
- elif [ -z "${day2}" ]; then
- day2=${arg}
- else
- err "$prog - ERROR - unknown argument : ${arg}"
- errit 1
- fi
- ;;
- esac
- done
- # not complete ?
- if [ -z "${day2}" ]; then
- err "$prog - ERROR - missing arguments"
- errit 1
- fi
- # -----------------------------------------------------
- # begin
- # -----------------------------------------------------
- # day2 should be equal to or later than day1
- if [ ${day2} -lt ${day1} ]; then
- err "$prog - day2 should not be earlier than day1 :"
- err "$prog - ${day1} ${day2}"
- errit 1
- fi
- # count from day1 to day2
- day=${day1}
- nday=0
- while [ ${day} -ne ${day2} ]; do
- nday=`/usr/bin/expr ${nday} + 1`
- day=`${bindir}/date_add ${day} 1`
- done
- # return number of days
- echo ${nday}
-
- # ok
- exit 0
-
- # -----------------------------------------------------
- # end
- # -----------------------------------------------------
|