View | Details | Raw Unified | Return to bug 15260
Collapse All | Expand All

(-)a/C4/Circulation.pm (-1 / +1 lines)
Lines 3537-3543 sub CalcDateDue { Link Here
3537
          my $calendar = Koha::Calendar->new( branchcode => $branch );
3537
          my $calendar = Koha::Calendar->new( branchcode => $branch );
3538
          if ( $calendar->is_holiday($datedue) ) {
3538
          if ( $calendar->is_holiday($datedue) ) {
3539
              # Don't return on a closed day
3539
              # Don't return on a closed day
3540
              $datedue = $calendar->prev_open_day( $datedue );
3540
              $datedue = $calendar->prev_open_days( $datedue, 1 );
3541
          }
3541
          }
3542
        }
3542
        }
3543
    }
3543
    }
(-)a/Koha/Calendar.pm (-23 / +29 lines)
Lines 171-179 sub addHours { Link Here
171
          $self->is_holiday($base_date) ) {
171
          $self->is_holiday($base_date) ) {
172
172
173
        if ( $hours_duration->is_negative() ) {
173
        if ( $hours_duration->is_negative() ) {
174
            $base_date = $self->prev_open_day($base_date);
174
            $base_date = $self->prev_open_days($base_date, 1);
175
        } else {
175
        } else {
176
            $base_date = $self->next_open_day($base_date);
176
            $base_date = $self->next_open_days($base_date, 1);
177
        }
177
        }
178
178
179
        $base_date->set_hour($return_by_hour);
179
        $base_date->set_hour($return_by_hour);
Lines 196-207 sub addDays { Link Here
196
196
197
        if ( $days_duration->is_negative() ) {
197
        if ( $days_duration->is_negative() ) {
198
            while ($days) {
198
            while ($days) {
199
                $base_date = $self->prev_open_day($base_date);
199
                $base_date = $self->prev_open_days($base_date, 1);
200
                --$days;
200
                --$days;
201
            }
201
            }
202
        } else {
202
        } else {
203
            while ($days) {
203
            while ($days) {
204
                $base_date = $self->next_open_day($base_date);
204
                $base_date = $self->next_open_days($base_date, 1);
205
                --$days;
205
                --$days;
206
            }
206
            }
207
        }
207
        }
Lines 270-296 sub is_holiday { Link Here
270
    return 0;
270
    return 0;
271
}
271
}
272
272
273
sub next_open_day {
273
sub next_open_days {
274
    my ( $self, $dt ) = @_;
274
    my ( $self, $dt, $to_add ) = @_;
275
    my $base_date = $dt->clone();
275
    my $base_date = $dt->clone();
276
276
277
    $base_date->add(days => 1);
277
    $base_date->add(days => $to_add);
278
278
279
    while ($self->is_holiday($base_date)) {
279
    while ($self->is_holiday($base_date)) {
280
        $base_date->add(days => 1);
280
        $base_date->add(days => $to_add);
281
    }
281
    }
282
282
283
    return $base_date;
283
    return $base_date;
284
}
284
}
285
285
286
sub prev_open_day {
286
sub prev_open_days {
287
    my ( $self, $dt ) = @_;
287
    my ( $self, $dt, $to_sub ) = @_;
288
    my $base_date = $dt->clone();
288
    my $base_date = $dt->clone();
289
289
290
    $base_date->add(days => -1);
290
    # It feels logical to be passed a positive number, though we're
291
    # subtracting, so do the right thing
292
    $to_sub = $to_sub > 0 ? 0 - $to_sub : $to_sub;
293
294
    $base_date->add(days => $to_sub);
291
295
292
    while ($self->is_holiday($base_date)) {
296
    while ($self->is_holiday($base_date)) {
293
        $base_date->add(days => -1);
297
        $base_date->add(days => $to_sub);
294
    }
298
    }
295
299
296
    return $base_date;
300
    return $base_date;
Lines 306-312 sub days_forward { Link Here
306
    my $base_dt = $start_dt->clone();
310
    my $base_dt = $start_dt->clone();
307
311
308
    while ($num_days--) {
312
    while ($num_days--) {
309
        $base_dt = $self->next_open_day($base_dt);
313
        $base_dt = $self->next_open_days($base_dt, 1);
310
    }
314
    }
311
315
312
    return $base_dt;
316
    return $base_dt;
Lines 472-492 Passed two dates returns a DateTime::Duration object measuring the length betwee Link Here
472
ignoring closed days. Always returns a positive number irrespective of the
476
ignoring closed days. Always returns a positive number irrespective of the
473
relative order of the parameters
477
relative order of the parameters
474
478
475
=head2 next_open_day
479
=head2 next_open_days
476
480
477
$datetime = $calendar->next_open_day($duedate_dt)
481
$datetime = $calendar->next_open_days($duedate_dt, $to_add)
478
482
479
Passed a Datetime returns another Datetime representing the next open day. It is
483
Passed a Datetime and number of days,  returns another Datetime representing
480
intended for use to calculate the due date when useDaysMode syspref is set to either
484
the next open day after adding the passed number of days. It is intended for
481
'Datedue' or 'Calendar'.
485
use to calculate the due date when useDaysMode syspref is set to either
486
'Datedue', 'Calendar' or 'Dayweek'.
482
487
483
=head2 prev_open_day
488
=head2 prev_open_days
484
489
485
$datetime = $calendar->prev_open_day($duedate_dt)
490
$datetime = $calendar->prev_open_days($duedate_dt, $to_sub)
486
491
487
Passed a Datetime returns another Datetime representing the previous open day. It is
492
Passed a Datetime and a number of days, returns another Datetime
488
intended for use to calculate the due date when useDaysMode syspref is set to either
493
representing the previous open day after subtracting the number of passed
489
'Datedue' or 'Calendar'.
494
days. It is intended for use to calculate the due date when useDaysMode
495
syspref is set to either 'Datedue', 'Calendar' or 'Dayweek'.
490
496
491
=head2 set_daysmode
497
=head2 set_daysmode
492
498
(-)a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl (-3 / +2 lines)
Lines 307-313 sub GetWaitingHolds { Link Here
307
        my $waiting_date = dt_from_string( $issue->{waitingdate}, 'sql' );
307
        my $waiting_date = dt_from_string( $issue->{waitingdate}, 'sql' );
308
        my $pickup_date = $waiting_date->clone->add( days => $pickupdelay );
308
        my $pickup_date = $waiting_date->clone->add( days => $pickupdelay );
309
        if ( $calendar->is_holiday($pickup_date) ) {
309
        if ( $calendar->is_holiday($pickup_date) ) {
310
            $pickup_date = $calendar->next_open_day( $pickup_date );
310
            $pickup_date = $calendar->next_open_days( $pickup_date, 1 );
311
        }
311
        }
312
312
313
        $issue->{'date_due'} = output_pref({dt => $pickup_date, dateformat => 'iso' });
313
        $issue->{'date_due'} = output_pref({dt => $pickup_date, dateformat => 'iso' });
Lines 315-321 sub GetWaitingHolds { Link Here
315
315
316
        my $days_to_subtract = 0;
316
        my $days_to_subtract = 0;
317
        if ( $calendar->is_holiday($waiting_date) ) {
317
        if ( $calendar->is_holiday($waiting_date) ) {
318
            my $next_open_day = $calendar->next_open_day( $waiting_date );
318
            my $next_open_day = $calendar->next_open_days( $waiting_date, 1 );
319
            $days_to_subtract = $calendar->days_between($waiting_date, $next_open_day)->days;
319
            $days_to_subtract = $calendar->days_between($waiting_date, $next_open_day)->days;
320
        }
320
        }
321
321
322
- 

Return to bug 15260