From ac8abba03fcfd39e4a84d63ac48a63f085081bac Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 5 Mar 2021 11:43:46 +0100 Subject: [PATCH] Bug 27851: Add Koha::Old::Checkouts->filter_by_todays_checkins The logic for this code is handled at two different places (and in 2 different ways). Better to centralize and provide tests Signed-off-by: Katrin Fischer --- Koha/Old/Checkouts.pm | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Koha/Old/Checkouts.pm b/Koha/Old/Checkouts.pm index af598efab1..ec8b223907 100644 --- a/Koha/Old/Checkouts.pm +++ b/Koha/Old/Checkouts.pm @@ -18,10 +18,28 @@ package Koha::Old::Checkouts; use Modern::Perl; use Koha::Database; +use Koha::DateUtils qw( dt_from_string ); use Koha::Old::Checkout; use base qw(Koha::Objects); +sub filter_by_todays_checkins { + my ( $self ) = @_; + + my $dtf = Koha::Database->new->schema->storage->datetime_parser; + my $today = dt_from_string; + my $today_start = $today->clone->set( hour => 0, minute => 0, second => 0 ); + my $today_end = $today->clone->set( hour => 23, minute => 59, second => 59 ); + $today_start = $dtf->format_datetime( $today_start ); + $today_end = $dtf->format_datetime( $today_end ); + return $self->search({ + returndate => { + '>=' => $today_start, + '<=' => $today_end, + }, + }); +} + sub _type { return 'OldIssue'; } -- 2.11.0