[open-ils-commits] r12526 - trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD (djfiander)

svn at svn.open-ils.org svn at svn.open-ils.org
Sat Mar 14 23:16:19 EDT 2009


Author: djfiander
Date: 2009-03-14 23:16:17 -0400 (Sat, 14 Mar 2009)
New Revision: 12526

Modified:
   trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm
Log:
Add code to support setting volume number based on date rather
than number of issues per volume.


Modified: trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm
===================================================================
--- trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm	2009-03-14 21:28:04 UTC (rev 12525)
+++ trunk/Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Holding.pm	2009-03-15 03:16:17 UTC (rev 12526)
@@ -259,6 +259,15 @@
     return @new;
 }
 
+# Test to see if $m1/$d1 is on or after $m2/$d2
+# if $d2 is undefined, test is based on just months
+sub on_or_after {
+    my ($m1, $d1, $m2, $d2) = @_;
+
+    return (($m1 > $m2)
+	    || ($m1 == $m2 && ((!defined $d2) || ($d1 >= $d2))));
+}
+
 sub next_date {
     my $self = shift;
     my $next = shift;
@@ -308,7 +317,51 @@
     # Figure out if we need to adust volume number
     # right now just use the $carry that was passed in.
     # in long run, need to base this on ($carry or date_change)
-    $next->{'a'} += $carry;
+    if ($carry) {
+	# if $carry is set, the date doesn't matter: we're not
+	# going to increment the v. number twice at year-change.
+	$next->{a} += $carry;
+    } elsif ($caption->subfield('x')) {
+	my $cal_change = $caption->subfield('x');
+	my $month;
+	my $day;
+	my $cur_before;
+	my $new_on_or_after;
+
+	# A calendar change is defined, need to check if it applies
+	if ((scalar(@new) == 2 && $new[1] > 20) || (scalar(@new) == 1)) {
+	    carp "Can't calculate date change for ", $caption->as_string;
+	    return;
+	}
+
+	if (length($cal_change) == 2) {
+	    $month = $cal_change;
+	} elsif (length($cal_change) == 4) {
+	    ($month, $day) = unpack("a2a2", $cal_change);
+	}
+
+# 	print "# next_date: month = '$month', day = '$day'\n";
+# 	print "# next_date: cur[0] = '$cur[0]', cur[1] = '$cur[1]'\n";
+# 	print "# next_date: new[0] = '$new[0]', new[1] = '$new[1]'\n";
+
+	if ($cur[0] == $new[0]) {
+	    # Same year, so a 'simple' month/day comparison will be fine
+	    $next->{a} += (!on_or_after($cur[1], $cur[2], $month, $day)
+			   && on_or_after($new[1], $new[2], $month, $day));
+	} else {
+	    # @cur is in the year before @new. There are
+	    # two possible cases for the calendar change date that
+	    # indicate that it's time to change the volume:
+	    # (1) the change date is AFTER @cur in the year, or
+	    # (2) the change date is BEFORE @new in the year.
+	    # 
+	    #  -------|------|------X------|------|
+	    #       @cur    (1)   Jan 1   (2)   @new
+
+	    $next->{a} += (on_or_after($new[1], $new[2], $month, $day)
+			   || !on_or_after($cur[1], $cur[2], $month, $day));
+	}
+    }
 }
 
 sub next_alt_enum {



More information about the open-ils-commits mailing list