Bug 8251 - Follow up, use 'day' instead of 'days' for Datetime::truncate

As noted in comment #4 by Jonathan Druart, this should be fixed in every call
to DateTie::truncate function. This patch does exactly that.

julian_m tested that truncate( to => 'days' ) didn't actually do anything, so
it is understandable that this 'fix' might introduce new bugs as we might have
'fixed' at a higher libs level this issue.

'minutes' is used in truncate function too, so fixing.

Signed-off-by: Dobrica Pavlinusic <dpavlin@rot13.org>
Signed-off-by: Paul Poulain <paul.poulain@biblibre.com>
This commit is contained in:
Tomás Cohen Arazi 2012-06-21 11:27:20 -03:00 committed by Paul Poulain
parent c6f1f64cb7
commit 9d4e241ada
6 changed files with 18 additions and 18 deletions

View file

@ -701,7 +701,7 @@ sub CanBookBeIssued {
}
if ($duedate) {
my $today = $now->clone();
$today->truncate( to => 'minutes');
$today->truncate( to => 'minute');
if (DateTime->compare($duedate,$today) == -1 ) { # duedate cannot be before now
$needsconfirmation{INVALID_DATE} = output_pref($duedate);
}
@ -738,8 +738,8 @@ sub CanBookBeIssued {
day => $d,
time_zone => C4::Context->tz,
);
$expiry_dt->truncate( to => 'days');
my $today = $now->clone()->truncate(to => 'days');
$expiry_dt->truncate( to => 'day');
my $today = $now->clone()->truncate(to => 'day');
if (DateTime->compare($today, $expiry_dt) == 1) {
$issuingimpossible{EXPIRED} = 1;
}
@ -1051,7 +1051,7 @@ sub AddIssue {
$datedue = CalcDateDue( $issuedate, $itype, $branch, $borrower );
}
$datedue->truncate( to => 'minutes');
$datedue->truncate( to => 'minute');
$sth->execute(
$borrower->{'borrowernumber'}, # borrowernumber
$item->{'itemnumber'}, # itemnumber
@ -2081,10 +2081,10 @@ sub GetItemIssue {
my $data = $sth->fetchrow_hashref;
return unless $data;
$data->{issuedate} = dt_from_string($data->{issuedate}, 'sql');
$data->{issuedate}->truncate(to => 'minutes');
$data->{issuedate}->truncate(to => 'minute');
$data->{date_due} = dt_from_string($data->{date_due}, 'sql');
$data->{date_due}->truncate(to => 'minutes');
my $dt = DateTime->now( time_zone => C4::Context->tz)->truncate( to => 'minutes');
$data->{date_due}->truncate(to => 'minute');
my $dt = DateTime->now( time_zone => C4::Context->tz)->truncate( to => 'minute');
$data->{'overdue'} = DateTime->compare($data->{'date_due'}, $dt ) == -1 ? 1 : 0;
return $data;
}
@ -2129,7 +2129,7 @@ sub GetItemIssues {
my ( $itemnumber, $history ) = @_;
my $today = DateTime->now( time_zome => C4::Context->tz); # get today date
$today->truncate( to => 'minutes' );
$today->truncate( to => 'minute' );
my $sql = "SELECT * FROM issues
JOIN borrowers USING (borrowernumber)
JOIN items USING (itemnumber)
@ -2151,7 +2151,7 @@ sub GetItemIssues {
my $results = $sth->fetchall_arrayref({});
foreach (@$results) {
my $date_due = dt_from_string($_->{date_due},'sql');
$date_due->truncate( to => 'minutes' );
$date_due->truncate( to => 'minute' );
$_->{overdue} = (DateTime->compare($date_due, $today) == -1) ? 1 : 0;
}

View file

@ -147,7 +147,7 @@ sub is_holiday {
if ( $self->{weekly_closed_days}->[$dow] == 1 ) {
return 1;
}
$dt->truncate( to => 'days' );
$dt->truncate( to => 'day' );
my $day = $dt->day;
my $month = $dt->month;
if ( exists $self->{day_month_closed_days}->{$month}->{$day} ) {
@ -189,8 +189,8 @@ sub days_between {
sub hours_between {
my ($self, $start_dt, $end_dt) = @_;
my $duration = $end_dt->delta_ms($start_dt);
$start_dt->truncate( to => 'days' );
$end_dt->truncate( to => 'days' );
$start_dt->truncate( to => 'day' );
$end_dt->truncate( to => 'day' );
# NB this is a kludge in that it assumes all days are 24 hours
# However for hourly loans the logic should be expanded to
# take into account open/close times then it would be a duration

View file

@ -158,7 +158,7 @@ sub format_sqldatetime {
my $force_pref = shift; # if testing we want to override Context
if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
my $dt = dt_from_string( $str, 'sql' );
$dt->truncate( to => 'minutes' );
$dt->truncate( to => 'minute' );
return output_pref( $dt, $force_pref );
}
return q{};
@ -178,7 +178,7 @@ sub format_sqlduedatetime {
my $force_pref = shift; # if testing we want to override Context
if ( defined $str && $str =~ m/^\d{4}-\d{2}-\d{2}/ ) {
my $dt = dt_from_string( $str, 'sql' );
$dt->truncate( to => 'minutes' );
$dt->truncate( to => 'minute' );
return output_pref_due( $dt, $force_pref );
}
return q{};

View file

@ -239,7 +239,7 @@ if ($noreport) {
my $today_dt = DateTime->now(time_zone => C4::Context->tz);
$today_dt->truncate(to => 'minutes');
$today_dt->truncate(to => 'minute');
my $todaysdate = $today_dt->strftime('%Y-%m-%d %H:%M');
$bornamefilter =~s/\*/\%/g;

View file

@ -250,7 +250,7 @@ if ($barcode) {
);
if ($returned) {
my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minutes');
my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute');
my $duedate = $issueinformation->{date_due}->strftime('%Y-%m-%d %H:%M');
$returneditems{0} = $barcode;
$riborrowernumber{0} = $borrower->{'borrowernumber'};

View file

@ -251,7 +251,7 @@ if ( @borrowernumbers ) {
}
my $roaddetails = &GetRoadTypeDetails( $data->{'streettype'} );
my $today = DateTime->now( time_zone => C4::Context->tz);
$today->truncate(to => 'days');
$today->truncate(to => 'day');
my @borrowers_with_issues;
my $overdues_exist = 0;
my $totalprice = 0;
@ -494,7 +494,7 @@ sub build_issue_data {
$row{red} = 1;
}
if ($issuedate) {
$issuedate->truncate( to => 'days' );
$issuedate->truncate( to => 'day' );
if ( DateTime->compare( $issuedate, $today ) == 0 ) {
$row{today} = 1;
}