Merge branch 'master' of git.evergreen-ils.org:Evergreen into social
[evergreen-equinox.git] / Open-ILS / src / perlmods / lib / OpenILS / Utils / MFHD / Date.pm
index 34c85d9..e442347 100644 (file)
@@ -5,6 +5,7 @@ use Carp;
 
 use Data::Dumper;
 use DateTime;
+use OpenILS::Utils::MFHD::Caption;
 
 use base 'Exporter';
 
@@ -62,9 +63,13 @@ sub match_day {
     }
 }
 
+# TODO: possible support for extraneous $yp information
+# ex. $ypdtu but on a bi-weekly (currently assumes weekly)
 sub subsequent_day {
     my $pat = shift;
-    my @cur = @_;
+    my $cur = shift;
+
+    my @cur = @$cur;
     my $dt  = DateTime->new(
         year  => $cur[0],
         month => $cur[1],
@@ -103,7 +108,7 @@ sub subsequent_day {
         # MMDD: published on the given day of the given month
         my ($mon, $day) = unpack("a2a2", $pat);
 
-        if (on_or_after($mon, $day, $cur[1], $cur[2])) {
+        if (MFHD::Caption::on_or_after([$cur[1], $cur[2]], [$mon, $day])) {
             # Current date is on or after pattern; next one is next year
             $cur[0] += 1;
         }
@@ -280,7 +285,9 @@ sub match_week {
 #
 sub subsequent_week {
     my $pat = shift;
-    my @cur = @_;
+    my $cur = shift;
+
+    my @cur = @$cur;
     my $candidate;
     my $dt;
 
@@ -388,7 +395,9 @@ sub match_month {
 
 sub subsequent_month {
     my $pat = shift;
-    my @cur = @_;
+    my $cur = shift;
+
+    my @cur = @$cur;
 
     if ($cur[1] >= $pat) {
         # Current date is on or after the patter date, so the next
@@ -411,7 +420,10 @@ sub match_season {
 
 sub subsequent_season {
     my $pat = shift;
-    my @cur = @_;
+    my $cur = shift;
+    my $caption = shift;
+
+    my @cur = @$cur;
 
 #     printf("# subsequent_season: pat='%s', cur='%s'\n", $pat, join('/',@cur));
 
@@ -420,6 +432,15 @@ sub subsequent_season {
         return undef;
     }
 
+    if ($caption->winter_starts_year()) {
+        if ($pat == 24) {
+            $pat = 20; # fake early winter
+        }
+        if ($cur[1] == 24) {
+            $cur[1] = 20; # fake early winter
+        }
+    }
+
     if ($cur[1] >= $pat) {
         # current season is on or past pattern season in this year,
         # advance to next year
@@ -445,6 +466,8 @@ sub subsequent_year {
     my $pat = shift;
     my $cur = shift;
 
+    my @cur = @$cur;
+
     # XXX WRITE ME
     return undef;
 }
@@ -463,6 +486,8 @@ sub subsequent_issue {
     my $pat = shift;
     my $cur = shift;
 
+    my @cur = @$cur;
+
     # Issue generation is handled separately
     return undef;
 }
@@ -509,6 +534,7 @@ my %increments = (
     i => {days   => 2},     # three times / week
     j => {days   => 10},    # three times /month
                             # k => continuous
+#    l => {weeks  => 3},     # triweekly (NON-STANDARD)
     m => {months => 1},     # monthly
     q => {months => 3},     # quarterly
     s => {days   => 15},    # semimonthly