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

(-)a/C4/Circulation.pm (-6 / +16 lines)
Lines 1161-1166 sub AddIssue { Link Here
1161
	my $barcodecheck=CheckValidBarcode($barcode);
1161
	my $barcodecheck=CheckValidBarcode($barcode);
1162
    if ($datedue && ref $datedue ne 'DateTime') {
1162
    if ($datedue && ref $datedue ne 'DateTime') {
1163
        $datedue = dt_from_string($datedue);
1163
        $datedue = dt_from_string($datedue);
1164
        if ( C4::Context->preference('useDaysMode') eq 'Datedue' ) {
1165
          # use the calendar to push the due date to the next open day
1166
          $datedue = $calendar->next_open_day($datedue);
1167
        }
1164
    }
1168
    }
1165
    # $issuedate defaults to today.
1169
    # $issuedate defaults to today.
1166
    if ( ! defined $issuedate ) {
1170
    if ( ! defined $issuedate ) {
Lines 3004-3025 sub CalcDateDue { Link Here
3004
            C4::Context->preference('dateformat')
3008
            C4::Context->preference('dateformat')
3005
        );
3009
        );
3006
    } else {
3010
    } else {
3007
3008
        # otherwise, calculate the datedue as normal
3011
        # otherwise, calculate the datedue as normal
3009
        if ( C4::Context->preference('useDaysMode') eq 'Days' )
3012
        my $calendar = Koha::Calendar->new( branchcode => $branch );
3010
        {    # ignoring calendar
3013
3014
        if ( C4::Context->preference('useDaysMode') ne 'Calendar' )
3015
        {   # ignoring calendar to calculate date due
3011
            my $dt =
3016
            my $dt =
3012
              DateTime->now( time_zone => C4::Context->tz() )
3017
              DateTime->now( time_zone => C4::Context->tz() )
3013
              ->truncate( to => 'minute' );
3018
              ->truncate( to => 'minute' );
3014
            if ( $loanlength->{lengthunit} eq 'hours' ) {
3019
            if ( $loanlength->{lengthunit} eq 'hours' ) {
3015
                $dt->add( hours => $loanlength->{issuelength} );
3020
                $dt->add( hours => $loanlength->{issuelength} );
3016
                return $dt;
3017
            } else {    # days
3021
            } else {    # days
3018
                $dt->add( days => $loanlength->{issuelength} );
3022
                $dt->add( days => $loanlength->{issuelength} );
3019
                $dt->set_hour(23);
3023
                $dt->set_hour(23);
3020
                $dt->set_minute(59);
3024
                $dt->set_minute(59);
3021
                return $dt;
3022
            }
3025
            }
3026
            
3027
            if ( C4::Context->preference('useDaysMode') eq 'Datedue' ) {
3028
                # use the calendar to push the due date to the next open day
3029
                $dt = $calendar->next_open_day($dt);
3030
            }
3031
3032
            return $dt;
3033
3023
        } else {
3034
        } else {
3024
            my $dur;
3035
            my $dur;
3025
            if ($loanlength->{lengthunit} eq 'hours') {
3036
            if ($loanlength->{lengthunit} eq 'hours') {
Lines 3031-3037 sub CalcDateDue { Link Here
3031
            if (ref $startdate ne 'DateTime' ) {
3042
            if (ref $startdate ne 'DateTime' ) {
3032
                $startdate = dt_from_string($startdate);
3043
                $startdate = dt_from_string($startdate);
3033
            }
3044
            }
3034
            my $calendar = Koha::Calendar->new( branchcode => $branch );
3035
            $datedue = $calendar->addDate( $startdate, $dur, $loanlength->{lengthunit} );
3045
            $datedue = $calendar->addDate( $startdate, $dur, $loanlength->{lengthunit} );
3036
            if ($loanlength->{lengthunit} eq 'days') {
3046
            if ($loanlength->{lengthunit} eq 'days') {
3037
                $datedue->set_hour(23);
3047
                $datedue->set_hour(23);
(-)a/Koha/Calendar.pm (-3 / +23 lines)
Lines 164-169 sub is_holiday { Link Here
164
    return 0;
164
    return 0;
165
}
165
}
166
166
167
sub next_open_day {
168
    my ( $self, $dt ) = @_;
169
170
    while ($self->is_holiday($dt)) {
171
        $dt->add(days => 1);
172
    }
173
174
    return $dt;
175
}
176
167
sub days_between {
177
sub days_between {
168
    my $self     = shift;
178
    my $self     = shift;
169
    my $start_dt = shift;
179
    my $start_dt = shift;
Lines 273-281 This documentation refers to Koha::Calendar version 0.0.1 Link Here
273
283
274
=head1 SYNOPSIS
284
=head1 SYNOPSIS
275
285
276
  use Koha::Calendat
286
  use Koha::Calendar
277
287
278
  my $c = Koha::Calender->new( branchcode => 'MAIN' );
288
  my $c = Koha::Calendar->new( branchcode => 'MAIN' );
279
  my $dt = DateTime->now();
289
  my $dt = DateTime->now();
280
290
281
  # are we open
291
  # are we open
Lines 315-321 parameter will be removed when issuingrules properly cope with that Link Here
315
325
316
$yesno = $calendar->is_holiday($dt);
326
$yesno = $calendar->is_holiday($dt);
317
327
318
passed at DateTime object returns 1 if it is a closed day
328
passed a DateTime object returns 1 if it is a closed day
319
0 if not according to the calendar
329
0 if not according to the calendar
320
330
321
=head2 days_between
331
=head2 days_between
Lines 326-331 Passed two dates returns a DateTime::Duration object measuring the length betwee Link Here
326
ignoring closed days. Always returns a positive number irrespective of the
336
ignoring closed days. Always returns a positive number irrespective of the
327
relative order of the parameters
337
relative order of the parameters
328
338
339
=head2 next_open_day
340
341
$datetime = $calendar->next_open_day($duedate_dt)
342
343
Passed a Datetime returns another Datetime representing the next open day. It is
344
intended for use to calculate the due date when useDaysMode syspref is set to either
345
'Datedue' or 'Calendar'.
346
347
Note: if is_holiday($duedate_dt) = 0 then it should return the same date.
348
329
=head2 set_daysmode
349
=head2 set_daysmode
330
350
331
For testing only allows the calling script to change days mode
351
For testing only allows the calling script to change days mode
(-)a/t/Calendar.t (-2 / +5 lines)
Lines 3-9 Link Here
3
use strict;
3
use strict;
4
use warnings;
4
use warnings;
5
use DateTime;
5
use DateTime;
6
use Test::More tests => 21;
6
use Test::More tests => 23;
7
use Koha::DateUtils;
7
use Koha::DateUtils;
8
8
9
BEGIN {
9
BEGIN {
Lines 127-129 $cal->add_holiday( dt_from_string('2012-07-07','iso') ); Link Here
127
$daycount = $cal->days_between( dt_from_string("2012-07-01",'iso'),
127
$daycount = $cal->days_between( dt_from_string("2012-07-01",'iso'),
128
    dt_from_string("2012-07-15",'iso') )->in_units('days');
128
    dt_from_string("2012-07-15",'iso') )->in_units('days');
129
cmp_ok( $daycount, '==', 12, 'multiple holidays correctly recognized' );
129
cmp_ok( $daycount, '==', 12, 'multiple holidays correctly recognized' );
130
- 
130
$dt = dt_from_string('2012-07-07','iso');
131
cmp_ok( $dt->add(days => 1), '==', $cal->next_open_day(dt_from_string('2012-07-07','iso')), 'Next open day correctly calculated' );
132
$dt = dt_from_string('2012-07-08','iso');
133
cmp_ok( $dt, '==', $cal->next_open_day(dt_from_string('2012-07-08','iso')), 'Next open day correctly calculated (idempotent version)' );

Return to bug 8800