about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--META6.json3
-rw-r--r--lib/Taurus/CLI.rakumod15
-rw-r--r--lib/Taurus/Seconds.rakumod11
3 files changed, 22 insertions, 7 deletions
diff --git a/META6.json b/META6.json
index 21cdec0..17c97eb 100644
--- a/META6.json
+++ b/META6.json
@@ -7,7 +7,8 @@
     "license" : "ISC",
     "perl" : "6.d",
     "provides" : {
-        "Taurus::CLI" : "lib/Taurus/CLI.rakumod"
+        "Taurus::CLI" : "lib/Taurus/CLI.rakumod",
+        "Taurus::Seconds" : "lib/Taurus/Seconds.rakumod"
     },
     "depends" : [
         "CSV::Parser",
diff --git a/lib/Taurus/CLI.rakumod b/lib/Taurus/CLI.rakumod
index 56ef889..a7759b0 100644
--- a/lib/Taurus/CLI.rakumod
+++ b/lib/Taurus/CLI.rakumod
@@ -1,3 +1,5 @@
+use Taurus::Seconds;
+
 use CSV::Parser;
 use Terminal::UI 'ui';
 use Terminal::ANSI::OO 't';
@@ -83,9 +85,9 @@ multi sub MAIN (
                 my $outgoing = .grep(*.[2] eqv "Outgoing Call").map(*.[4]).sum;
                 my $incoming = .grep(*.[2] eqv "Incoming Call").map(*.[4]).sum;
 
-                $p1.put: "%-*s %.2f hours".sprintf($fmt, "Outgoing:", $outgoing / 3600);
-                $p1.put: "%-*s %.2f hours".sprintf($fmt, "Incoming:",  $incoming / 3600);
-                $p1.put: "%-*s %.2f hours".sprintf($fmt, "Total:",  ($incoming + $outgoing) / 3600);
+                $p1.put: "%-*s %s".sprintf($fmt, "Outgoing:", seconds-to-str($outgoing));
+                $p1.put: "%-*s %s".sprintf($fmt, "Incoming:",  seconds-to-str($incoming));
+                $p1.put: "%-*s %s".sprintf($fmt, "Total:",  seconds-to-str($outgoing + $incoming));
                 $p1.put: "";
             }
         } elsif %meta<number> -> $num {
@@ -99,9 +101,9 @@ multi sub MAIN (
                 my $outgoing = .grep(*.[2] eqv "Outgoing Call").map(*.[4]).sum;
                 my $incoming = .grep(*.[2] eqv "Incoming Call").map(*.[4]).sum;
 
-                $p1.put: "%-*s %.2f hours".sprintf($fmt, "Outgoing:", $outgoing / 3600);
-                $p1.put: "%-*s %.2f hours".sprintf($fmt, "Incoming:", $incoming / 3600);
-                $p1.put: "%-*s %.2f hours".sprintf($fmt, "Total:", ($incoming + $outgoing) / 3600);
+                $p1.put: "%-*s %s".sprintf($fmt, "Outgoing:", seconds-to-str($outgoing));
+                $p1.put: "%-*s %s".sprintf($fmt, "Incoming:", seconds-to-str($incoming));
+                $p1.put: "%-*s %s".sprintf($fmt, "Total:", seconds-to-str($outgoing + $incoming));
                 $p1.put: "";
 
                 $p1.put: "%-*s %d".sprintf($fmt, "Declined:",
@@ -118,6 +120,7 @@ multi sub MAIN (
     ui.shutdown;
 }
 
+
 multi sub MAIN(
     Bool :$version #= print version
 ) is export { put "Taurus v" ~ $?DISTRIBUTION.meta<version>; }
diff --git a/lib/Taurus/Seconds.rakumod b/lib/Taurus/Seconds.rakumod
new file mode 100644
index 0000000..647f96d
--- /dev/null
+++ b/lib/Taurus/Seconds.rakumod
@@ -0,0 +1,11 @@
+unit module Taurus::Seconds;
+
+sub seconds-to-str(UInt $seconds --> Str) is export {
+    given $seconds {
+        when * < 60 { $seconds ~ "s" }
+        when * < 3600 { "%2dm %2ds".sprintf($_ div 60, $_ % 60) }
+        when * < 86400 { "%2dh %2dm %2ds".sprintf($_ div 3600, ($_ % 3600) div 60, $_ % 60) }
+        default { "%dd %2dh %2dm %2ds"
+                  .sprintf($_ div 86400, ($_ % 86400) div 3600, ($_ % 3600) div 60, $_ % 60) }
+    }
+}