LP#1474507: fix interval_to_seconds for weeks and seconds
authorJason Etheridge <jason@esilibrary.com>
Tue, 14 Jul 2015 18:54:27 +0000 (14:54 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Thu, 4 Feb 2016 16:33:23 +0000 (11:33 -0500)
This patch fixes an issue where OpenSRF::Utils::interval_to_seconds()
was not recognizing intervals expressed as seconds or weeks.

Signed-off-by: Jason Etheridge <jason@esilibrary.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>

src/perl/lib/OpenSRF/Utils.pm

index 61596d0..bb6858a 100644 (file)
@@ -261,11 +261,11 @@ sub interval_to_seconds {
         while ($interval =~ /\s*([\+-]?)\s*(\d+)\s*(\w+)\s*/g) {
                my ($sign, $count, $type) = ($1, $2, $3);
                $count = "$sign$count" if ($sign);
-                $amount += $count if ($type eq 's');
+                $amount += $count if ($type =~ /^s/);
                 $amount += 60 * $count if ($type =~ /^m(?!o)/oi);
                 $amount += 60 * 60 * $count if ($type =~ /^h/);
                 $amount += 60 * 60 * 24 * $count if ($type =~ /^d/oi);
-                $amount += 60 * 60 * 24 * 7 * $count if (defined $2 && $2 =~ /^w/oi);
+                $amount += 60 * 60 * 24 * 7 * $count if ($type =~ /^w/oi);
                 $amount += ((60 * 60 * 24 * 365)/12) * $count if ($type =~ /^mo/io);
                 $amount += 60 * 60 * 24 * 365 * $count if ($type =~ /^y/oi);
         }