[open-ils-commits] r15857 - trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher (miker)

svn at svn.open-ils.org svn at svn.open-ils.org
Tue Mar 16 10:14:39 EDT 2010


Author: miker
Date: 2010-03-16 10:14:37 -0400 (Tue, 16 Mar 2010)
New Revision: 15857

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm
Log:
use logical date math to avoid problems with DST boundary

Modified: trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm	2010-03-16 14:14:06 UTC (rev 15856)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Application/Storage/Publisher/action.pm	2010-03-16 14:14:37 UTC (rev 15857)
@@ -650,7 +650,74 @@
 	method          => 'find_usr_summary_surveys',
 );
 
+sub seconds_to_interval_hash {
+		my $interval = shift;
+		my $limit = shift || 's';
+		$limit =~ s/^(.)/$1/o;
 
+		my %ouptut;
+
+		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;
@@ -818,7 +885,12 @@
 				}
 				
 				# XXX Use org time zone (or default to 'local') once we have the ou setting built for that
-				my $billing_ts = DateTime->from_epoch( epoch => $last_fine + $fine_interval * $bill, time_zone => 'local' );
+				my $billing_ts = DateTime->from_epoch( epoch => $last_fine, time_zone => 'local' );
+				my $current_bill_count = $bill;
+				while ( $current_bill_count ) {
+					$billing_ts->add( seconds_to_interval_hash( $fine_interval ) );
+					$current_bill_count--;
+				}
 
 				my $dow = $billing_ts->day_of_week_0();
 				my $dow_open = "dow_${dow}_open";



More information about the open-ils-commits mailing list