#!/bin/bash
# $Id: datediff,v 1.1 2002/07/07 14:39:09 oliver Exp $
# $Log: datediff,v $
# Revision 1.1  2002/07/07 14:39:09  oliver
# Initial revision
#


# usage: $1 date1 date2
# output: difference in s

Prog=$(basename $0)

BC="/usr/bin/bc -l"
VERBOSE="--verbose"

USAGE="Usage: ${Prog} [OPTIONS] 'date_1' 'date_2'
Prints the difference between dates in seconds. 'now' is allowed.

  date_2 - date_1  [seconds]

OPTIONS:
    -h, --help           print this help
    -v, --verbose        be chatty (verbose is the default)
    -q, --quiet          do not be verbose 

Options are not allowed after or between the dates!
"



while [ $# -gt 0 ]; do
   case "$1" in
        -h|--help)  echo "${USAGE}";
		    exit 0;
		    ;;
	-v|--verbose)
	            VERBOSE="--verbose";;
	-q|--quiet) VERBOSE='';;
	       -*)  echo "Unknown option '$1'."
		    exit 1;
		    ;;
		*)  DATE1=$1;
		    shift; 
		    DATE2=$1;
    esac;
    shift;
done;


SEC1=$(date --date="${DATE1}" +'%s')
SEC2=$(date --date="${DATE2}" +'%s')

DIFF=$(echo "${SEC2} - ${SEC1}" | ${BC})

test -n "${VERBOSE}" && \
    echo "[${DATE2}] - [${DATE1}]" 

echo ${DIFF}


