From 9d4e241adadc9a3c62d94a2d487a738e9490925a Mon Sep 17 00:00:00 2001 From: Tomas Cohen Arazi Date: Thu, 21 Jun 2012 11:27:20 -0300 Subject: [PATCH] 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 Signed-off-by: Paul Poulain --- C4/Circulation.pm | 18 +++++++++--------- Koha/Calendar.pm | 6 +++--- Koha/DateUtils.pm | 4 ++-- circ/overdue.pl | 2 +- circ/returns.pl | 2 +- members/moremember.pl | 4 ++-- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index 96ae0d963f..a7e7389c97 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -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; } diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index dc132cd2ac..f31edf2811 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -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 diff --git a/Koha/DateUtils.pm b/Koha/DateUtils.pm index e2e92bd494..a1fd088fe4 100644 --- a/Koha/DateUtils.pm +++ b/Koha/DateUtils.pm @@ -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{}; diff --git a/circ/overdue.pl b/circ/overdue.pl index 56e0941081..e44e792f0a 100755 --- a/circ/overdue.pl +++ b/circ/overdue.pl @@ -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; diff --git a/circ/returns.pl b/circ/returns.pl index 38e9887838..b9127da549 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -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'}; diff --git a/members/moremember.pl b/members/moremember.pl index b4e80f7932..e1f8af52d1 100755 --- a/members/moremember.pl +++ b/members/moremember.pl @@ -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; } -- 2.39.5