#!/bin/bash
function normalizeTimeInput()
{
local -r inputTime="${1}"
local outputTime="${inputTime//\'/:}"
outputTime="${outputTime//\"/:}"
echo "${outputTime}"
}
function addTime()
{
local inputTimes=("${@}")
local hours=0
local minutes=0
local seconds=0
local milliseconds=0
local tod="" # tod is time of day. Meaning units of hours:minutes:seconds:milliseconds
for time in "${inputTimes[@]}"; do
#echo "${time}" | grep -oE "([[:digit:]]:)+[[:digit:]]+"
tod=$(echo "${time}" | grep -oE "[[:digit:]]+:[[:digit:]]+:[[:digit:]]+")
millisecond=$(echo "${tod}" | cut -f 3 -d ':')
second=$(echo "${tod}" | cut -f 2 -d ':')
minute=$(echo "${tod}" | cut -f 1 -d ':')
#echo millisecond=$millisecond
# Strip leading zeroes and add.
milliseconds=$(( ${milliseconds} + ${millisecond##0} ))
seconds=$(( ${seconds} + ${second##0} ))
minutes=$(( ${minutes} + ${minute##0} ))
done
echo $minutes, $seconds, $milliseconds
seconds=$((${seconds} + ${milliseconds} / 1000 ))
milliseconds=$((${milliseconds} % 1000 ))
minutes=$((${minutes} + ${seconds} / 60 ))
seconds=$((${seconds} % 60 ))
hours=$((${hours} + ${minutes} / 60 ))
minutes=$((${minutes} % 60 ))
echo $hours hours, $minutes minutes, $seconds seconds, $milliseconds milliseconds
}
times=(
"1'34\"277" # Mario Kart Stadium
"1'38\"995" # Water Park
"1'48\"224" # Sweet Sweet Canyon
"1'48\"077" # Thwomp Ruins
"1'43\"830" # Mario Circuit
"2'01\"586" # Toad Harbor
"1'53\"354" # Twisted Mansion
"1'55\"385" # Shy Guy Falls
"1'57\"221" # Sunshine Airport
"1'52\"119" # Dolphin Shoals
"1'55\"367" # Electrodrome
"1'40\"545" # Mount Wario
"1'59\"329" # Cloudtop Cruise
"1'46\"413" # Bone-Dry Dunes
"1'57\"655" # Bowser's Castle
"1'58\"454" # Rainbow Road
"1'23\"642" # Wii Moo Moo Meadows
"1'22\"953" # GBA Mario Circuit
"1'46\"080" # DS Cheep Cheep Beach
"1'45\"563" # N64 Toad's Turnpike
"1'52\"431" # GCN Dry Dry Desert
"1'12\"833" # SNES Donut Plains 3
"1'54\"778" # N64 Royal Raceway
"2'00\"477" # 3DS DK Jungle
"1'50\"581" # DS Wario Stadium
"1'46\"298" # GCN Sherbet Land
"1'50\"508" # 3DS Music Park
"1'57\"720" # N64 Yoshi Valley
"1'41\"292" # DS Tick-Tock Clock
"1'57\"960" # 3DS Piranha Plant Slide
"1'52\"441" # Wii Grumble Volcano
"1'19\"274" # N64 Rainbow Road
"1'41\"253" # GCN Yoshi Circuit
"1'38\"502" # Excitebike Arena
"1'40\"081" # Dragon Driftway
"1'50\"788" # Mute City
"2'01\"373" # Wii Wario's Gold Mine
"1'25\"569" # SNES Rainbow Road
"1'44\"738" # Ice Ice Outpost
"1'46\"905" # Hyrule Circuit
"1'01\"836" # GCN Baby Park
"1'41\"432" # GBA Cheese Land
"1'45\"405" # Wild Woods
"1'42\"158" # 3DS Neo Bowser City
"1'43\"489" # GBA Ribbon Road
"1'39\"680" # Super Bell Subway
"1'23\"189" # Big Blue
)
normTimes=()
timesStr=""
function normalizeInputs()
{
for time in "${times[@]}"; do
normTimes+=($(normalizeTimeInput "${time}"))
done
}
normalizeInputs
addTime "${normTimes[@]}"