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

(-)a/C4/Circulation.pm (-3 / +3 lines)
Lines 1345-1351 sub checkHighHolds { Link Here
1345
        } else {
1345
        } else {
1346
            $duration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1346
            $duration = C4::Context->preference('decreaseLoanHighHoldsDuration');
1347
        }
1347
        }
1348
        my $reduced_datedue = $calendar->addDate( $issuedate, $duration );
1348
        my $reduced_datedue = $calendar->addDuration( $issuedate, $duration );
1349
        $reduced_datedue->set_hour($orig_due->hour);
1349
        $reduced_datedue->set_hour($orig_due->hour);
1350
        $reduced_datedue->set_minute($orig_due->minute);
1350
        $reduced_datedue->set_minute($orig_due->minute);
1351
        $reduced_datedue->truncate( to => 'minute' );
1351
        $reduced_datedue->truncate( to => 'minute' );
Lines 2466-2472 sub _calculate_new_debar_dt { Link Here
2466
                branchcode => $branchcode,
2466
                branchcode => $branchcode,
2467
                days_mode  => 'Calendar'
2467
                days_mode  => 'Calendar'
2468
            );
2468
            );
2469
            $new_debar_dt = $calendar->addDate( $return_date, $suspension_days );
2469
            $new_debar_dt = $calendar->addDuration( $return_date, $suspension_days );
2470
        }
2470
        }
2471
        else {
2471
        else {
2472
            $new_debar_dt = $return_date->clone()->add_duration($suspension_days);
2472
            $new_debar_dt = $return_date->clone()->add_duration($suspension_days);
Lines 3651-3657 sub CalcDateDue { Link Here
3651
            $dur = DateTime::Duration->new( days => $loanlength->{$length_key});
3651
            $dur = DateTime::Duration->new( days => $loanlength->{$length_key});
3652
        }
3652
        }
3653
        my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode );
3653
        my $calendar = Koha::Calendar->new( branchcode => $branch, days_mode => $daysmode );
3654
        $datedue = $calendar->addDate( $datedue, $dur, $loanlength->{lengthunit} );
3654
        $datedue = $calendar->addDuration( $datedue, $dur, $loanlength->{lengthunit} );
3655
        if ($loanlength->{lengthunit} eq 'days') {
3655
        if ($loanlength->{lengthunit} eq 'days') {
3656
            $datedue->set_hour(23);
3656
            $datedue->set_hour(23);
3657
            $datedue->set_minute(59);
3657
            $datedue->set_minute(59);
(-)a/Koha/Calendar.pm (-5 / +5 lines)
Lines 90-100 sub _holidays { Link Here
90
    return $holidays // {};
90
    return $holidays // {};
91
}
91
}
92
92
93
sub addDate {
93
sub addDuration {
94
    my ( $self, $startdate, $add_duration, $unit ) = @_;
94
    my ( $self, $startdate, $add_duration, $unit ) = @_;
95
95
96
96
97
    Koha::Exceptions::MissingParameter->throw("Missing mandatory option for Koha:Calendar->addDate: days_mode")
97
    Koha::Exceptions::MissingParameter->throw("Missing mandatory option for Koha:Calendar->addDuration: days_mode")
98
        unless exists $self->{days_mode};
98
        unless exists $self->{days_mode};
99
99
100
    # Default to days duration (legacy support I guess)
100
    # Default to days duration (legacy support I guess)
Lines 392-398 Koha::Calendar - Object containing a branches calendar Link Here
392
  # are we open
392
  # are we open
393
  $open = $c->is_holiday($dt);
393
  $open = $c->is_holiday($dt);
394
  # when will item be due if loan period = $dur (a DateTime::Duration object)
394
  # when will item be due if loan period = $dur (a DateTime::Duration object)
395
  $duedate = $c->addDate($dt,$dur,'days');
395
  $duedate = $c->addDuration($dt,$dur,'days');
396
396
397
397
398
=head1 DESCRIPTION
398
=head1 DESCRIPTION
Lines 408-416 my $calendar = Koha::Calendar->new( branchcode => 'MAIN' ); Link Here
408
The option branchcode is required
408
The option branchcode is required
409
409
410
410
411
=head2 addDate
411
=head2 addDuration
412
412
413
    my $dt = $calendar->addDate($date, $dur, $unit)
413
    my $dt = $calendar->addDuration($date, $dur, $unit)
414
414
415
C<$date> is a DateTime object representing the starting date of the interval.
415
C<$date> is a DateTime object representing the starting date of the interval.
416
416
(-)a/Koha/Checkouts.pm (-1 / +1 lines)
Lines 57-63 sub calculate_dropbox_date { Link Here
57
    );
57
    );
58
    my $calendar     = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
58
    my $calendar     = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );
59
    my $today        = dt_from_string;
59
    my $today        = dt_from_string;
60
    my $dropbox_date = $calendar->addDate( $today, -1 );
60
    my $dropbox_date = $calendar->addDuration( $today, -1 );
61
61
62
    return $dropbox_date;
62
    return $dropbox_date;
63
}
63
}
(-)a/t/Calendar.t (-21 / +20 lines)
Lines 133-139 my $day_after_christmas = DateTime->new( Link Here
133
    year    => 2012,
133
    year    => 2012,
134
    month   => 12,
134
    month   => 12,
135
    day     => 26
135
    day     => 26
136
);  # for testing negative addDate
136
);  # for testing negative addDuration
137
137
138
my $holiday_for_another_branch = DateTime->new(
138
my $holiday_for_another_branch = DateTime->new(
139
    year => 2012,
139
    year => 2012,
Lines 218-240 my $holiday_excepted = DateTime->new( Link Here
218
218
219
    $cal = Koha::Calendar->new( branchcode => 'MPL', days_mode => 'Datedue' );
219
    $cal = Koha::Calendar->new( branchcode => 'MPL', days_mode => 'Datedue' );
220
220
221
    is($cal->addDate( $dt, $one_day_dur, 'days' ), # tuesday
221
    is($cal->addDuration( $dt, $one_day_dur, 'days' ), # tuesday
222
        dt_from_string('2012-07-05','iso'),
222
        dt_from_string('2012-07-05','iso'),
223
        'Single day add (Datedue, matches holiday, shift)' );
223
        'Single day add (Datedue, matches holiday, shift)' );
224
224
225
    is($cal->addDate( $dt, $two_day_dur, 'days' ),
225
    is($cal->addDuration( $dt, $two_day_dur, 'days' ),
226
        dt_from_string('2012-07-05','iso'),
226
        dt_from_string('2012-07-05','iso'),
227
        'Two days add, skips holiday (Datedue)' );
227
        'Two days add, skips holiday (Datedue)' );
228
228
229
    cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ), 'eq',
229
    cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
230
        '2012-07-30T11:53:00',
230
        '2012-07-30T11:53:00',
231
        'Add 7 days (Datedue)' );
231
        'Add 7 days (Datedue)' );
