From: Mischa POSLAWSKY Date: Tue, 15 Nov 2022 12:41:48 +0000 (+0100) Subject: support negative sexagesimal times X-Git-Tag: v1.09~14 X-Git-Url: http://git.shiar.nl/barcat.git/commitdiff_plain/e80d9d3878bb64f7c165c0904bd5513b43faf55f support negative sexagesimal times Work around perl's weird modulo op. --- diff --git a/barcat b/barcat index 1a1112c..fb5c1ab 100755 --- 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) diff --git a/t/t1421-sexy_time.in b/t/t1421-sexy_time.in index 62c17bf..de02594 100644 --- a/t/t1421-sexy_time.in +++ b/t/t1421-sexy_time.in @@ -9,4 +9,3 @@ 35999.5 40271.1 86400 - diff --git a/t/t1421-sexy_time_--sexagesimal.out b/t/t1421-sexy_time_--sexagesimal.out index 8164e5b..dfe88d9 100644 --- a/t/t1421-sexy_time_--sexagesimal.out +++ b/t/t1421-sexy_time_--sexagesimal.out @@ -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 index 0000000..c8fa5a8 --- /dev/null +++ b/t/t1422-all_the_time.in @@ -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 index 0000000..9ba7ac2 --- /dev/null +++ b/t/t1422-all_the_time_--sexagesimal_-H_-sC.out @@ -0,0 +1,10 @@ +0:00:00 - +24:00:00 ---=-- +111:11:11 long ---=------------------------ + +-0:00:00 - +-0:00:01 - +-0:00:01 - +-0:00:02 - +-2:02:02 +479345.21 total in 8 values over 9 lines (-2:02:02 min, 16:38:38 avg, 111:11:11 max)