From a9839535fee42f2dcedddcae80638d97136a7382 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 26 Mar 2020 11:05:32 +0000 Subject: [PATCH] Bug 24840: [19.11.x] Replace DateTime->now with dt_from_string We should use Koha::DateUtils instead of Date::Time directly This patch simplay replaces calls to now() with a call to dt_from_string() which does effectively the same thing. Probably reading the code and verifying changes is sufficient but... To test: 1 - confirm the files all compile 2 - confirm all tests pass 3 - confirm Koha still works Signed-off-by: Martin Renvoize Signed-off-by: Jonathan Druart Bug 24840: Catch some further cases of DateTime->now This patch corrects a few additional cases where DateTime->now is called directly instead of via Koha::DateUtils. Signed-off-by: Jonathan Druart --- C4/Circulation.pm | 20 +++++++++----------- C4/Letters.pm | 2 +- C4/MarcModificationTemplates.pm | 3 ++- Koha/Calendar.pm | 2 +- Koha/Checkout.pm | 3 ++- Koha/Checkouts.pm | 3 ++- Koha/EDI.pm | 5 +++-- Koha/Edifact/Order.pm | 3 ++- Koha/Edifact/Transport.pm | 3 ++- Koha/Illrequest.pm | 3 ++- Koha/Patron/Password/Recovery.pm | 3 ++- Koha/Sitemapper/Writer.pm | 4 ++-- Koha/StockRotationItem.pm | 12 ++++++------ circ/overdue.pl | 2 +- circ/returns.pl | 6 +++--- .../mysql/fix_unclosed_nonaccruing_fines_bug17135.pl | 2 +- installer/data/mysql/updatedatabase.pl | 2 +- members/summary-print.pl | 3 ++- misc/cronjobs/fines.pl | 2 +- misc/cronjobs/overdue_notices.pl | 4 ++-- misc/cronjobs/update_totalissues.pl | 3 ++- opac/opac-ics.pl | 2 +- t/Circulation/AgeRestrictionMarkers.t | 5 +++-- t/db_dependent/DecreaseLoanHighHolds.t | 5 +++-- t/db_dependent/Letters/TemplateToolkit.t | 2 +- t/db_dependent/OAI/Server.t | 2 +- t/db_dependent/Passwordrecovery.t | 11 ++++++----- t/db_dependent/Sitemapper.t | 3 ++- 28 files changed, 66 insertions(+), 54 deletions(-) diff --git a/C4/Circulation.pm b/C4/Circulation.pm index f7855d5887..e3d505e16b 100644 --- a/C4/Circulation.pm +++ b/C4/Circulation.pm @@ -703,7 +703,7 @@ sub CanBookBeIssued { if ($duedate && ref $duedate ne 'DateTime') { $duedate = dt_from_string($duedate); } - my $now = DateTime->now( time_zone => C4::Context->tz() ); + my $now = dt_from_string(); unless ( $duedate ) { my $issuedate = $now->clone(); @@ -1234,7 +1234,7 @@ sub checkHighHolds { } } - my $issuedate = DateTime->now( time_zone => C4::Context->tz() ); + my $issuedate = dt_from_string(); my $calendar = Koha::Calendar->new( branchcode => $branchcode ); @@ -1313,7 +1313,7 @@ sub AddIssue { # $issuedate defaults to today. if ( !defined $issuedate ) { - $issuedate = DateTime->now( time_zone => C4::Context->tz() ); + $issuedate = dt_from_string(); } else { if ( ref $issuedate ne 'DateTime' ) { @@ -1463,7 +1463,7 @@ sub AddIssue { holdingbranch => C4::Context->userenv->{'branch'}, itemlost => 0, onloan => $datedue->ymd(), - datelastborrowed => DateTime->now( time_zone => C4::Context->tz() )->ymd(), + datelastborrowed => dt_from_string(), }, $item_object->biblionumber, $item_object->itemnumber, @@ -2766,7 +2766,7 @@ sub CanBookBeRenewed { $soonestrenewal->truncate( to => 'day' ); } - if ( $soonestrenewal > DateTime->now( time_zone => C4::Context->tz() ) ) + if ( $soonestrenewal > dt_from_string() ) { return ( 0, "auto_too_soon" ) if $issue->auto_renew; return ( 0, "too_soon" ); @@ -2888,7 +2888,7 @@ sub AddRenewal { my $itemnumber = shift or return; my $branch = shift; my $datedue = shift; - my $lastreneweddate = shift || DateTime->now(time_zone => C4::Context->tz); + my $lastreneweddate = shift || dt_from_string(); my $item_object = Koha::Items->find($itemnumber) or return; my $biblio = $item_object->biblio; @@ -2927,7 +2927,7 @@ sub AddRenewal { $datedue = (C4::Context->preference('RenewalPeriodBase') eq 'date_due') ? dt_from_string( $issue->date_due, 'sql' ) : - DateTime->now( time_zone => C4::Context->tz()); + dt_from_string(); $datedue = CalcDateDue($datedue, $itemtype, $circ_library->branchcode, $patron_unblessed, 'is a renewal'); } @@ -3556,9 +3556,7 @@ sub CalcDateDue { $datedue = $startdate->clone; } } else { - $datedue = - DateTime->now( time_zone => C4::Context->tz() ) - ->truncate( to => 'minute' ); + $datedue = dt_from_string()->truncate( to => 'minute' ); } @@ -4035,7 +4033,7 @@ sub GetAgeRestriction { } #Get how many days the borrower has to reach the age restriction - my @Today = split /-/, DateTime->today->ymd(); + my @Today = split /-/, dt_from_string()->ymd(); my $daysToAgeRestriction = Date_to_Days(@alloweddate) - Date_to_Days(@Today); #Negative days means the borrower went past the age restriction age return ($restriction_year, $daysToAgeRestriction); diff --git a/C4/Letters.pm b/C4/Letters.pm index 097096a501..f505927675 100644 --- a/C4/Letters.pm +++ b/C4/Letters.pm @@ -797,7 +797,7 @@ sub _parseletter { } if ($letter->{content} && $letter->{content} =~ /<>/) { - my $todaysdate = output_pref( DateTime->now() ); + my $todaysdate = output_pref( dt_from_string() ); $letter->{content} =~ s/<>/$todaysdate/go; } diff --git a/C4/MarcModificationTemplates.pm b/C4/MarcModificationTemplates.pm index 54846e5956..5ed2f94ae0 100644 --- a/C4/MarcModificationTemplates.pm +++ b/C4/MarcModificationTemplates.pm @@ -24,6 +24,7 @@ use DateTime; use C4::Context; use Koha::SimpleMARC; use Koha::MoreUtils; +use Koha::DateUtils; use vars qw(@ISA @EXPORT); @@ -501,7 +502,7 @@ sub ModifyRecordWithTemplate { warn( "C4::MarcModificationTemplates::ModifyRecordWithTemplate( $template_id, $record )" ) if DEBUG; warn( "Unmodified Record:\n" . $record->as_formatted() ) if DEBUG >= 10; - my $current_date = DateTime->now()->ymd(); + my $current_date = dt_from_string()->ymd(); my $branchcode = ''; $branchcode = C4::Context->userenv->{branch} if C4::Context->userenv; diff --git a/Koha/Calendar.pm b/Koha/Calendar.pm index 7382fb8ce4..b38a8bba85 100644 --- a/Koha/Calendar.pm +++ b/Koha/Calendar.pm @@ -410,7 +410,7 @@ Koha::Calendar - Object containing a branches calendar use Koha::Calendar my $c = Koha::Calendar->new( branchcode => 'MAIN' ); - my $dt = DateTime->now(); + my $dt = dt_from_string(); # are we open $open = $c->is_holiday($dt); diff --git a/Koha/Checkout.pm b/Koha/Checkout.pm index f789de6d8d..a7c72e0dde 100644 --- a/Koha/Checkout.pm +++ b/Koha/Checkout.pm @@ -54,7 +54,8 @@ will be the reference date. sub is_overdue { my ( $self, $dt ) = @_; - $dt ||= DateTime->now( time_zone => C4::Context->tz ); + $dt ||= dt_from_string(); + my $is_overdue = DateTime->compare( dt_from_string( $self->date_due, 'sql' ), $dt ) == -1 ? 1 diff --git a/Koha/Checkouts.pm b/Koha/Checkouts.pm index 5726699900..62d582f6fb 100644 --- a/Koha/Checkouts.pm +++ b/Koha/Checkouts.pm @@ -24,6 +24,7 @@ use Carp; use C4::Context; use Koha::Checkout; use Koha::Database; +use Koha::DateUtils; use base qw(Koha::Objects); @@ -48,7 +49,7 @@ sub calculate_dropbox_date { my $branchcode = $userenv->{branch} // q{}; my $calendar = Koha::Calendar->new( branchcode => $branchcode ); - my $today = DateTime->now( time_zone => C4::Context->tz() ); + my $today = dt_from_string(); my $dropbox_date = $calendar->addDate( $today, -1 ); return $dropbox_date; diff --git a/Koha/EDI.pm b/Koha/EDI.pm index 0ab4658689..4171f3f7d9 100644 --- a/Koha/EDI.pm +++ b/Koha/EDI.pm @@ -27,6 +27,7 @@ use Business::ISBN; use DateTime; use C4::Context; use Koha::Database; +use Koha::DateUtils; use C4::Acquisition qw( NewBasket CloseBasket ModOrder); use C4::Suggestions qw( ModSuggestion ); use C4::Items qw(AddItem); @@ -175,7 +176,7 @@ sub process_ordrsp { ordernumber => $ordernumber, cancellationreason => $reason, orderstatus => 'cancelled', - datecancellationprinted => DateTime->now()->ymd(), + datecancellationprinted => dt_from_string()->ymd(), } ); } @@ -625,7 +626,7 @@ sub quote_item { # database definitions should set some of these defaults but dont my $order_hash = { biblionumber => $bib->{biblionumber}, - entrydate => DateTime->now( time_zone => 'local' )->ymd(), + entrydate => dt_from_string()->ymd(), basketno => $basketno, listprice => $item->price, quantity => $order_quantity, diff --git a/Koha/Edifact/Order.pm b/Koha/Edifact/Order.pm index 062a2f930a..dc88426f6c 100644 --- a/Koha/Edifact/Order.pm +++ b/Koha/Edifact/Order.pm @@ -26,6 +26,7 @@ use DateTime; use Readonly; use Business::ISBN; use Koha::Database; +use Koha::DateUtils; use C4::Budgets qw( GetBudget ); use Koha::Acquisition::Orders; @@ -51,7 +52,7 @@ sub new { # convenient alias $self->{basket} = $self->{orderlines}->[0]->basketno; - $self->{message_date} = DateTime->now( time_zone => 'local' ); + $self->{message_date} = dt_from_string(); } # validate that its worth proceeding diff --git a/Koha/Edifact/Transport.pm b/Koha/Edifact/Transport.pm index a64d583776..e52b6ef468 100644 --- a/Koha/Edifact/Transport.pm +++ b/Koha/Edifact/Transport.pm @@ -29,6 +29,7 @@ use File::Slurp; use File::Copy; use File::Basename qw( fileparse ); use Koha::Database; +use Koha::DateUtils; use Encode qw( from_to ); sub new { @@ -40,7 +41,7 @@ sub new { account => $acct, schema => $schema, working_dir => C4::Context::temporary_directory, #temporary work directory - transfer_date => DateTime->now( time_zone => 'local' ), + transfer_date => dt_from_string(), }; bless $self, $class; diff --git a/Koha/Illrequest.pm b/Koha/Illrequest.pm index 5e0a806f38..b576c47074 100644 --- a/Koha/Illrequest.pm +++ b/Koha/Illrequest.pm @@ -28,6 +28,7 @@ use Try::Tiny; use DateTime; use Koha::Database; +use Koha::DateUtils qw/ dt_from_string /; use Koha::Email; use Koha::Exceptions::Ill; use Koha::Illcomments; @@ -662,7 +663,7 @@ Mark a request as completed (status = COMP). sub mark_completed { my ( $self ) = @_; $self->status('COMP')->store; - $self->completed(DateTime->now)->store; + $self->completed(dt_from_string())->store; return { error => 0, status => '', diff --git a/Koha/Patron/Password/Recovery.pm b/Koha/Patron/Password/Recovery.pm index 0d09923bf1..664035481d 100644 --- a/Koha/Patron/Password/Recovery.pm +++ b/Koha/Patron/Password/Recovery.pm @@ -21,6 +21,7 @@ use Modern::Perl; use C4::Context; use C4::Letters; use Crypt::Eksblowfish::Bcrypt qw(en_base64); +use Koha::DateUtils; use vars qw(@ISA @EXPORT); @@ -115,7 +116,7 @@ sub SendPasswordRecoveryEmail { # insert into database my $expirydate = - DateTime->now( time_zone => C4::Context->tz() )->add( days => 2 ); + dt_from_string()->add( days => 2 ); if ($update) { my $rs = $schema->resultset('BorrowerPasswordRecovery') diff --git a/Koha/Sitemapper/Writer.pm b/Koha/Sitemapper/Writer.pm index d00c175c9d..2dfe122cac 100644 --- a/Koha/Sitemapper/Writer.pm +++ b/Koha/Sitemapper/Writer.pm @@ -23,7 +23,7 @@ use Moo; use Modern::Perl; use XML::Writer; use IO::File; -use DateTime; +use Koha::DateUtils; my $MAX = 50000; @@ -106,7 +106,7 @@ sub end { my $w = $self->_writer_create("sitemapindex.xml"); $w->startTag('sitemapindex', 'xmlns' => 'http://www.sitemaps.org/schemas/sitemap/0.9'); - my $now = DateTime->now()->ymd; + my $now = dt_from_string()->ymd; for my $i ( 1..$self->count ) { $w->startTag('sitemap'); $w->startTag('loc'); diff --git a/Koha/StockRotationItem.pm b/Koha/StockRotationItem.pm index e451bb08db..2aa7a17ca8 100644 --- a/Koha/StockRotationItem.pm +++ b/Koha/StockRotationItem.pm @@ -129,7 +129,7 @@ sub needs_advancing { ); my $duration = DateTime::Duration ->new( days => $self->stage->duration ); - if ( $arrival + $duration le DateTime->now ) { + if ( $arrival + $duration le dt_from_string() ) { return 1; } else { return 0; @@ -155,7 +155,7 @@ sub repatriate { 'itemnumber' => $self->itemnumber_id, 'frombranch' => $self->itemnumber->holdingbranch, 'tobranch' => $self->stage->branchcode_id, - 'datesent' => DateTime->now, + 'datesent' => dt_from_string(), 'comments' => $msg || "StockrotationRepatriation", })->store; $self->itemnumber->homebranch($self->stage->branchcode_id)->store; @@ -184,14 +184,14 @@ sub advance { my $transfer = Koha::Item::Transfer->new({ 'itemnumber' => $self->itemnumber_id, 'frombranch' => $item->holdingbranch, - 'datesent' => DateTime->now, + 'datesent' => dt_from_string(), 'comments' => "StockrotationAdvance" }); if ( $self->indemand && !$self->fresh ) { $self->indemand(0)->store; # De-activate indemand $transfer->tobranch($self->stage->branchcode_id); - $transfer->datearrived(DateTime->now); + $transfer->datearrived(dt_from_string()); } else { # Find and update our stage. my $stage = $self->stage; @@ -199,7 +199,7 @@ sub advance { if ( $self->fresh ) { # Just added to rota $new_stage = $self->stage->first_sibling || $self->stage; $transfer->tobranch($new_stage->branchcode_id); - $transfer->datearrived(DateTime->now) # Already at first branch + $transfer->datearrived(dt_from_string()) # Already at first branch if $item->holdingbranch eq $new_stage->branchcode_id; $self->fresh(0)->store; # Reset fresh } elsif ( !$stage->last_sibling ) { # Last stage @@ -207,7 +207,7 @@ sub advance { # Revert to first stage. $new_stage = $stage->first_sibling || $stage; $transfer->tobranch($new_stage->branchcode_id); - $transfer->datearrived(DateTime->now); + $transfer->datearrived(dt_from_string()); } else { $self->delete; # StockRotationItem is done. return 1; diff --git a/circ/overdue.pl b/circ/overdue.pl index a1c8bb748e..7eb6d08a21 100755 --- a/circ/overdue.pl +++ b/circ/overdue.pl @@ -214,7 +214,7 @@ if ($noreport) { # FIX 2: ensure there are indexes for columns participating in the WHERE clauses, where feasible/reasonable - my $today_dt = DateTime->now(time_zone => C4::Context->tz); + my $today_dt = dt_from_string(); $today_dt->truncate(to => 'minute'); my $todaysdate = $today_dt->strftime('%Y-%m-%d %H:%M'); diff --git a/circ/returns.pl b/circ/returns.pl index a9e2bc243c..903a646d04 100755 --- a/circ/returns.pl +++ b/circ/returns.pl @@ -309,7 +309,7 @@ if ($barcode) { AddReturn( $barcode, $userenv_branch, $exemptfine, $return_date ); if ($returned) { - my $time_now = DateTime->now( time_zone => C4::Context->tz )->truncate( to => 'minute'); + my $time_now = dt_from_string()->truncate( to => 'minute'); my $date_due_dt = dt_from_string( $issue->date_due, 'sql' ); my $duedate = $date_due_dt->strftime('%Y-%m-%d %H:%M'); $returneditems{0} = $barcode; @@ -318,7 +318,7 @@ if ($barcode) { $input{borrowernumber} = $borrower->{'borrowernumber'}; $input{duedate} = $duedate; unless ( $dropboxmode ) { - $input{return_overdue} = 1 if (DateTime->compare($date_due_dt, DateTime->now()) == -1); + $input{return_overdue} = 1 if (DateTime->compare($date_due_dt, dt_from_string()) == -1); } else { $input{return_overdue} = 1 if (DateTime->compare($date_due_dt, $dropboxdate) == -1); } @@ -575,7 +575,7 @@ foreach ( sort { $a <=> $b } keys %returneditems ) { $ri{duedate} = output_pref($duedate); my $patron = Koha::Patrons->find( $riborrowernumber{$_} ); unless ( $dropboxmode ) { - $ri{return_overdue} = 1 if (DateTime->compare($duedate, DateTime->now()) == -1); + $ri{return_overdue} = 1 if (DateTime->compare($duedate, dt_from_string()) == -1); } else { $ri{return_overdue} = 1 if (DateTime->compare($duedate, $dropboxdate) == -1); } diff --git a/installer/data/mysql/fix_unclosed_nonaccruing_fines_bug17135.pl b/installer/data/mysql/fix_unclosed_nonaccruing_fines_bug17135.pl index b7f1efd088..cc3a85d988 100755 --- a/installer/data/mysql/fix_unclosed_nonaccruing_fines_bug17135.pl +++ b/installer/data/mysql/fix_unclosed_nonaccruing_fines_bug17135.pl @@ -76,7 +76,7 @@ sub Bug_17135_fix { my $control = C4::Context->preference('CircControl'); my $mode = C4::Context->preference('finesMode'); - my $today = DateTime->now( time_zone => C4::Context->tz() ); + my $today = dt_from_string(); my $dbh = C4::Context->dbh; ## fetch the unclosed FU fines linked to the issues by issue_id diff --git a/installer/data/mysql/updatedatabase.pl b/installer/data/mysql/updatedatabase.pl index eb79de8baa..7df5db1ad7 100755 --- a/installer/data/mysql/updatedatabase.pl +++ b/installer/data/mysql/updatedatabase.pl @@ -16262,7 +16262,7 @@ $DBversion = '18.06.00.016'; if( CheckVersion( $DBversion ) ) { my $dtf = Koha::Database->new->schema->storage->datetime_parser; my $days = C4::Context->preference('MaxPickupDelay') || 7; - my $date = DateTime->now()->add( days => $days ); + my $date = dt_from_string()->add( days => $days ); my $sql = q|UPDATE reserves SET expirationdate = ? WHERE expirationdate IS NULL AND waitingdate IS NOT NULL|; $dbh->do( $sql, undef, $dtf->format_datetime($date) ); SetVersion( $DBversion ); diff --git a/members/summary-print.pl b/members/summary-print.pl index 38127c9061..a0fee06c59 100755 --- a/members/summary-print.pl +++ b/members/summary-print.pl @@ -25,6 +25,7 @@ use C4::Members; use C4::Circulation qw( GetIssuingCharges ); use C4::Reserves; use C4::Items; +use Koha::DateUtils; use Koha::Holds; use Koha::ItemTypes; use Koha::Patrons; @@ -109,7 +110,7 @@ sub build_reserve_data { my $return = []; - my $today = DateTime->now( time_zone => C4::Context->tz ); + my $today = dt_from_string(); $today->truncate( to => 'day' ); while ( my $reserve = $reserves->next() ) { diff --git a/misc/cronjobs/fines.pl b/misc/cronjobs/fines.pl index 8d8c9c543e..d68d817de0 100755 --- a/misc/cronjobs/fines.pl +++ b/misc/cronjobs/fines.pl @@ -84,7 +84,7 @@ my $mode = C4::Context->preference('finesMode'); my $delim = "\t"; # ? C4::Context->preference('delimiter') || "\t"; my %is_holiday; -my $today = DateTime->now( time_zone => C4::Context->tz() ); +my $today = dt_from_string(); my $filename; if ($log or $output_dir) { $filename = get_filename($output_dir); diff --git a/misc/cronjobs/overdue_notices.pl b/misc/cronjobs/overdue_notices.pl index a4348fed24..9b49dd084c 100755 --- a/misc/cronjobs/overdue_notices.pl +++ b/misc/cronjobs/overdue_notices.pl @@ -417,7 +417,7 @@ if ( defined $htmlfilename ) { if ( $htmlfilename eq '' ) { $fh = *STDOUT; } else { - my $today = DateTime->now(time_zone => C4::Context->tz ); + my $today = dt_from_string(); open $fh, ">:encoding(UTF-8)",File::Spec->catdir ($htmlfilename,"notices-".$today->ymd().".html"); } @@ -438,7 +438,7 @@ elsif ( defined $text_filename ) { if ( $text_filename eq '' ) { $fh = *STDOUT; } else { - my $today = DateTime->now(time_zone => C4::Context->tz ); + my $today = dt_from_string(); open $fh, ">",File::Spec->catdir ($text_filename,"notices-".$today->ymd().".txt"); } } diff --git a/misc/cronjobs/update_totalissues.pl b/misc/cronjobs/update_totalissues.pl index 7e24d0788d..6421779d16 100755 --- a/misc/cronjobs/update_totalissues.pl +++ b/misc/cronjobs/update_totalissues.pl @@ -32,6 +32,7 @@ use Getopt::Long; use Pod::Usage; use Koha::Script -cron; +use Koha::DateUtils qw/ dt_from_string /; use C4::Context; use C4::Biblio; use C4::Log; @@ -122,7 +123,7 @@ sub process_items { sub process_stats { if ($interval) { - my $dt = DateTime->now; + my $dt = dt_from_string(); my %units = ( h => 'hours', diff --git a/opac/opac-ics.pl b/opac/opac-ics.pl index 4069ce78ca..fb1ae4db68 100755 --- a/opac/opac-ics.pl +++ b/opac/opac-ics.pl @@ -55,7 +55,7 @@ my $pending_checkouts = $patron->pending_checkouts; while ( my $c = $pending_checkouts->next ) { my $issue = $c->unblessed_all_relateds; my $vevent = Data::ICal::Entry::Event->new(); - my $timestamp = DateTime->now(); # Defaults to UTC + my $timestamp = dt_from_string(undef,undef,"UTC"); #Get current time in UTC # Send some values to the template to generate summary and description $issue->{overdue} = $c->is_overdue; $template->param( diff --git a/t/Circulation/AgeRestrictionMarkers.t b/t/Circulation/AgeRestrictionMarkers.t index 49c1d14444..0fc362d200 100644 --- a/t/Circulation/AgeRestrictionMarkers.t +++ b/t/Circulation/AgeRestrictionMarkers.t @@ -22,6 +22,7 @@ use Modern::Perl; use DateTime; use Test::More tests => 7; +use Koha::DateUtils; use t::lib::Mocks; @@ -38,7 +39,7 @@ is ( C4::Circulation::GetAgeRestriction('K16'), '16', 'K16 returns 16' ); subtest 'Patron tests - 15 years old' => sub { plan tests => 5; ##Testing age restriction for a borrower. - my $now = DateTime->now(); + my $now = dt_from_string(); my $borrower = { dateofbirth => $now->add( years => -15 )->strftime("%Y-%m-%d") }; TestPatron($borrower,0); }; @@ -55,7 +56,7 @@ subtest 'Patron tests - 15 years old (Time Zone shifts)' => sub { Time::Fake->offset("+${offset}h"); ##Testing age restriction for a borrower. - my $now = DateTime->now(); + my $now = dt_from_string(); my $borrower = { dateofbirth => $now->add( years => -15 )->strftime("%Y-%m-%d") }; TestPatron($borrower,$offset); diff --git a/t/db_dependent/DecreaseLoanHighHolds.t b/t/db_dependent/DecreaseLoanHighHolds.t index daa975bb9b..9128aae215 100755 --- a/t/db_dependent/DecreaseLoanHighHolds.t +++ b/t/db_dependent/DecreaseLoanHighHolds.t @@ -20,6 +20,7 @@ use DateTime; use C4::Circulation; use Koha::Database; +use Koha::DateUtils; use Koha::Patrons; use Koha::Biblio; use Koha::Item; @@ -38,7 +39,7 @@ my $builder = t::lib::TestBuilder->new; $dbh->{RaiseError} = 1; $schema->storage->txn_begin(); -my $now_value = DateTime->now(); +my $now_value = dt_from_string(); my $mocked_datetime = Test::MockModule->new('DateTime'); $mocked_datetime->mock( 'now', sub { return $now_value->clone; } ); @@ -112,7 +113,7 @@ $builder->build( my $orig_due = C4::Circulation::CalcDateDue( - DateTime->now(time_zone => C4::Context->tz()), + dt_from_string(), $item->effective_itemtype, $patron->branchcode, $patron->unblessed diff --git a/t/db_dependent/Letters/TemplateToolkit.t b/t/db_dependent/Letters/TemplateToolkit.t index fff90b17fb..af8778f8c6 100644 --- a/t/db_dependent/Letters/TemplateToolkit.t +++ b/t/db_dependent/Letters/TemplateToolkit.t @@ -58,7 +58,7 @@ $dbh->{RaiseError} = 1; $dbh->do(q|DELETE FROM letter|); -my $now_value = DateTime->now(); +my $now_value = dt_from_string(); my $mocked_datetime = Test::MockModule->new('DateTime'); $mocked_datetime->mock( 'now', sub { return $now_value->clone; } ); diff --git a/t/db_dependent/OAI/Server.t b/t/db_dependent/OAI/Server.t index d0bbfff76d..de6939f2f7 100644 --- a/t/db_dependent/OAI/Server.t +++ b/t/db_dependent/OAI/Server.t @@ -72,7 +72,7 @@ $dbh->do('DELETE FROM oai_sets'); set_fixed_time(CORE::time()); -my $base_datetime = DateTime->now(); +my $base_datetime = dt_from_string(); my $date_added = $base_datetime->ymd . ' ' .$base_datetime->hms . 'Z'; my $date_to = substr($date_added, 0, 10) . 'T23:59:59Z'; my (@header, @marcxml, @oaidc); diff --git a/t/db_dependent/Passwordrecovery.t b/t/db_dependent/Passwordrecovery.t index 37f5ca9658..ccf567a689 100755 --- a/t/db_dependent/Passwordrecovery.t +++ b/t/db_dependent/Passwordrecovery.t @@ -21,6 +21,7 @@ use C4::Context; use Mail::Sendmail; use C4::Letters; use Koha::Database; +use Koha::DateUtils; use Koha::Patrons; use t::lib::TestBuilder; @@ -115,21 +116,21 @@ $schema->resultset('BorrowerPasswordRecovery')->create( { borrowernumber => $borrowernumber1, uuid => $uuid1, - valid_until => DateTime->now( time_zone => C4::Context->tz() )->add( days => 2 )->datetime() + valid_until => dt_from_string()->add( days => 2 )->datetime() } ); $schema->resultset('BorrowerPasswordRecovery')->create( { borrowernumber => $borrowernumber2, uuid => $uuid2, - valid_until => DateTime->now( time_zone => C4::Context->tz() )->subtract( days => 2 )->datetime() + valid_until => dt_from_string()->subtract( days => 2 )->datetime() } ); $schema->resultset('BorrowerPasswordRecovery')->create( { borrowernumber => $borrowernumber3, uuid => $uuid3, - valid_until => DateTime->now( time_zone => C4::Context->tz() )->subtract( days => 3 )->datetime() + valid_until => dt_from_string()->subtract( days => 3 )->datetime() } ); @@ -167,7 +168,7 @@ $schema->resultset('BorrowerPasswordRecovery')->create( { borrowernumber => $borrowernumber2, uuid => $uuid2, - valid_until => DateTime->now( time_zone => C4::Context->tz() )->subtract( days => 2 )->datetime() + valid_until => dt_from_string()->subtract( days => 2 )->datetime() } ); @@ -182,7 +183,7 @@ $schema->resultset('BorrowerPasswordRecovery')->create( { borrowernumber => $borrowernumber3, uuid => $uuid3, - valid_until => DateTime->now( time_zone => C4::Context->tz() )->subtract( days => 3 )->datetime() + valid_until => dt_from_string()->subtract( days => 3 )->datetime() } ); diff --git a/t/db_dependent/Sitemapper.t b/t/db_dependent/Sitemapper.t index 30c64cfd1d..7bb2dba55e 100755 --- a/t/db_dependent/Sitemapper.t +++ b/t/db_dependent/Sitemapper.t @@ -21,6 +21,7 @@ use Modern::Perl; use File::Basename; use File::Path; use DateTime; +use Koha::DateUtils; use Test::MockModule; use Test::More tests => 16; use Carp qw/croak carp/; @@ -31,7 +32,7 @@ BEGIN { use_ok('Koha::Sitemapper::Writer'); } -my $now_value = DateTime->now(); +my $now_value = dt_from_string(); my $mocked_datetime = Test::MockModule->new('DateTime'); $mocked_datetime->mock( 'now', sub { return $now_value->clone; } ); -- 2.11.0