From d80ef8df782191b05571e57b1f6e23e2c8b035ef Mon Sep 17 00:00:00 2001 From: Aleisha Amohia Date: Mon, 1 May 2023 02:56:42 +0000 Subject: [PATCH] Bug 6796: Fix saving of libraries and tests Sponsored-by: Catalyst IT Sponsored-by: Auckland University of Technology Signed-off-by: Sam Lau Signed-off-by: Martin Renvoize Signed-off-by: Katrin Fischer --- admin/branches.pl | 8 ++++---- t/db_dependent/Circulation/CalcDateDue.t | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/admin/branches.pl b/admin/branches.pl index 21de53802f..b94325eef2 100755 --- a/admin/branches.pl +++ b/admin/branches.pl @@ -125,10 +125,10 @@ if ( $op eq 'add_form' ) { my @close_times = $input->multi_param("close_time"); foreach my $day ( @days ) { - if ( $open_times[$day] and $open_times[$day] eq '' ) { + if ( $open_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) { $open_times[$day] = undef; } - if ( $close_times[$day] and $close_times[$day] eq '' ) { + if ( $close_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) { $close_times[$day] = undef; } @@ -178,10 +178,10 @@ if ( $op eq 'add_form' ) { my @close_times = $input->multi_param("close_time"); foreach my $day ( @days ) { - if ( $open_times[$day] and $open_times[$day] eq '' ) { + if ( $open_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) { $open_times[$day] = undef; } - if ( $close_times[$day] and $close_times[$day] eq '' ) { + if ( $close_times[$day] !~ /([0-9]{2}:[0-9]{2})/ ) { $close_times[$day] = undef; } diff --git a/t/db_dependent/Circulation/CalcDateDue.t b/t/db_dependent/Circulation/CalcDateDue.t index 96e1f3a210..54bde9fe95 100755 --- a/t/db_dependent/Circulation/CalcDateDue.t +++ b/t/db_dependent/Circulation/CalcDateDue.t @@ -368,13 +368,14 @@ Koha::CirculationRules->set_rules( rules => { issuelength => 3, # loan period is 3 hours lengthunit => 'hours', + daysmode => '', } } ); -my $open = DateTime->now->subtract( hours => 4 )->hms; -my $close = DateTime->now->add( hours => 2 )->hms; -my $now = DateTime->now; +my $open = DateTime->new( year => 2023, month => 5, day => 1, hour => 10 )->hms; +my $close = DateTime->new( year => 2023, month => 5, day => 1, hour => 16 )->hms; +my $now = DateTime->new( year => 2023, month => 5, day => 1, hour => 14 ); foreach (0..6) { # library opened 4 hours ago and closes in 2 hours. @@ -387,17 +388,17 @@ t::lib::Mocks::mock_preference('ConsiderLibraryHoursInCirculation', 'close'); # shorten loan period $date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); -my $expected_duetime = DateTime->now->add( hours => 2 ); +my $expected_duetime = $now->clone->add( hours => 2 ); is( $date, $expected_duetime, "Loan period was shortened because ConsiderLibraryHoursInCirculation is set to close time" ); t::lib::Mocks::mock_preference('ConsiderLibraryHoursWhenIssuing', 'open'); # extend loan period $date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); -$expected_duetime = DateTime->now->add( days => 1 )->subtract( hours => 4 ); +$expected_duetime = $now->clone->add( days => 1 )->subtract( hours => 4 ); is( $date, $expected_duetime, "Loan period was extended because ConsiderLibraryHoursInCirculation is set to open time" ); -my $holiday_tomorrow = DateTime->now->add( days => 1 ); +my $holiday_tomorrow = $now->clone->add( days => 1 ); # consider calendar my $library1_calendar = C4::Calendar->new( branchcode => $library1->{branchcode} ); @@ -414,7 +415,7 @@ Koha::CirculationRules->set_rules( itemtype => $itemtype, branchcode => $library1->{branchcode}, rules => { - issuelength => 13, # loan period must cross over into tomorrow + issuelength => 18, # loan period must cross over into tomorrow lengthunit => 'hours', } } @@ -425,14 +426,14 @@ t::lib::Mocks::mock_preference('ConsiderLibraryHoursInCirculation', 'close'); # shorten loan period $date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); -$expected_duetime = DateTime->now->add( days => 2, hours => 2 ); +$expected_duetime = $now->clone->add( days => 2, hours => 2 ); is( $date, $expected_duetime, "Loan period was shortened (but considers the holiday) because ConsiderLibraryHoursInCirculation is set to close time" ); t::lib::Mocks::mock_preference( 'ConsiderLibraryHoursInCirculation', 'open' ); # extend loan period $date = C4::Circulation::CalcDateDue( $now, $itemtype, $library1->{branchcode}, $borrower ); -$expected_duetime = DateTime->now->add( days => 2 )->subtract( hours => 4 ); +$expected_duetime = $now->clone->add( days => 2 )->subtract( hours => 4 ); is( $date, $expected_duetime, "Loan period was extended (but considers the holiday) because ConsiderLibraryHoursInCirculation is set to open time" ); $cache->clear_from_cache($key); -- 2.39.5