Commits

Shlomi Fish committed 2cd4a9c

Test and fixed 1h04s.

Comments (0)

Files changed (2)

App-Countdown/lib/App/Countdown.pm

 package App::Countdown;
 
-use 5.008;
+use 5.010;
 
 use strict;
 use warnings FATAL => 'all';
 
 my $up_to_60_re = qr/[1-9]|[1-5][0-9]|0[0-9]?/;
 
-sub _calc_delay {
+sub _get_up_to_60_val
+{
+    my ($v) = @_;
+
+    ($v //= '') =~ s/\A0*//;
+
+    return (length($v) ? $v : 0);
+}
+
+sub _calc_delay
+{
     my ($self, $delay_spec) = @_;
 
     if (my ($n, $qualifier) = $delay_spec =~ /\A((?:[1-9][0-9]*(?:\.\d*)?)|(?:0\.\d+))([mhs]?)\z/)
     }
     elsif (my ($min, $sec) = $delay_spec =~ /\A([1-9][0-9]*)m($up_to_60_re)s\z/)
     {
-        $sec =~ s/\A0*//;
-        return $min * 60 + (length($sec) ? $sec : 0);
+        return $min * 60 + _get_up_to_60_val($sec);
     }
     elsif (((my $hour), $min, $sec) =
         $delay_spec =~ /\A([1-9][0-9]*)h(?:($up_to_60_re)m)?(?:($up_to_60_re)s)?\z/
     )
     {
-        $sec =~ s/\A0*//;
-        $min =~ s/\A0*//;
-        return (($hour * 60 + $min) * 60 + $sec);
+        return (($hour * 60 + _get_up_to_60_val($min)) * 60 + _get_up_to_60_val($sec));
     }
     else
     {

App-Countdown/t/unit-calc-delay.t

 use strict;
 use warnings;
 
-use Test::More tests => 14;
+use Test::More tests => 15;
 
 use App::Countdown;
 
 
     # TEST
     is ($obj->_calc_delay('1h30m20s'), ((1*60+30)*60+20), "_calc_delay(1h30m20s) == right number (seconds)");
+
+    # TEST
+    is ($obj->_calc_delay('1h04s'), (1*60*60+4), "_calc_delay(1h04s) == right number (seconds)");
 }