Fix calculation of of date correction.
authordjfiander <djfiander@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 8 Jul 2009 21:42:54 +0000 (21:42 +0000)
committerdjfiander <djfiander@dcc99617-32d9-48b4-a31d-7c20da2025e4>
Wed, 8 Jul 2009 21:42:54 +0000 (21:42 +0000)
git-svn-id: svn://svn.open-ils.org/ILS/trunk@13540 dcc99617-32d9-48b4-a31d-7c20da2025e4

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

index 8d67b70..b2b9ac1 100644 (file)
@@ -72,7 +72,7 @@ sub subsequent_day {
     if (exists $daynames{$pat}) {
        # dd: published on the given weekday
        my $dow = $dt->day_of_week;
-       my $corr = ($dow - $daynames{$pat} + 7) % 7;
+       my $corr = ($daynames{$pat} - $dow + 7) % 7;
 
        if ($dow == $daynames{$pat}) {
            # the next one is one week hence
@@ -276,14 +276,11 @@ sub subsequent_week {
            # Every week
            $candidate = $dt->clone;
 
-#          printf("# subsequent_week: DateTime->clone() failed\n")
-#            if !defined($candidate);
-
            if ($dt->day_of_week == $daynames{$day}) {
                # Current is right day, next one is a week hence
                $candidate->add(days => 7);
            } else {
-               $candidate->add(days => ($dt->day_of_week - $daynames{$day} + 7) % 7);
+               $candidate->add(days => ($daynames{$day} - $dt->day_of_week + 7) % 7);
            }
        } else {
            # 3rd Friday of the month (eg)
@@ -306,6 +303,9 @@ sub subsequent_week {
        # MMWWdd: published on given weekday of given week of given month
        my ($month, $week, $day) = ($1, $2, $3);
 
+#      printf("# subsequent_week: matched /MMWWdd/: month='%s', week='%s', day='%s'\n",
+#             $month, $week, $day);
+
        $candidate = DateTime->new(year => $dt->year,
                                   month=> $month,
                                   day  => 1);