From b3ec8d413f5c4356b2a7318e11cdaeea2b0ba996 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 11 Nov 2015 12:31:12 +0000 Subject: [PATCH] [PASSED QA] Bug 14960: Simplify the date management in staticfines There is no need to create a DT objcet, then display in string/iso then recreate a DT object from this string. Signed-off-by: Jonathan Druart Signed-off-by: Kyle M Hall --- misc/cronjobs/staticfines.pl | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/misc/cronjobs/staticfines.pl b/misc/cronjobs/staticfines.pl index de92c65..c57e99e 100755 --- a/misc/cronjobs/staticfines.pl +++ b/misc/cronjobs/staticfines.pl @@ -103,7 +103,7 @@ foreach (@pcategories) { } use vars qw(@borrower_fields @item_fields @other_fields); -use vars qw($fldir $libname $control $mode $delim $dbname $today_iso $today_days); +use vars qw($fldir $libname $control $mode $delim $dbname $today $today_iso $today_days); use vars qw($filename); CHECK { @@ -135,23 +135,24 @@ if (defined $borrowernumberlimit) { } my $overdueItemsCounted = 0; my %calendars = (); -$today_iso = output_pref( { dt => dt_from_string, dateonly => 1, dateformat => 'iso' } ); +$today = dt_from_string; +$today_iso = output_pref( { dt => $today, dateonly => 1, dateformat => 'iso' } ); my ($tyear, $tmonth, $tday) = split( /-/, $today_iso ); $today_days = Date_to_Days( $tyear, $tmonth, $tday ); for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { next if $data->[$i]->{'itemlost'}; - my $datedue; - my $datedue_days; + my ( $datedue, $datedue_days ); eval { - $datedue = eval { output_pref( { dt => dt_from_string( $data->[$i]->{'date_due'} ), dateonly => 1, dateformat => 'iso' } ); }; - $datedue_days = Date_to_Days( split( /-/, $datedue ) ); + $datedue = dt_from_string( $data->[$i]->{'date_due'} ); + my $datedue_iso = output_pref( { dt => $datedue, dateonly => 1, dateformat => 'iso' } ); + $datedue_days = Date_to_Days( split( /-/, $datedue_iso ) ); }; if ($@) { warn "Error on date for borrower " . $data->[$i]->{'borrowernumber'} . ": $@date_due: " . $data->[$i]->{'date_due'} . "\ndatedue_days: " . $datedue_days . "\nSkipping"; next; } - my $due_str = eval { output_pref( { dt => dt_from_string( $datedue ), dateonly => 1 } ); }; + my $due_str = output_pref( { dt => $datedue, dateonly => 1 } ); unless ( defined $data->[$i]->{'borrowernumber'} ) { print STDERR "ERROR in Getoverdues line $i: issues.borrowernumber IS NULL. Repair 'issues' table now! Skipping record.\n"; next; # Note: this doesn't solve everything. After NULL borrowernumber, multiple issues w/ real borrowernumbers can pile up. @@ -191,8 +192,8 @@ for ( my $i = 0 ; $i < scalar(@$data) ; $i++ ) { $data->[$i], $borrower->{'categorycode'}, $branchcode, - dt_from_string( $datedue ), - dt_from_string( $today_iso ), + $datedue, + $today, ); # Reassign fine's amount if specified in command-line -- 1.7.10.4