From d32a9cb74657e1fda1c1de17809cb74276a8455a Mon Sep 17 00:00:00 2001 From: Ruzicka Pavel Date: Mon, 19 Sep 2016 04:10:02 +0200 Subject: [PATCH] seconds_to_time.sh added --- seconds_to_time.sh | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100755 seconds_to_time.sh diff --git a/seconds_to_time.sh b/seconds_to_time.sh new file mode 100755 index 0000000..652f3de --- /dev/null +++ b/seconds_to_time.sh @@ -0,0 +1,15 @@ +#!/bin/bash + +function displaytime { + local T=$1 + local D=$((T/60/60/24)) + local H=$((T/60/60%24)) + local M=$((T/60%60)) + local S=$((T%60)) + [[ $D > 0 ]] && printf '%d days ' $D + [[ $H > 0 ]] && printf '%d hours ' $H + [[ $M > 0 ]] && printf '%d minutes ' $M + [[ $D > 0 || $H > 0 || $M > 0 ]] && printf 'and ' + printf '%d seconds\n' $S +} +displaytime $1