232
232
233
    is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
233
    is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
234
        'addDate skips closed Sunday (Datedue)' );
234
        'addDuration skips closed Sunday (Datedue)' );
235
235
236
    is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
236
    is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
237
        'Negative call to addDate (Datedue)' );
237
        'Negative call to addDuration (Datedue)' );
238
238
239
    ## Note that the days_between API says closed days are not considered.
239
    ## Note that the days_between API says closed days are not considered.
240
    ## This tests are here as an API test.
240
    ## This tests are here as an API test.
Lines 251-269 my $holiday_excepted = DateTime->new( Link Here
251
251
252
    $dt = dt_from_string('2012-07-03','iso');
252
    $dt = dt_from_string('2012-07-03','iso');
253
253
254
    is($cal->addDate( $dt, $one_day_dur, 'days' ),
254
    is($cal->addDuration( $dt, $one_day_dur, 'days' ),
255
        dt_from_string('2012-07-05','iso'),
255
        dt_from_string('2012-07-05','iso'),
256
        'Single day add (Calendar)' );
256
        'Single day add (Calendar)' );
257
257
258
    cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ), 'eq',
258
    cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ), 'eq',
259
       '2012-08-01T11:53:00',
259
       '2012-08-01T11:53:00',
260
       'Add 7 days (Calendar)' );
260
       'Add 7 days (Calendar)' );
261
261
262
    is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
262
    is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 1,
263
            'addDate skips closed Sunday (Calendar)' );
263
            'addDuration skips closed Sunday (Calendar)' );
264
264
265
    is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
265
    is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-24',
266
            'Negative call to addDate (Calendar)' );
266
            'Negative call to addDuration (Calendar)' );
267
267
268
    cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
268
    cmp_ok( $cal->days_between( $test_dt, $later_dt )->in_units('days'),
269
                '==', 40, 'days_between calculates correctly (Calendar)' );
269
                '==', 40, 'days_between calculates correctly (Calendar)' );
Lines 279-297 my $holiday_excepted = DateTime->new( Link Here
279
279
280
    $dt = dt_from_string('2012-07-03','iso');
280
    $dt = dt_from_string('2012-07-03','iso');
281
281
282
    is($cal->addDate( $dt, $one_day_dur, 'days' ),
282
    is($cal->addDuration( $dt, $one_day_dur, 'days' ),
283
        dt_from_string('2012-07-04','iso'),
283
        dt_from_string('2012-07-04','iso'),
284
        'Single day add (Days)' );
284
        'Single day add (Days)' );
285
285
286
    cmp_ok($cal->addDate( $test_dt, $seven_day_dur, 'days' ),'eq',
286
    cmp_ok($cal->addDuration( $test_dt, $seven_day_dur, 'days' ),'eq',
287
        '2012-07-30T11:53:00',
287
        '2012-07-30T11:53:00',
288
        'Add 7 days (Days)' );
288
        'Add 7 days (Days)' );
289
289
290
    is( $cal->addDate( $saturday, $one_day_dur, 'days' )->day_of_week, 7,
290
    is( $cal->addDuration( $saturday, $one_day_dur, 'days' )->day_of_week, 7,
291
        'addDate doesn\'t skip closed Sunday (Days)' );
291
        'addDuration doesn\'t skip closed Sunday (Days)' );
292
292
293
    is( $cal->addDate($day_after_christmas, -1, 'days')->ymd(), '2012-12-25',
293
    is( $cal->addDuration($day_after_christmas, -1, 'days')->ymd(), '2012-12-25',
294
        'Negative call to addDate (Days)' );
294
        'Negative call to addDuration (Days)' );
295
295
296
    ## Note that the days_between API says closed days are not considered.
296
    ## Note that the days_between API says closed days are not considered.
297
    ## This tests are here as an API test.
297
    ## This tests are here as an API test.
298
- 

Return to bug 25802