LP#1198465 Move seconds_to_interval_hash helper function
authorDan Wells <dbw2@calvin.edu>
Wed, 3 Dec 2014 19:17:39 +0000 (14:17 -0500)
committerDan Wells <dbw2@calvin.edu>
Mon, 8 Dec 2014 14:38:19 +0000 (09:38 -0500)
This function was only used by generate_fines, so let's move it
entirely to CircCommon.pm.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
Open-ILS/src/perlmods/lib/OpenILS/Application/Circ/CircCommon.pm
Open-ILS/src/perlmods/lib/OpenILS/Application/Storage/Publisher/action.pm

index 50611cc..4687cf6 100644 (file)
@@ -256,6 +256,73 @@ sub can_close_circ {
     return $can_close;
 }
 
+sub seconds_to_interval_hash {
+        my $interval = shift;
+        my $limit = shift || 's';
+        $limit =~ s/^(.)/$1/o;
+
+        my %output;
+
+        my ($y,$ym,$M,$Mm,$w,$wm,$d,$dm,$h,$hm,$m,$mm,$s);
+        my ($year, $month, $week, $day, $hour, $minute, $second) =
+                ('years','months','weeks','days', 'hours', 'minutes', 'seconds');
+
+        if ($y = int($interval / (60 * 60 * 24 * 365))) {
+                $output{$year} = $y;
+                $ym = $interval % (60 * 60 * 24 * 365);
+        } else {
+                $ym = $interval;
+        }
+        return %output if ($limit eq 'y');
+
+        if ($M = int($ym / ((60 * 60 * 24 * 365)/12))) {
+                $output{$month} = $M;
+                $Mm = $ym % ((60 * 60 * 24 * 365)/12);
+        } else {
+                $Mm = $ym;
+        }
+        return %output if ($limit eq 'M');
+
+        if ($w = int($Mm / 604800)) {
+                $output{$week} = $w;
+                $wm = $Mm % 604800;
+        } else {
+                $wm = $Mm;
+        }
+        return %output if ($limit eq 'w');
+
+        if ($d = int($wm / 86400)) {
+                $output{$day} = $d;
+                $dm = $wm % 86400;
+        } else {
+                $dm = $wm;
+        }
+        return %output if ($limit eq 'd');
+
+        if ($h = int($dm / 3600)) {
+                $output{$hour} = $h;
+                $hm = $dm % 3600;
+        } else {
+                $hm = $dm;
+        }
+        return %output if ($limit eq 'h');
+
+        if ($m = int($hm / 60)) {
+                $output{$minute} = $m;
+                $mm = $hm % 60;
+        } else {
+                $mm = $hm;
+        }
+        return %output if ($limit eq 'm');
+
+        if ($s = int($mm)) {
+                $output{$second} = $s;
+        } else {
+                $output{$second} = 0 unless (keys %output);
+        }
+        return %output;
+}
+
 sub generate_fines {
     my $self = shift;
     my $client = shift;
index 0452676..53a7d0a 100644 (file)
@@ -970,74 +970,6 @@ __PACKAGE__->register_method(
     method          => 'find_usr_summary_surveys',
 );
 
-sub seconds_to_interval_hash {
-        my $interval = shift;
-        my $limit = shift || 's';
-        $limit =~ s/^(.)/$1/o;
-
-        my %output;
-
-        my ($y,$ym,$M,$Mm,$w,$wm,$d,$dm,$h,$hm,$m,$mm,$s);
-        my ($year, $month, $week, $day, $hour, $minute, $second) =
-                ('years','months','weeks','days', 'hours', 'minutes', 'seconds');
-
-        if ($y = int($interval / (60 * 60 * 24 * 365))) {
-                $output{$year} = $y;
-                $ym = $interval % (60 * 60 * 24 * 365);
-        } else {
-                $ym = $interval;
-        }
-        return %output if ($limit eq 'y');
-
-        if ($M = int($ym / ((60 * 60 * 24 * 365)/12))) {
-                $output{$month} = $M;
-                $Mm = $ym % ((60 * 60 * 24 * 365)/12);
-        } else {
-                $Mm = $ym;
-        }
-        return %output if ($limit eq 'M');
-
-        if ($w = int($Mm / 604800)) {
-                $output{$week} = $w;
-                $wm = $Mm % 604800;
-        } else {
-                $wm = $Mm;
-        }
-        return %output if ($limit eq 'w');
-
-        if ($d = int($wm / 86400)) {
-                $output{$day} = $d;
-                $dm = $wm % 86400;
-        } else {
-                $dm = $wm;
-        }
-        return %output if ($limit eq 'd');
-
-        if ($h = int($dm / 3600)) {
-                $output{$hour} = $h;
-                $hm = $dm % 3600;
-        } else {
-                $hm = $dm;
-        }
-        return %output if ($limit eq 'h');
-
-        if ($m = int($hm / 60)) {
-                $output{$minute} = $m;
-                $mm = $hm % 60;
-        } else {
-                $mm = $hm;
-        }
-        return %output if ($limit eq 'm');
-
-        if ($s = int($mm)) {
-                $output{$second} = $s;
-        } else {
-                $output{$second} = 0 unless (keys %output);
-        }
-        return %output;
-}
-
-
 sub generate_fines {
     my $self = shift;
     my $client = shift;