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();
}
}
- my $issuedate = DateTime->now( time_zone => C4::Context->tz() );
+ my $issuedate = dt_from_string();
my $calendar = Koha::Calendar->new( branchcode => $branchcode );
# $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' ) {
$item_object->holdingbranch(C4::Context->userenv->{'branch'});
$item_object->itemlost(0);
$item_object->onloan($datedue->ymd());
- $item_object->datelastborrowed(DateTime->now( time_zone => C4::Context->tz() )->ymd()); # FIXME we should use dt_from_string here
+ $item_object->datelastborrowed( dt_from_string()->ymd() );
$item_object->store({log_action => 0});
ModDateLastSeen( $item_object->itemnumber );
$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 && $patron->autorenew_checkouts;
return ( 0, "too_soon" );
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 $skipfinecalc = shift;
my $item_object = Koha::Items->find($itemnumber) or return;
$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');
}
$datedue = $startdate->clone;
}
} else {
- $datedue =
- DateTime->now( time_zone => C4::Context->tz() )
- ->truncate( to => 'minute' );
+ $datedue = dt_from_string()->truncate( to => 'minute' );
}
}
#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);
}
if ($letter->{content} && $letter->{content} =~ /<<today>>/) {
- my $todaysdate = output_pref( DateTime->now() );
+ my $todaysdate = output_pref( dt_from_string() );
$letter->{content} =~ s/<<today>>/$todaysdate/go;
}
use C4::Context;
use Koha::SimpleMARC;
use Koha::MoreUtils;
+use Koha::DateUtils;
use vars qw(@ISA @EXPORT);
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;
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);
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
use C4::Context;
use Koha::Checkout;
use Koha::Database;
+use Koha::DateUtils;
use base qw(Koha::Objects);
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;
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::Biblio qw( AddBiblio TransformKohaToMarc GetMarcBiblio GetFrameworkCode GetMarcFromKohaField );
ordernumber => $ordernumber,
cancellationreason => $reason,
orderstatus => 'cancelled',
- datecancellationprinted => DateTime->now()->ymd(),
+ datecancellationprinted => dt_from_string()->ymd(),
}
);
}
# 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,
use Readonly;
use Business::ISBN;
use Koha::Database;
+use Koha::DateUtils;
use C4::Budgets qw( GetBudget );
use Koha::Acquisition::Orders;
# 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
use File::Copy;
use File::Basename qw( fileparse );
use Koha::Database;
+use Koha::DateUtils;
use Encode qw( from_to );
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;
use C4::Context;
use C4::Letters;
use Crypt::Eksblowfish::Bcrypt qw(en_base64);
+use Koha::DateUtils;
use vars qw(@ISA @EXPORT);
# 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')
use Modern::Perl;
use XML::Writer;
use IO::File;
-use DateTime;
+use Koha::DateUtils;
my $MAX = 50000;
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');
# 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');
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;
$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);
}
$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);
}
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
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 );
use C4::Circulation qw( GetIssuingCharges );
use C4::Reserves;
use C4::Items;
+use Koha::DateUtils;
use Koha::Holds;
use Koha::ItemTypes;
use Koha::Patrons;
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() ) {
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);
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");
}
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");
}
}
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(
use Modern::Perl;
use DateTime;
+use Koha::DateUtils;
use Test::More tests => 8;
use Test::Warn;
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);
};
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);
use C4::Circulation;
use Koha::Database;
+use Koha::DateUtils;
use Koha::Patrons;
use Koha::Biblio;
use Koha::Item;
$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; } );
my $orig_due = C4::Circulation::CalcDateDue(
- DateTime->now(time_zone => C4::Context->tz()),
+ dt_from_string(),
$item->effective_itemtype,
$patron->branchcode,
$patron->unblessed
$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; } );
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);
use Mail::Sendmail;
use C4::Letters;
use Koha::Database;
+use Koha::DateUtils;
use Koha::Patrons;
use t::lib::TestBuilder;
{
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()
}
);
{
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()
}
);
{
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()
}
);
use File::Basename;
use File::Path;
use DateTime;
+use Koha::DateUtils;
use Test::MockModule;
use Test::More tests => 16;
use Carp qw/croak carp/;
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; } );