From 74e28c02f9c7588fed911afaf92eac6e34d00e49 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 Signed-off-by: Kyle M Hall --- .../thirdparty/TalkingTech_itiva_outbound.pl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl b/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl index c17a73443c..1299b7d91b 100755 --- a/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl +++ b/misc/cronjobs/thirdparty/TalkingTech_itiva_outbound.pl @@ -291,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