From 01a1ed449f72740d81cda58357936639ce8b79cd Mon Sep 17 00:00:00 2001 From: Patrick Spek Date: Sun, 22 Mar 2020 23:23:28 +0100 Subject: Include duration of installation process --- lib/util.bash | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'lib/util.bash') diff --git a/lib/util.bash b/lib/util.bash index 8ca1a5e..7ab0bc1 100644 --- a/lib/util.bash +++ b/lib/util.bash @@ -74,6 +74,28 @@ fetch() { return $exit_code } +# Pretty print a duration between a starting point (in seconds) and an end +# point (in seconds). If no end point is given, the current time will be used. +# A good way to get a current timestamp in seconds is through date's "%s" +# format. +pp_duration() { + local start=$1 + local end=$2 + local diff + + if [[ -z "$end" ]] + then + end="$(date +%s)" + fi + + diff=$((end - start)) + + printf "%dh %02dm %02ds\n" \ + "$((diff / 60 / 60))" \ + "$((diff / 60))" \ + "$((diff % 60))" +} + # Create a temporary directory. Similar to tempfile, but you'll get a directory # instead. tmpdir() { -- cgit v1.1