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 <jmf@liblime.com>
This commit is contained in:
Galen Charlton 2008-04-01 12:01:04 -05:00 committed by Joshua Ferraro
parent b558a13323
commit a2c59f25e2
5 changed files with 22 additions and 60 deletions

View File

@ -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);

View File

@ -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' ) {

View File

@ -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
);

View File

@ -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+//;

View File

@ -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);