RE: [SLUG] need shell script routine

From: Levi Bard (levi@bard.sytes.net)
Date: Fri Feb 06 2004 - 15:26:57 EST


My contribution. Just keeps adding any hours over 24 to the total hours,
so that a valid result might be 423:15:58.

--

# Adds up all times and prints the total # Accepts arguments as valid times in the form of hh:mm:ss # Prints result on stdout function addtimes {

totaltime=(00 00 00) for i in "$@" do newtime=(`echo "$i" | awk -F : '{ print $1" "$2" "$3 }'`) totaltime[2]=$(( ${totaltime[2]} + ${newtime[2]} )) if [[ ${totaltime[2]} -gt 59 ]]; then totaltime[1]=$(( ${totaltime[1]} + 1 )) totaltime[2]=$(( ${totaltime[2]} - 60 )) fi totaltime[1]=$(( ${totaltime[1]} + ${newtime[1]} )) if [[ ${totaltime[1]} -gt 59 ]]; then totaltime[0]=$(( ${totaltime[0]} + 1 )) totaltime[1]=$(( ${totaltime[1]} - 60 )) fi totaltime[0]=$(( ${totaltime[0]} + ${newtime[0]} )) # if [[ ${totaltime[0]} -gt 23 ]]; then # totaltime[0]=$(( ${totaltime[0]} - 24 )) # fi done echo "${totaltime[0]}:${totaltime[1]}:${totaltime[2]}"

}

----------------------------------------------------------------------- This list is provided as an unmoderated internet service by Networked Knowledge Systems (NKS). Views and opinions expressed in messages posted are those of the author and do not necessarily reflect the official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:33:00 EDT