Bug 38046 - Koha::Calendar dies on invalid datetimes during addDuration()
Summary: Koha::Calendar dies on invalid datetimes during addDuration()
Status: NEW
Alias: None
Product: Koha
Classification: Unclassified
Component: Circulation (show other bugs)
Version: 23.11
Hardware: All All
: P5 - low normal
Assignee: Bugs List
QA Contact: Testopia
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-10-01 03:40 UTC by David Cook
Modified: 2024-10-01 04:20 UTC (History)
2 users (show)

See Also:
GIT URL:
Change sponsored?: ---
Patch complexity: ---
Documentation contact:
Documentation submission:
Text to go in the release notes:
Version(s) released in:
Circulation function:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Cook 2024-10-01 03:40:50 UTC
We noticed recently if AddRenewal is run during automatic_renewals.pl between 2am and 3am, it will reliably crash for 1 Koha instance:

{UNKNOWN}: Invalid local time for date in time zone: Australia/Sydney at /usr/share/koha/lib/C4/Circulation.pm line 3405

There is no valid Australia/Sydney time between October 6th 2:00am 2024 and October 6th 2:59am 2024, so I suspect that at some point during the AddRenewal process, there is an attempt to generate a DateTime object in the Australia/Sydney timezone within that datetime range.

--

We're going to work around it by just making sure the automatic_renewals.pl cronjob doesn't run between 2am and 3am, but it's not a real solution...
Comment 1 David Cook 2024-10-01 03:55:23 UTC
There is a HardDueDate which I think will be fetched with Australia/Sydney timezone... but with 00:00:00 time. 

October 7th is also a holiday... 

I keep thinking this is a Koha::Calendar bug but I'm not sure how yet... overall the time and time_zone handling looks OK.

But there must be somewhere that the time for now() must be used with a time_zone of Australia/Sydney on October 6th...
Comment 2 David Cook 2024-10-01 04:16:33 UTC
Ok, I think that I've got it...

my $datedue = dt_from_string();
$datedue->set_hour('02');
$datedue->set_minute('54');

my $dur = DateTime::Duration->new( days => 14);

my $branchcode = 'CPL';
my $daysmode = 'Calendar';

my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );

--

The above will produce the fatal error: "Invalid local time for date in time zone: Australia/Sydney"
Comment 3 David Cook 2024-10-01 04:17:45 UTC
(In reply to David Cook from comment #2)
> Ok, I think that I've got it...

Ooops, didn't copy the code quite correctly.

my $datedue = dt_from_string();
$datedue->set_hour('02');
$datedue->set_minute('54');
 
my $dur = DateTime::Duration->new( days => 14);
 
my $branchcode = 'CPL';
my $daysmode = 'Calendar';
my $calendar = Koha::Calendar->new( branchcode => $branchcode, days_mode => $daysmode );

$datedue = $calendar->addDuration( $datedue, $dur, 14 );
Comment 4 David Cook 2024-10-01 04:20:04 UTC
Ok going to update the title from "AddRenewal dies due to daylight savings time issue and some other unknown factor" to "Koha::Calendar dies on invalid datetimes during addDuration()".

The actual problem functions are used by addDuration(), so more investigation is needed, but yeah... not fun.