From d6e65d4f99b23e692989bcd10be4a59b0832d46c 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 Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart --- 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.39.5