Untested code for generating next dates for all patterns
authordjfiander <djfiander@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 12 Jun 2009 01:16:55 +0000 (01:16 +0000)
committerdjfiander <djfiander@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Fri, 12 Jun 2009 01:16:55 +0000 (01:16 +0000)
specified in the standard. Now to write the code that calls the
generators to find the correct "next" issue from the current one.

git-svn-id: svn://svn.open-ils.org/ILS/trunk@13374 dcc99617-32d9-48b4-a31d-7c20da2025e4

Open-ILS/src/perlmods/OpenILS/Utils/MFHD/Caption.pm

index d6084d5..ffae611 100755 (executable)
@@ -510,6 +510,25 @@ sub match_season {
     return ($pat eq $date[1]);
 }
 
+sub subsequent_season {
+    my $pat = shift;
+    my $cur = shift;
+
+    return undef if (($pat < 21) || ($pat > 24));
+
+    if ($cur->[1] >= $pat) {
+       # current season is on or past pattern season in this year,
+       # advance to next year
+       $cur->[0] += 1;
+    }
+    # Either we've advanced to the next year or the current season
+    # is before the pattern season in the current year. Either way,
+    # all that remains is to set the season properly
+    $cur->[1] = $pat;
+
+    return $cur;
+}
+
 sub match_year {
     my $pat = shift;
     my @date = @_;
@@ -518,6 +537,14 @@ sub match_year {
     return 0;
 }
 
+sub subsequent_year {
+    my $pat = shift;
+    my $cur = shift;
+
+    # XXX WRITE ME
+    return undef;
+}
+
 sub match_issue {
     my $pat = shift;
     my @date = @_;
@@ -528,6 +555,14 @@ sub match_issue {
     return 0;
 }
 
+sub subsequent_issue {
+    my $pat = shift;
+    my $cur = shift;
+
+    # Issue generation is handled separately
+    return undef;
+}
+
 my %dispatch = (
                'd' => \&match_day,
                'e' => \&match_issue, # not really a "chron" code
@@ -734,6 +769,15 @@ sub calendar_increment {
     }
 }
 
+my %generators = (
+                 'd' => \&subsequent_day,
+                 'e' => \&subsequent_issue, # not a chron code
+                 'w' => \&subsequent_week,
+                 'm' => \&subsequent_month,
+                 's' => \&subsequent_season,
+                 'y' => \&subsequent_year,
+);
+
 sub next_date {
     my $self = shift;
     my $next = shift;