Bug 14870: (followup) Remove stray C4::Dates from reports files
authorMarc Véron <veron@veron.ch>
Sun, 8 Nov 2015 22:09:10 +0000 (23:09 +0100)
committerTomas Cohen Arazi <tomascohen@theke.io>
Thu, 19 Nov 2015 16:05:06 +0000 (13:05 -0300)
This patch removes stray C4::Dates from following files:

reports/borrowers_stats.pl
To test: Verify that C4::Dates is not used in the file

reports/guided_reports.pl:
To test:
- Run a saved report with date input and with date range input, e.g.
- Verify that you are asked for date range or date and that the results
  are the same as without patch

Signed-off-by: Katrin Fischer <Katrin.Fischer.83@web.de>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
reports/borrowers_stats.pl
reports/guided_reports.pl

index 9ac0cac..b34934e 100755 (executable)
@@ -31,7 +31,6 @@ use C4::Output;
 use C4::Reports;
 use C4::Circulation;
 use C4::Members::AttributeTypes;
-use C4::Dates qw/format_date format_date_in_iso/;
 use Date::Calc qw(
   Today
   Add_Delta_YM
@@ -43,8 +42,6 @@ plugin that shows a stats on borrowers
 
 =head1 DESCRIPTION
 
-=over 2
-
 =cut
 
 my $input = new CGI;
index 098a3d1..cbdecda 100755 (executable)
@@ -357,9 +357,13 @@ elsif ( $phase eq 'Choose these criteria' ) {
             my $tovalue   = $input->param( "to_"   . $crit . "_value" );
 
             # If the range values are dates
-            if ($fromvalue =~ C4::Dates->regexp('syspref') && $tovalue =~ C4::Dates->regexp('syspref')) {
-                $fromvalue = C4::Dates->new($fromvalue)->output("iso");
-                $tovalue = C4::Dates->new($tovalue)->output("iso");
+            my $fromvalue_dt;
+            $fromvalue_dt = eval { dt_from_string( $fromvalue ); } if ( $fromvalue );
+            my $tovalue_dt;
+            $tovalue_dt = eval { dt_from_string( $tovalue ); } if ($tovalue);
+            if ( $fromvalue_dt && $tovalue_dt ) {
+                $fromvalue = output_pref( { dt => dt_from_string( $fromvalue_dt ), dateonly => 1, dateformat => 'iso' } );
+                $tovalue   = output_pref( { dt => dt_from_string( $tovalue_dt ), dateonly => 1, dateformat => 'iso' } );
             }
 
             if ($fromvalue && $tovalue) {
@@ -369,8 +373,10 @@ elsif ( $phase eq 'Choose these criteria' ) {
         } else {
 
             # If value is a date
-            if ($value =~ C4::Dates->regexp('syspref')) {
-                $value = C4::Dates->new($value)->output("iso");
+            my $value_dt;
+            $value_dt  =  eval { dt_from_string( $value ); } if ( $value );
+            if ( $value_dt ) {
+                $value = output_pref( { dt => dt_from_string( $value_dt ), dateonly => 1, dateformat => 'iso' } );
             }
             # don't escape runtime parameters, they'll be at runtime
             if ($value =~ /<<.*>>/) {