From 6c4415a8738b60f4fd7ad44e3b6b79ee1f3b6659 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 8 Apr 2016 15:51:22 +0100 Subject: [PATCH] Bug 9004: Use Koha::Calendar instead of C4::Calendar This patch tries to make the code more readable using Koha::Calendar instead of deprecated C4::Calendar and Date::Calc --- .../thirdparty/TalkingTech_itiva_outbound.pl | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl b/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl index b42cb25a06..1299b7d91b 100755 --- a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl +++ b/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl @@ -30,13 +30,12 @@ BEGIN { use Getopt::Long; use Pod::Usage; -use Date::Calc qw(Add_Delta_Days); use C4::Context; use C4::Items; use C4::Letters; use C4::Overdues; -use C4::Calendar; +use Koha::Calendar; use Koha::DateUtils; sub usage { @@ -292,22 +291,23 @@ sub GetWaitingHolds { $sth->execute(); my @results; while ( my $issue = $sth->fetchrow_hashref() ) { - my $calendar = C4::Calendar->new( branchcode => $issue->{'site'} ); + my $calendar = Koha::Calendar->new( branchcode => $issue->{'site'} ); - my ( $waiting_year, $waiting_month, $waiting_day ) = split( /-/, $issue->{'waitingdate'} ); - my ( $pickup_year, $pickup_month, $pickup_day ) = Add_Delta_Days( $waiting_year, $waiting_month, $waiting_day, $pickupdelay ); - - while ( $calendar->isHoliday( $pickup_day, $pickup_month, $pickup_year ) ) { - ( $pickup_year, $pickup_month, $pickup_day ) = Add_Delta_Days( $pickup_year, $pickup_month, $pickup_day, 1 ); + my $waiting_date = dt_from_string( $issue->{waitingdate}, 'sql' ); + my $pickup_date = $waiting_date->clone->add( days => $pickupdelay ); + if ( $calendar->is_holiday($pickup_date) ) { + $pickup_date = $calendar->next_open_day( $pickup_date ); } - $issue->{'date_due'} = sprintf( "%04d-%02d-%02d", $pickup_year, $pickup_month, $pickup_day ); + $issue->{'date_due'} = output_pref({dt => $pickup_date, dateformat => 'iso' }); $issue->{'level'} = 1; # only one level for Hold Waiting notifications my $days_to_subtract = 0; - while ( $calendar->isHoliday( reverse( Add_Delta_Days( $waiting_year, $waiting_month, $waiting_day, $days_to_subtract ) ) ) ) { - $days_to_subtract++; + if ( $calendar->is_holiday($waiting_date) ) { + my $next_open_day = $calendar->next_open_day( $waiting_date ); + $days_to_subtract = $calendar->days_between($waiting_date, $next_open_day)->days; } + $issue->{'days_since_waiting'} = $issue->{'days_since_waiting'} - $days_to_subtract; if ( ( grep $_ eq $issue->{'days_since_waiting'}, @holds_waiting_days_to_call ) -- 2.39.5