diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2017-02-05 02:17:12 +1300 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2017-02-05 02:18:24 +1300 |
commit | b9b5a431422c4213fe555e284fcfaa96cd692267 (patch) | |
tree | f2b81334491757777f857afed7925204fd4844f2 /bin/hms.awk | |
parent | Escape literal backslash in sec(1df) manual (diff) | |
download | dotfiles-b9b5a431422c4213fe555e284fcfaa96cd692267.tar.gz dotfiles-b9b5a431422c4213fe555e284fcfaa96cd692267.zip |
Add hms(1df)
Diffstat (limited to 'bin/hms.awk')
-rw-r--r-- | bin/hms.awk | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/bin/hms.awk b/bin/hms.awk new file mode 100644 index 00000000..3a9a1499 --- /dev/null +++ b/bin/hms.awk @@ -0,0 +1,31 @@ +BEGIN { + OFS = ":" +} + +# Refuse to deal with anything that's not a positive (unsigned) integer +/[^0-9]/ { + print "hms: Bad number" | "cat >&2" + err = 1 + next +} + +# Integer looks valid +{ + # Break it down into hours, minutes, and seconds + s = $0 + h = int(s / 3600) + s %= 3600 + m = int(s / 60) + s %= 60 + + # Print it, with the biggest number without a leading zero + if (h) + printf "%u:%02u:%02u\n", h, m, s + else if (m) + printf "%u:%02u\n", m, s + else + printf "%u\n", s +} + +# Done, exit 1 if we had any errors on the way +END { exit(err > 0) } |