From a2c59f25e268a2028eef763faacdde3ea394fb57 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Tue, 1 Apr 2008 12:01:04 -0500 Subject: [PATCH] various date-related cleanups in circ * use Date::Calc to perform date arithmetic * use Date::Calc::Today to consistently format the current date * format date per syspref in overdue report Signed-off-by: Joshua Ferraro --- circ/billing.pl | 20 ++++++-------------- circ/circulation.pl | 8 +------- circ/overdue.pl | 9 +++------ circ/pendingreserves.pl | 25 ++++++------------------- circ/reserveratios.pl | 20 ++++++-------------- 5 files changed, 22 insertions(+), 60 deletions(-) diff --git a/circ/billing.pl b/circ/billing.pl index f73962d890..2577371f4a 100755 --- a/circ/billing.pl +++ b/circ/billing.pl @@ -24,6 +24,7 @@ use C4::Output; use CGI; use C4::Auth; use C4::Dates qw/format_date format_date_in_iso/; +use Date::Calc qw/Today Add_Delta_YM/; use vars qw($debug); @@ -63,20 +64,11 @@ my $biblionumber; my $title; my $author; -my @datearr = localtime( time() ); -my -$todaysdate = - ( 1900 + $datearr[5] ) . '-' - . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-' - . sprintf( "%0.2d", $datearr[3] ); - +my ( $year, $month, $day ) = Today(); +my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day); # Find yesterday for the default shelf pull start and end dates -# A defualt of the prior years's holds is a reasonable way to pull holds -my @datearr_yesterday = localtime( time() - 86400*365 ); -my $yesterdaysdate = - ( 1900 + $datearr_yesterday[5] ) . '-' - . sprintf( "%0.2d", ( $datearr_yesterday[4] + 1 ) ) . '-' - . sprintf( "%0.2d", $datearr_yesterday[3] ); +# A default of the prior years's holds is a reasonable way to pull holds +my $datelastyear = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YM($year, $month, $day, -1, 0)); # Predefine the start and end dates if they are not already defined $startdate =~ s/^\s+//; @@ -85,7 +77,7 @@ $enddate =~ s/^\s+//; $enddate =~ s/\s+$//; # Check if null, should string match, if so set start and end date to yesterday if (!defined($startdate) or $startdate eq "") { - $startdate = format_date($yesterdaysdate); + $startdate = format_date($datelastyear); } if (!defined($enddate) or $enddate eq "") { $enddate = format_date($todaysdate); diff --git a/circ/circulation.pl b/circ/circulation.pl index ee3c8200e0..128864cc69 100755 --- a/circ/circulation.pl +++ b/circ/circulation.pl @@ -153,13 +153,7 @@ if ($duedatespec) { # ($year, $month, $day) = ($duedatespec) ? split /-/, $duedatespec : (0,0,0); #} -my @datearr = localtime(); - -# FIXME - Could just use POSIX::strftime("%Y%m%d", localtime); -my $todaysdate = - ( 1900 + $datearr[5] ) - . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) - . sprintf( "%0.2d", ( $datearr[3] ) ); +my $todaysdate = sprintf("%-04.4d%-02.2d%-02.2d", Today()); # check and see if we should print if ( $barcode eq '' && $print eq 'maybe' ) { diff --git a/circ/overdue.pl b/circ/overdue.pl index 83739085f5..27265d7bee 100755 --- a/circ/overdue.pl +++ b/circ/overdue.pl @@ -25,6 +25,7 @@ use CGI; use C4::Auth; use C4::Branch; use C4::Dates qw/format_date/; +use Date::Calc qw/Today/; my $input = new CGI; my $type = $input->param('type'); @@ -135,12 +136,8 @@ my $phone; my $email; my $title; my $author; -my @datearr = localtime( time() ); -my $todaysdate = - ( 1900 + $datearr[5] ) . '-' - . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-' - . sprintf( "%0.2d", $datearr[3] ); +my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", Today()); $bornamefilter =~s/\*/\%/g; $bornamefilter =~s/\?/\_/g; @@ -208,7 +205,7 @@ while (my $data=$sth->fetchrow_hashref) { } $template->param( - todaysdate => $todaysdate, + todaysdate => format_date($todaysdate), overdueloop => \@overduedata ); diff --git a/circ/pendingreserves.pl b/circ/pendingreserves.pl index 326fb3054c..7400638e60 100755 --- a/circ/pendingreserves.pl +++ b/circ/pendingreserves.pl @@ -29,6 +29,7 @@ use C4::Output; use CGI; use C4::Auth; use C4::Dates qw/format_date format_date_in_iso/; +use Date::Calc qw/Today Add_Delta_YMD/; use vars qw($debug); @@ -67,26 +68,12 @@ my $biblionumber; my $title; my $author; -my @datearr = localtime( time() ); -my $todaysdate = - ( 1900 + $datearr[5] ) . '-' - . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-' - . sprintf( "%0.2d", $datearr[3] ); - -# Find yesterday for the default shelf pull end dates -# A defualt of the prior day's holds is a reasonable way to pull holds -my @datearr_yesterday = localtime( time() - 86400 ); -my $yesterdaysdate = - ( 1900 + $datearr_yesterday[5] ) . '-' - . sprintf( "%0.2d", ( $datearr_yesterday[4] + 1 ) ) . '-' - . sprintf( "%0.2d", $datearr_yesterday[3] ); +my ( $year, $month, $day ) = Today(); +my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day); +my $yesterdaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, 0, 0, -1)); # Find 10 years ago for the default shelf pull start and end dates -# A defualt of the prior day's holds is a reasonable way to pull holds -my @datearr_past = localtime( time() - 86400*365*10 ); -my $pastdate = - ( 1900 + $datearr_past[5] ) . '-' - . sprintf( "%0.2d", ( $datearr_past[4] + 1 ) ) . '-' - . sprintf( "%0.2d", $datearr_past[3] ); +# A default of the prior day's holds is a reasonable way to pull holds +my $pastdate = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YMD($year, $month, $day, -10, 0, 0)); # Predefine the start and end dates if they are not already defined $startdate =~ s/^\s+//; diff --git a/circ/reserveratios.pl b/circ/reserveratios.pl index b45bab0985..d7fecbe943 100755 --- a/circ/reserveratios.pl +++ b/circ/reserveratios.pl @@ -24,6 +24,7 @@ use C4::Output; use CGI; use C4::Auth; use C4::Dates qw/format_date format_date_in_iso/; +use Date::Calc qw/Today Add_Delta_YM/; use vars qw($debug); @@ -63,20 +64,11 @@ my $biblionumber; my $title; my $author; -my @datearr = localtime( time() ); -my -$todaysdate = - ( 1900 + $datearr[5] ) . '-' - . sprintf( "%0.2d", ( $datearr[4] + 1 ) ) . '-' - . sprintf( "%0.2d", $datearr[3] ); - +my ( $year, $month, $day ) = Today(); +my $todaysdate = sprintf("%-04.4d-%-02.2d-%02.2d", $year, $month, $day); # Find yesterday for the default shelf pull start and end dates -# A defualt of the prior years's holds is a reasonable way to pull holds -my @datearr_yesterday = localtime( time() - 86400*365 ); -my $yesterdaysdate = - ( 1900 + $datearr_yesterday[5] ) . '-' - . sprintf( "%0.2d", ( $datearr_yesterday[4] + 1 ) ) . '-' - . sprintf( "%0.2d", $datearr_yesterday[3] ); +# A default of the prior years's holds is a reasonable way to pull holds +my $datelastyear = sprintf("%-04.4d-%-02.2d-%02.2d", Add_Delta_YM($year, $month, $day, -1, 0)); # Predefine the start and end dates if they are not already defined $startdate =~ s/^\s+//; @@ -85,7 +77,7 @@ $enddate =~ s/^\s+//; $enddate =~ s/\s+$//; # Check if null, should string match, if so set start and end date to yesterday if (!defined($startdate) or $startdate eq "") { - $startdate = format_date($yesterdaysdate); + $startdate = format_date($datelastyear); } if (!defined($enddate) or $enddate eq "") { $enddate = format_date($todaysdate); -- 2.20.1