summaryrefslogtreecommitdiff
path: root/functions/humanize_duration.fish
diff options
context:
space:
mode:
Diffstat (limited to 'functions/humanize_duration.fish')
-rw-r--r--functions/humanize_duration.fish19
1 files changed, 19 insertions, 0 deletions
diff --git a/functions/humanize_duration.fish b/functions/humanize_duration.fish
new file mode 100644
index 0000000..eeb999f
--- /dev/null
+++ b/functions/humanize_duration.fish
@@ -0,0 +1,19 @@
+function humanize_duration -d "Make a time interval human readable"
+ command awk '
+ function hmTime(time, stamp) {
+ split("h:m:s:ms", units, ":")
+ for (i = 2; i >= -1; i--) {
+ if (t = int( i < 0 ? time % 1000 : time / (60 ^ i * 1000) % 60 )) {
+ stamp = stamp t units[sqrt((i - 2) ^ 2) + 1] " "
+ }
+ }
+ if (stamp ~ /^ *$/) {
+ return "0ms"
+ }
+ return substr(stamp, 1, length(stamp) - 1)
+ }
+ {
+ print hmTime($0)
+ }
+ '
+end