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

(-)a/C4/Circulation.pm (-1 / +1 lines)
Lines 3581-3587 sub CalcDateDue { Link Here
3581
          my $calendar = Koha::Calendar->new( branchcode => $branch );
3581
          my $calendar = Koha::Calendar->new( branchcode => $branch );
3582
          if ( $calendar->is_holiday($datedue) ) {
3582
          if ( $calendar->is_holiday($datedue) ) {
3583
              # Don't return on a closed day
3583
              # Don't return on a closed day
3584
              $datedue = $calendar->prev_open_day( $datedue );
3584
              $datedue = $calendar->prev_open_days( $datedue, 1 );
3585
          }
3585
          }
3586
        }
3586
        }
3587
    }
3587
    }
(-)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 468-488 Passed two dates returns a DateTime::Duration object measuring the length betwee Link Here
468
ignoring closed days. Always returns a positive number irrespective of the
472
ignoring closed days. Always returns a positive number irrespective of the
469
relative order of the parameters
473
relative order of the parameters
470
474
471
=head2 next_open_day
475
=head2 next_open_days
472
476
473
$datetime = $calendar->next_open_day($duedate_dt)
477
$datetime = $calendar->next_open_days($duedate_dt, $to_add)
474
478
475
Passed a Datetime returns another Datetime representing the next open day. It is
479
Passed a Datetime and number of days,  returns another Datetime representing
476
intended for use to calculate the due date when useDaysMode syspref is set to either
480
the next open day after adding the passed number of days. It is intended for
477
'Datedue' or 'Calendar'.
481
use to calculate the due date when useDaysMode syspref is set to either
482
'Datedue', 'Calendar' or 'Dayweek'.
478
483
479
=head2 prev_open_day
484
=head2 prev_open_days
480
485
481
$datetime = $calendar->prev_open_day($duedate_dt)
486
$datetime = $calendar->prev_open_days($duedate_dt, $to_sub)
482
487
483
Passed a Datetime returns another Datetime representing the previous open day. It is
488
Passed a Datetime and a number of days, returns another Datetime
484
intended for use to calculate the due date when useDaysMode syspref is set to either
489
representing the previous open day after subtracting the number of passed
485
'Datedue' or 'Calendar'.
490
days. It is intended for use to calculate the due date when useDaysMode
491
syspref is set to either 'Datedue', 'Calendar' or 'Dayweek'.
486
492
487
=head2 set_daysmode
493
=head2 set_daysmode
488
494
(-)a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl (-3 / +2 lines)
Lines 337-343 sub GetWaitingHolds { Link Here
337
        my $waiting_date = dt_from_string( $issue->{waitingdate}, 'sql' );
337
        my $waiting_date = dt_from_string( $issue->{waitingdate}, 'sql' );
338
        my $pickup_date = $waiting_date->clone->add( days => $pickupdelay );
338
        my $pickup_date = $waiting_date->clone->add( days => $pickupdelay );
339
        if ( $calendar->is_holiday($pickup_date) ) {
339
        if ( $calendar->is_holiday($pickup_date) ) {
340
            $pickup_date = $calendar->next_open_day( $pickup_date );
340
            $pickup_date = $calendar->next_open_days( $pickup_date, 1 );
341
        }
341
        }
342
342
343
        $issue->{'date_due'} = output_pref({dt => $pickup_date, dateformat => 'iso' });
343
        $issue->{'date_due'} = output_pref({dt => $pickup_date, dateformat => 'iso' });
Lines 345-351 sub GetWaitingHolds { Link Here
345
345
346
        my $days_to_subtract = 0;
346
        my $days_to_subtract = 0;
347
        if ( $calendar->is_holiday($waiting_date) ) {
347
        if ( $calendar->is_holiday($waiting_date) ) {
348
            my $next_open_day = $calendar->next_open_day( $waiting_date );
348
            my $next_open_day = $calendar->next_open_days( $waiting_date, 1 );
349
            $days_to_subtract = $calendar->days_between($waiting_date, $next_open_day)->days;
349
            $days_to_subtract = $calendar->days_between($waiting_date, $next_open_day)->days;
350
        }
350
        }
351
351
352
- 

Return to bug 15260