From 671686d2329c0e5c8787b16467d0b0b12cdc5334 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 1 Oct 2015 10:08:56 +0100 Subject: [PATCH] Bug 14918: Remove C4::Dates from circ/pendingreserves.pl Content-Type: text/plain; charset=utf-8 This patch uses Koha::DateUtils instead of C4::Dates and Date::Calc. It also sent DateTime objects to the template, which use the TT plugin to display them. If an invalid dates is entered, the default date is picked. Test plan: 1/ Go to Home > Circulation > Holds to pull 2/ Verify that the the filter and the list behave as before 3/ Enter invalid dates and confirm that you do not get a software error Counter patch works as expected and is a much cleaner solution. Signed-off-by: Marc Veron Signed-off-by: Marcel de Rooy --- circ/pendingreserves.pl | 38 +++++++++++--------- .../prog/en/modules/circ/pendingreserves.tt | 6 ++-- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 947a9fe..fc2df04 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -27,15 +27,14 @@ use strict; #use warnings; FIXME - Bug 2505 use constant TWO_DAYS => 2; -use constant TWO_DAYS_AGO => -2; use C4::Context; use C4::Output; use CGI qw ( -utf8 ); use C4::Auth; -use C4::Dates qw/format_date format_date_in_iso/; use C4::Debug; -use Date::Calc qw/Today Add_Delta_YMD/; +use Koha::DateUtils; +use DateTime::Duration; my $input = new CGI; my $startdate=$input->param('from'); @@ -68,39 +67,44 @@ my $biblionumber; my $title; my $author; -my ( $year, $month, $day ) = Today(); -my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day); +my $today = dt_from_string; $startdate =~ s/^\s+//; $startdate =~ s/\s+$//; $enddate =~ s/^\s+//; $enddate =~ s/\s+$//; -if (!defined($startdate) or $startdate eq "") { +if ( $startdate ) { + $startdate = eval{dt_from_string( $startdate )}; +} +unless ( $startdate ){ # changed from delivered range of 10 years-yesterday to 2 days ago-today # Find two days ago for the default shelf pull start date, unless HoldsToPullStartDate sys pref is set. - my $pastdate= sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, 0, 0, -C4::Context->preference('HoldsToPullStartDate')||TWO_DAYS_AGO )); - $startdate = format_date($pastdate); + $startdate = $today - DateTime::Duration->new( days => C4::Context->preference('HoldsToPullStartDate') || 2 ); } -if (!defined($enddate) or $enddate eq "") { +if ( $enddate ) { + $enddate = eval{dt_from_string( $enddate )}; +} +unless ( $enddate ) { #similarly: calculate end date with ConfirmFutureHolds (days) - my $d=sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, 0, 0, C4::Context->preference('ConfirmFutureHolds')||0 )); - $enddate = format_date($d); + $enddate = $today - DateTime::Duration->new( days => C4::Context->preference('ConfirmFutureHolds') || 0 ); } my @reservedata; if ( $run_report ) { my $dbh = C4::Context->dbh; my $sqldatewhere = ""; - $debug and warn format_date_in_iso($startdate) . "\n" . format_date_in_iso($enddate); + my $startdate_iso = output_pref({ dt => $startdate, dateformat => 'iso', dateonly => 1 }); + my $enddate_iso = output_pref({ dt => $enddate, dateformat => 'iso', dateonly => 1 }); + $debug and warn $startdate_iso. "\n" . $enddate_iso; my @query_params = (); - if ($startdate) { + if ($startdate_iso) { $sqldatewhere .= " AND reservedate >= ?"; - push @query_params, format_date_in_iso($startdate); + push @query_params, $startdate_iso; } - if ($enddate) { + if ($enddate_iso) { $sqldatewhere .= " AND reservedate <= ?"; - push @query_params, format_date_in_iso($enddate); + push @query_params, $enddate_iso; } my $strsth = @@ -196,7 +200,7 @@ if ( $run_report ) { } $template->param( - todaysdate => $todaysdate, + todaysdate => $today, from => $startdate, to => $enddate, run_report => $run_report, diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt index 1cf144e..d6013f8 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/circ/pendingreserves.tt @@ -82,7 +82,7 @@ $(document).ready(function() {
-

Holds to pull[% IF ( run_report ) %] placed between [% from %] and [% to %][% END %]

+

Holds to pull[% IF ( run_report ) %] placed between [% from | $KohaDates %] and [% to | $KohaDates %][% END %]

[% IF ( run_report ) %]

Reported on [% todaysdate | $KohaDates %]

The following holds have not been filled. Please retrieve them and check them in.

@@ -171,12 +171,12 @@ $(document).ready(function() { - +
  • - +
  • (Inclusive, default is [% HoldsToPullStartDate %] days ago to [% IF ( HoldsToPullEndDate ) %][% HoldsToPullEndDate %] days ahead[% ELSE %]today[% END %], set other date ranges as needed. )

    -- 1.7.10.4