Bug 24545: Fix license statements
[srvgit] / Koha / Calendar.pm
index 9781f69..dfc358d 100644 (file)
@@ -218,7 +218,7 @@ sub addDays {
                 my $dow = $base_date->day_of_week;
                 my $days = $days_duration->in_units('days');
                 # Is it a period based on weeks
-                my $push_amt = $days_duration % 7 == 0 ?
+                my $push_amt = $days % 7 == 0 ?
                     $self->get_push_amt($base_date) : 1;
                 if ( $days_duration->is_negative() ) {
                     $base_date = $self->prev_open_days($base_date, $push_amt);
@@ -310,6 +310,8 @@ sub prev_open_days {
 
     while ($self->is_holiday($base_date)) {
         my $sub_next = $self->get_push_amt($base_date);
+        # Ensure we're subtracting when we need to be
+        $sub_next = $sub_next > 0 ? 0 - $sub_next : $sub_next;
         $base_date->add(days => $sub_next);
     }
 
@@ -345,31 +347,33 @@ sub days_between {
     }
 
     # start and end should not be closed days
-    my $days = $start_dt->delta_days($end_dt)->delta_days;
+    my $delta_days = $start_dt->delta_days($end_dt)->delta_days;
     while( $start_dt->compare($end_dt) < 1 ) {
-        $days-- if $self->is_holiday($start_dt);
+        $delta_days-- if $self->is_holiday($start_dt);
         $start_dt->add( days => 1 );
     }
-    return DateTime::Duration->new( days => $days );
+    return DateTime::Duration->new( days => $delta_days );
 }
 
 sub hours_between {
     my ($self, $start_date, $end_date) = @_;
     my $start_dt = $start_date->clone()->set_time_zone('floating');
     my $end_dt = $end_date->clone()->set_time_zone('floating');
+
     my $duration = $end_dt->delta_ms($start_dt);
     $start_dt->truncate( to => 'day' );
     $end_dt->truncate( to => 'day' );
+
     # NB this is a kludge in that it assumes all days are 24 hours
     # However for hourly loans the logic should be expanded to
     # take into account open/close times then it would be a duration
     # of library open hours
-    # start and end should not be closed days
     my $skipped_days = 0;
     while( $start_dt->compare($end_dt) < 1 ) {
-        $start_dt->add( days => 1 );
         $skipped_days++ if $self->is_holiday($start_dt);
+        $start_dt->add( days => 1 );
     }
+
     if ($skipped_days) {
         $duration->subtract_duration(DateTime::Duration->new( hours => 24 * $skipped_days));
     }
@@ -451,6 +455,14 @@ C<$offset> is a DateTime::Duration to add to it
 
 C<$return_by_hour> is an integer value representing the opening hour for the branch
 
+=head2 get_push_amt
+
+    my $amt = $calendar->get_push_amt($date)
+
+C<$date> is a DateTime object representing a closed return date
+
+Using the days_mode syspref value and the nature of the closed return
+date, return how many days we should jump forward to find another return date
 
 =head2 addDays
 
@@ -486,7 +498,19 @@ $duration = $calendar->days_between($start_dt, $end_dt);
 
 Passed two dates returns a DateTime::Duration object measuring the length between them
 ignoring closed days. Always returns a positive number irrespective of the
-relative order of the parameters
+relative order of the parameters.
+
+Note: This routine assumes neither the passed start_dt nor end_dt can be a closed day
+
+=head2 hours_between
+
+$duration = $calendar->hours_between($start_dt, $end_dt);
+
+Passed two dates returns a DateTime::Duration object measuring the length between them
+ignoring closed days. Always returns a positive number irrespective of the
+relative order of the parameters.
+
+Note: This routine assumes neither the passed start_dt nor end_dt can be a closed day
 
 =head2 next_open_days
 
@@ -539,15 +563,15 @@ Colin Campbell colin.campbell@ptfs-europe.com
 
 Copyright (c) 2011 PTFS-Europe Ltd All rights reserved
 
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
+Koha is free software; you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+Koha is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
+along with Koha; if not, see <http://www.gnu.org/licenses>.