Bug 14969: (followup) Today's date withoute time when receiving
[koha_ffzg] / serials / showpredictionpattern.pl
index 690705d..add9f06 100755 (executable)
@@ -30,12 +30,13 @@ publication date, based on frequency and first publication date.
 
 use Modern::Perl;
 
-use CGI;
+use CGI qw ( -utf8 );
 use Date::Calc qw(Today Day_of_Year Week_of_Year Day_of_Week Days_in_Year Delta_Days Add_Delta_Days Add_Delta_YM);
 use C4::Auth;
 use C4::Output;
 use C4::Serials;
 use C4::Serials::Frequency;
+use Koha::DateUtils;
 
 my $input = new CGI;
 my ($template, $loggedinuser, $cookie, $flags) = get_template_and_user( {
@@ -55,6 +56,7 @@ my $subtype = $input->param('subtype');
 my $sublength = $input->param('sublength');
 my $custompattern = $input->param('custompattern');
 
+my $frequency = GetSubscriptionFrequency($frequencyid);
 
 my %pattern = (
     numberingmethod => $input->param('numberingmethod') // '',
@@ -75,19 +77,13 @@ my %pattern = (
     every3          => $input->param('every3') // '',
 );
 
-if(!defined $firstacquidate || $firstacquidate eq ''){
-    my ($year, $month, $day) = Today();
-    $firstacquidate = sprintf "%04d-%02d-%02d", $year, $month, $day;
-} else {
-    $firstacquidate = C4::Dates->new($firstacquidate)->output('iso');
-}
+$firstacquidate = eval { output_pref( { str => $firstacquidate, dateonly => 1, dateformat => 'iso' } ); }
+    or output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } );
 
-if($enddate){
-    $enddate = C4::Dates->new($enddate)->output('iso');
-}
+$enddate = eval { output_pref( { str => $enddate, dateonly => 1, dateformat => 'iso' } ); };
 
 if($nextacquidate) {
-    $nextacquidate = C4::Dates->new($nextacquidate)->output('iso');
+    $nextacquidate =  eval { output_pref( { str => $nextacquidate, dateonly => 1, dateformat => 'iso' } ); };
 } else {
     $nextacquidate = $firstacquidate;
 }
@@ -177,8 +173,6 @@ $template->param(
     predictions_loop => \@predictions_loop,
 );
 
-my $frequency = GetSubscriptionFrequency($frequencyid);
-
 if ( $frequency->{unit} and not $custompattern ) {
     $template->param( ask_for_irregularities => 1 );
     if ( $frequency->{unit} eq 'day' and $frequency->{unitsperissue} == 1 ) {