Serials: Fix a problem with chronology prediction when there's
authorsenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 12 Jan 2011 00:24:51 +0000 (00:24 +0000)
committersenator <senator@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 12 Jan 2011 00:24:51 +0000 (00:24 +0000)
a subfield $y in a caption/pattern with a weekly chronology code

Illustrative 853 tag:
 $2$0$8$1$a$v.$b$no.$u$50$v$r$i$(year)$j$(month)$k$(day)$w$w$x$01$y$ow1198,1204
Holding (863) tag:
 $4$1$8$1$a$1$b$39$i$2011$j$09$k$26$x$AUTOGEN

Before this commit, you get a run of predictions that look like this:
v.1:no.40(2011:Oct.03)
v.1:no.41(2011:Oct.10)
v.1:no.42(2011:Oct.17)
v.1:no.43(2011:Oct.24)
v.1:no.44(2011:Oct.31)
v.1:no.45(2011:Nov.07)
v.1:no.46(2011:Nov.21)
v.1:no.47(2011:Nov.28)
v.1:no.48(2011:Dec.05)
v.1:no.49(2011:Dec.12)
v.1:no.50(2011:Dec.26)
v.2:no.1(2012:Jan.02)

Which I'm pretty sure is wrong.  The next-to-last week in November should have
been skipped, and the fourth week in December should have been skipped.  I think
the week number should be defined in terms of the day of the week on which this
weekly serial is published, so fourth week means fourth Monday in this case (?).

With this commit, you get a run of predictions that look like:
v.1:no.40(2011:Oct.03)
v.1:no.41(2011:Oct.10)
v.1:no.42(2011:Oct.17)
v.1:no.43(2011:Oct.24)
v.1:no.44(2011:Oct.31)
v.1:no.45(2011:Nov.07)
v.1:no.46(2011:Nov.14)
v.1:no.47(2011:Nov.28)
v.1:no.48(2011:Dec.05)
v.1:no.49(2011:Dec.12)
v.1:no.50(2011:Dec.19)
v.2:no.1(2012:Jan.02)

Which seems correct to me. I'm going to consult with others before backporting
this to rel_2_0, however.

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

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

index 34c85d9..1a1f4cd 100644 (file)
@@ -167,7 +167,7 @@ sub nth_week_of_month {
         );
     } else {
         # count backwards
-        $nth_day->subtract(days => ($day - $dow + 7) % 7);
+        $nth_day->subtract(days => ($dow - $day + 7) % 7);
 
         # 99: last week of month, 98: second last, etc.
         for (my $i = 99 - $week; $i > 0; $i--) {
@@ -196,15 +196,10 @@ sub check_date {
     if (!defined $day) {
         # MMWW
         return (
-            ($dt->month == $month)
-              && (
-                ($dt->week_of_month == $weekno)
-                || (
-                    $weekno >= 97
-                    && ($dt->week_of_month ==
-                        nth_week_of_month($dt, $weekno, $day)->week_of_month)
-                )
-              )
+            ($dt->month == $month) && (
+                $dt->week_of_month ==
+                    nth_week_of_month($dt, $weekno, $day)->week_of_month
+            )
         );
     }