--- /dev/null
+#!/bin/bash
+
+# some helpful functions for counting a named duration.
+
+# start tracking time for a named purpose, passed as the first parameter.
+function start_time_tracking()
+{
+ local varname="$1"; shift
+ if [ -z "$varname" ]; then echo must pass variable name to start_time_tracking; return 1; fi
+ local startvar="${varname}_START"
+ eval $startvar="$(date +"%s")"
+}
+
+# stop tracking the named time duration.
+function end_time_tracking()
+{
+ local varname="$1"; shift
+ if [ -z "$varname" ]; then echo must pass variable name to end_time_tracking; return 1; fi
+ local endvar="${varname}_END"
+ eval $endvar="$(date +"%s")"
+}
+
+# display the time taken for a named duration.
+function show_tracked_duration()
+{
+ varname="$1"; shift
+ if [ -z "$varname" ]; then echo must pass variable name to end_time_tracking; return 1; fi
+ # calculate the time taken.
+ local startvar="${varname}_START"
+ local endvar="${varname}_END"
+ duration="$((${!endvar} - ${!startvar}))"
+ # separate it into hours and minutes.
+ minutes="$(($duration / 60))"
+ hours="$(($duration / 60))"
+ # subtract the hours from the minutes sum for modulo.
+ minutes="$(($minutes - $hours * 60))"
+ # fashion conceit, add zeroes.
+ if (($minutes < 10)); then minutes="0$minutes"; fi
+ if (($hours < 10)); then hours="0$hours"; fi
+ echo "Time taken for ${varname}: ${hours}:${minutes} hh:mm (a total of $duration seconds)"
+}
+
+
+++ /dev/null
-#!/bin/bash
-#
-# tests the array sifter methods.
-
-source $FEISTY_MEOW_SCRIPTS/core/array_sifter.sh
-
-#demo 1 & 2 for test presence.
-declare -a my_array=(peanuts sauce fish basil)
-
-test1=basil
-test_presence my_array $test1
-if [ $? != 0 ]; then
- echo "test1 did not find flag, but should have."
-else
- echo "test1 found expected flag."
-fi
-
-test2=spoo
-test_presence my_array $test2
-if [ $? != 0 ]; then
- echo "test2 did not find flag, which is correct."
-else
- echo "test2 found flag when should not have."
-fi
-
-#############################################
-
-#demo3 for sifting...
-
-declare -a sift_list=(ontrack selenium aggressive)
-declare -a stripping=(selenium)
-declare -a store_list=()
-
-sift_array "sift_list" "stripping" "store_list"
-if [ ${store_list[0]} == "selenium" ]; then
- echo "test3 found expected content in storage list."
-else
- echo "test3 was missing expected content in storage list."
-fi
-echo sift is now ${sift_list[*]}
-if [ "${sift_list[*]}" == "ontrack aggressive" ]; then
- echo "test3 found expected content in sifting list."
-else
- echo "test3 was missing expected content in sifting list."
-fi
-
-
--- /dev/null
+#!/bin/bash
+#
+# tests the array sifter methods.
+
+source $FEISTY_MEOW_SCRIPTS/core/array_sifter.sh
+
+#demo 1 & 2 for test presence.
+declare -a my_array=(peanuts sauce fish basil)
+
+test1=basil
+test_presence my_array $test1
+if [ $? != 0 ]; then
+ echo "test1 did not find flag, but should have."
+else
+ echo "test1 found expected flag."
+fi
+
+test2=spoo
+test_presence my_array $test2
+if [ $? != 0 ]; then
+ echo "test2 did not find flag, which is correct."
+else
+ echo "test2 found flag when should not have."
+fi
+
+#############################################
+
+#demo3 for sifting...
+
+declare -a sift_list=(ontrack selenium aggressive)
+declare -a stripping=(selenium)
+declare -a store_list=()
+
+sift_array "sift_list" "stripping" "store_list"
+if [ ${store_list[0]} == "selenium" ]; then
+ echo "test3 found expected content in storage list."
+else
+ echo "test3 was missing expected content in storage list."
+fi
+echo sift is now ${sift_list[*]}
+if [ "${sift_list[*]}" == "ontrack aggressive" ]; then
+ echo "test3 found expected content in sifting list."
+else
+ echo "test3 was missing expected content in sifting list."
+fi
+
+
declare -A snuggles
# make an associative array
-snuggles=([book]=petunia "[muffets]=glasgow robbery")
+snuggles=([book]=petunia [muffets]="glasgow robbery")
# keys: book and muffets
# values: (second part)
--- /dev/null
+#!/bin/bash
+
+# tests out the time tracking methods.
+
+source $FEISTY_MEOW_SCRIPTS/system/time_tracker.sh
+
+echo testing time tracking...
+start_time_tracking crungle
+
+sleep $(($RANDOM / 1000))
+sleep 2
+
+end_time_tracking crungle
+
+echo ...done testing time tracking.
+
+show_tracked_duration crungle
+