commit 9118425533f3f710a84c9803e143b8c0c07649cb
parent 18113c85b0e53eec4420c475ea860525cfed2719
Author: hhvn <dev@hhvn.uk>
Date: Sun, 2 May 2021 20:04:30 +0100
.s/b/{cst,secs}2{secs,cst}: seconds -> colon seperated time (old/untracked)
Diffstat:
2 files changed, 40 insertions(+), 0 deletions(-)
diff --git a/.scripts/bin/cst2secs b/.scripts/bin/cst2secs
@@ -0,0 +1,14 @@
+#!/bin/sh
+#
+# colon-seperated-time to seconds
+
+[ -z $1 ] || [ "$1" = "-h" ] && echo "usage: cst2secs [HH:]MM:SS" && exit 1
+
+echo "$1" | awk -F":" -v "s=0" '{
+ n=1
+ for (i=NF; i != 0; i--) {
+ s = s + ($i * n)
+ n = n * 60
+ }
+ print s
+ }'
diff --git a/.scripts/bin/secs2cst b/.scripts/bin/secs2cst
@@ -0,0 +1,26 @@
+#!/bin/sh
+#
+# seconds to colon-seperated-time
+
+# DONOTUSE: cannot handle hours yet
+
+[ -z $1 ] || [ "$1" = "-h" ] && echo "usage: secs2cst <n>" && exit 1
+
+awk -v "n=$1" '{
+ for (i=0;; i++) {
+ if (n > 60) {
+ result[i] = int(n / 60)
+ n = n - (result[i] * 60)
+ } else {
+ result[i] = n
+ break
+ }
+ }
+ elements = i
+ for (i=0; i <= elements; i++)
+ if (i != elements)
+ printf("%02d:", result[i])
+ else
+ printf("%02d\n", result[i])
+ }'
+