Commits

Shlomi Fish committed 261db5a

Add support for m.

Comments (0)

Files changed (2)

App-Countdown/lib/App/Countdown.pm

 sub _calc_delay {
     my ($self, $delay_spec) = @_;
 
-    if ($delay_spec !~ /\A[1-9][0-9]*\z/)
+    if (my ($n, $qualifier) = $delay_spec =~ /\A([1-9][0-9]*)([m]?)\z/)
+    {
+        return ($n * ($qualifier eq 'm' ? 60 : 1));
+    }
+    else
     {
         Carp::confess ("Invalid delay. Must be a positive integer.");
     }
-
-    return $delay_spec;
 }
 
 sub _init

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

 use strict;
 use warnings;
 
-use Test::More tests => 2;
+use Test::More tests => 3;
 
 use App::Countdown;
 
 
     # TEST
     is ($obj->_calc_delay('60'), 60, "_calc_delay(60) == 60");
+
+    # TEST
+    is ($obj->_calc_delay('2m'), 120, "_calc_delay(2m) == 120 (2 minutes)");
 }