}
}
if ( C4::Context->preference('useDaysMode') ne 'Days' ) {
- # Don't return on a closed day
my $calendar = Koha::Calendar->new( branchcode => $branch );
- $datedue = $calendar->prev_open_day( $datedue );
+ if ( $calendar->is_holiday($datedue) ) {
+ # Don't return on a closed day
+ $datedue = $calendar->prev_open_day( $datedue );
+ }
}
}
use Modern::Perl;
-use Test::More tests => 5;
+use Test::More tests => 6;
use Test::MockModule;
use DBI;
use DateTime;
use t::lib::Mocks;
use t::lib::TestBuilder;
+use C4::Calendar;
use_ok('C4::Circulation');
$borrower = {categorycode => 'B', dateexpiry => $dateexpiry};
$start_date = DateTime->new({year => 2013, month => 2, day => 9});
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
-is($date, $dateexpiry . 'T23:59:00', 'date expiry');
+is($date, $dateexpiry . 'T23:59:00', 'date expiry with useDaysMode to noDays');
+
+# Let's add a special holiday on 2013-01-01. With ReturnBeforeExpiry and
+# useDaysMode different from 'Days', return should forward the dateexpiry.
+my $calendar = C4::Calendar->new(branchcode => $branchcode);
+$calendar->insert_single_holiday(
+ day => 1,
+ month => 1,
+ year => 2013,
+ title =>'holidayTest',
+ description => 'holidayDesc'
+);
+$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower );
+is($date, '2012-12-31T23:59:00', 'date expiry should be 2013-01-01 -1 day');
+
$date = C4::Circulation::CalcDateDue( $start_date, $itemtype, $branchcode, $borrower, 1 );
use C4::Members;
use Koha::DateUtils;
use Koha::Database;
-use C4::Calendar;
use t::lib::TestBuilder;
use t::lib::Mocks qw( mock_preference );
can_book_be_issued();
};
subtest 'Tests for CalcDateDue related to dateexpiry' => sub {
- plan tests => 5;
+ plan tests => 4;
calc_date_due();
};
sub calc_date_due {
t::lib::Mocks::mock_preference( 'ReturnBeforeExpiry', 1 );
- t::lib::Mocks::mock_preference( 'useDaysMode', 'Days' );
# this triggers the compare between expiry and due date
$d = C4::Circulation::CalcDateDue( $today, $item->{itype}, $branch->{branchcode}, $patron );
my $t2 = time;
is( ref $d eq "DateTime" && $t2 - $t1 < 1, 1, "CalcDateDue with expiry in year 9876 in " . sprintf( "%6.4f", $t2 - $t1 ) . " seconds." );
-
- # fifth test takes account of closed days
- $d = C4::Circulation::CalcDateDue( $today, $item->{itype}, $branch->{branchcode}, $patron );
- t::lib::Mocks::mock_preference( 'useDaysMode', 'Datedue' );
- my $calendar = C4::Calendar->new(branchcode => $branch->{branchcode});
- $calendar->insert_single_holiday(
- day => $d->day(),
- month => $d->month(),
- year => $d->year(),
- title =>'holidayTest',
- description => 'holidayDesc'
- );
- $calendar->delete_holiday(weekday => $d->day_of_week() - 1, day => $d->day()-1, month =>$d->month(), year=>$d->year() );
- $d2 = C4::Circulation::CalcDateDue( $today, $item->{itype}, $branch->{branchcode}, $patron );
- $d2->add(days => 1);
- $d->truncate( to => 'day' );
- $d2->truncate( to => 'day' );
- is ( DateTime->compare( $d, $d2) == 0, 1, "no problem with closed days");
}
$schema->storage->txn_rollback;