From 686188a6ebb87059940a9bacb44d9e587832a1a1 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 --- 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 d0e8af71847..6baaa6d6a6a 100755 --- a/admin/branches.pl +++ b/admin/branches.pl @@ -123,10 +123,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; } @@ -176,10 +176,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 faa1f4af35b..50c88d1cd39 100755 --- a/t/db_dependent/Circulation/CalcDateDue.t +++ b/t/db_dependent/Circulation/CalcDateDue.t @@ -352,13 +352,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. @@ -371,17 +372,17 @@ t::lib::Mocks::mock_preference('ConsiderLibraryHoursWhenIssuing', '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 ConsiderLibraryHoursWhenIssuing 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 ConsiderLibraryHoursWhenIssuing 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} ); @@ -398,7 +399,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', } } @@ -409,14 +410,14 @@ t::lib::Mocks::mock_preference('ConsiderLibraryHoursWhenIssuing', '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 ConsiderLibraryHoursWhenIssuing 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 => 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 ConsiderLibraryHoursWhenIssuing is set to open time" ); $cache->clear_from_cache($key); -- 2.30.2