Add script 'time_duration.sh'.

This commit is contained in:
Christoph 2022-07-01 10:43:46 +02:00
parent 94785d7874
commit bbed7cd985

45
snippets/time_duration.sh Executable file
View File

@ -0,0 +1,45 @@
#!/usr/bin/env bash
function time_duration () {
local __begin=$1
local __end=$2
local __duration
if [[ "$__begin" ]] && [[ "$__end" ]] ; then
local __duration
local __time=`expr $__end - $__begin`
local __t_h=`expr $__time / 60 / 60`
local __t_rest_h=`expr $__time - $__t_h \\* 60 \\* 60`
local __t_m=`expr $__t_rest_h / 60`
local __t_s=`expr $__t_rest_h - $__t_m \\* 60`
if [[ $__t_h -gt 0 ]]; then
echo "$__t_h h : $__t_m min : $__t_s sec"
elif [[ $__t_m -gt 0 ]]; then
echo "$__t_m min : $__t_s sec"
else
echo "$__t_s sec"
fi
else
echo "N/A"
fi
}
b_timestamp=$(date +"%s")
sleep 3
e_timestamp=$(date +"%s")
duration=$(time_duration $b_timestamp $e_timestamp)
echo ""
echo "time duration: [ $duration ]"
echo ""
exit 0