support negative sexagesimal times
authorMischa POSLAWSKY <perl@shiar.org>
Tue, 15 Nov 2022 12:41:48 +0000 (13:41 +0100)
committerMischa POSLAWSKY <perl@shiar.org>
Mon, 21 Nov 2022 15:42:04 +0000 (16:42 +0100)
Work around perl's weird modulo op.

barcat
t/t1421-sexy_time.in
t/t1421-sexy_time_--sexagesimal.out
t/t1422-all_the_time.in [new file with mode: 0644]
t/t1422-all_the_time_--sexagesimal_-H_-sC.out [new file with mode: 0644]

diff --git a/barcat b/barcat
index 1a1112c0ccdfa530e55b1792a7d25bf21f5381c1..fb5c1ab42dbf4172ac734d6719142518a9b82de4 100755 (executable)
--- a/barcat
+++ b/barcat
@@ -131,8 +131,8 @@ $opt{input} = (@ARGV && $ARGV[0] =~ m/\A[-0-9]/) ? \@ARGV : undef
 $opt{'sum-format'} = sub { sprintf '%.8g', $_[0] };
 $opt{'calc-format'} = sub { sprintf '%*.*f', 0, 2, $_[0] };
 $opt{'value-format'} = $opt{sexagesimal} ? sub {
-       my $s = $_[0] + .5;
-       sprintf('%d:%02d:%02d', $s/3600, $s/60%60, $s%60);
+       my $s = abs($_[0]) + .5;
+       sprintf('%s%d:%02d:%02d', $_[0] < 0 && '-', $s/3600, $s/60%60, $s%60);
 } : $opt{units} && sub {
        my $unit = (
                log(abs $_[0] || 1) / log(10)
index 62c17bfabecccfac1d8f021d8c5dacd0b3f2cbd8..de02594b3d4af9ec7cbac67412afbdbeca2c808c 100644 (file)
@@ -9,4 +9,3 @@
 35999.5
 40271.1
 86400
-
index 8164e5bc24059a862bd9d069723bb3ad01e144b7..dfe88d94d483d4b8db1866fdf50e823f5cfd8134 100644 (file)
@@ -9,4 +9,3 @@
 10:00:00 +----=----->-
 11:11:11 +----=----->--
 24:00:00 +----=----->-------------------
-
diff --git a/t/t1422-all_the_time.in b/t/t1422-all_the_time.in
new file mode 100644 (file)
index 0000000..c8fa5a8
--- /dev/null
@@ -0,0 +1,9 @@
+0
+86400
+400271.1 long
+
+-.49
+-.5
+-.9
+-2
+-7322
diff --git a/t/t1422-all_the_time_--sexagesimal_-H_-sC.out b/t/t1422-all_the_time_--sexagesimal_-H_-sC.out
new file mode 100644 (file)
index 0000000..9ba7ac2
--- /dev/null
@@ -0,0 +1,10 @@
+\e[90m0:00:00\e[0m      -
+\e[90m24:00:00\e[0m      ---\e[36m=\e[0m--
+\e[32m111:11:11\e[0m long ---\e[36m=\e[0m------------------------
+
+\e[90m-0:00:00\e[0m      -
+\e[90m-0:00:01\e[0m      -
+\e[90m-0:00:01\e[0m      -
+\e[90m-0:00:02\e[0m      -
+\e[31m-2:02:02\e[0m      
+\e[1m479345.21\e[0m total in 8 values over 9 lines (\e[31m-2:02:02\e[0m min, \e[36m16:38:38\e[0m avg, \e[32m111:11:11\e[0m max)