From dda262bddb556195e6b2ca457ae70f2c80fa5815 Mon Sep 17 00:00:00 2001 From: Nick Chambers Date: Sun, 18 Jul 2021 12:28:11 -0500 Subject: [PATCH] Add a helper function for processing a unix timestamp --- rowbot | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/rowbot b/rowbot index ebd013f..759bf02 100755 --- a/rowbot +++ b/rowbot @@ -100,6 +100,32 @@ run_callbacks() { return "$status" } +# The variables are checked dynamically +# shellcheck disable=SC2034 +seconds() { + local day hour minute second span time + (( day = $1 / 60 / 60 / 24 )) + (( hour = $1 / 60 / 60 % 24 )) + (( minute = $1 / 60 % 60 )) + (( second = $1 % 60 )) + + for span in day hour minute second; do + if (( ${!span} )); then + if [[ $time ]]; then + time+=", " + fi + + time+="${!span} $span" + + if (( ${!span} > 1 )); then + time+=s + fi + fi + done + + printf -- %s "$time" +} + url() { if [[ ${config[tls]} = no ]]; then printf irc://