#!/bin/sh
#-*- tab-width: 4; -*-
# ex:ts=4

putime()
{
    local __time_now __time_int __sec __min __hr

	__time_now=`env LANG=C date`
	case $1 in
	-e)
		_time_end=`env LANG=C date -j -f "%a %b %d %T %Z %Y" "${__time_now}" "+%s"`
		;;
	-i)
		: $((__time_int = _time_end - _time_start))
		: $((__sec = __time_int % 60))
		: $((__min = __time_int / 60 % 60))
		: $((__hr  = __time_int / 60 / 60 % 60))
		printf "%02d:%02d:%02d\n" ${__hr} ${__min} ${__sec}
		;;
	-s)
		_time_start=`env LANG=C date -j -f "%a %b %d %T %Z %Y" "${__time_now}" "+%s"`
		;;
	*)
		echo ${__time_now}
		;;
	esac
}

putime -s
echo "Starting at `putime`"
i=0; n=10
while [ ${i} -lt ${n} ]; do
	echo -n "."
	sleep 1
	: $((i += 1))
done
echo "done"
putime -e
echo "Ended at `putime` consumed `putime -i`"
