From d3b73e391b745a4d0957d440d2d1e49a8baea1d8 Mon Sep 17 00:00:00 2001 From: Kyle Hall Date: Wed, 8 Jun 2022 13:34:12 -0400 Subject: [PATCH] Bug 30927 - Improve formatting or iCal files for checkout due dates We got some feedback from a patron regarding the default notifications on the iCal export for the patron checkout summary in the OPAC. The notifications send 1 minute before the event (the due date), which is midnight. It makes more sense for: A) Checkouts due at midnight to be "All day events" B) Checkouts due at specific time to start in the morning, and end at the time due. Test Plan: 1) Apply this patch 2) Restart all the things! 3) Make a checkout due at 23:59 4) Make a checkout due at 11:00 5) Download the iCal file from the OPAC 6) Import this file into Calendar 7) Note the first checkout is an all day event 8) Note the second checkout starts in the morning and ends at the due time --- opac/opac-ics.pl | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/opac/opac-ics.pl b/opac/opac-ics.pl index 62603f3a2f..ae3a549192 100755 --- a/opac/opac-ics.pl +++ b/opac/opac-ics.pl @@ -61,12 +61,14 @@ while ( my $c = $pending_checkouts->next ) { # Catch the result of the template and split on newline my ($summary,$description) = split /\n/, $template->output; my $datestart; + my $datestart_local; if ($issue->{'overdue'} && $issue->{'overdue'} == 1) { # Not much use adding an event in the past for a book that is overdue # so we set datestart = now $datestart = $timestamp; } else { $datestart = dt_from_string($issue->{'date_due'}); + $datestart_local = $datestart->clone(); $datestart->set_time_zone('UTC'); } # Create a UID that includes the issue number and the domain @@ -80,11 +82,23 @@ while ( my $c = $pending_checkouts->next ) { } my $uid = 'issue-' . $issue->{'issue_id'} . '@' . $domain; # Create the event + + my ( $dtstart, $dtend ); + # Checkouts due at 23:59 are "all day events" + if ( $datestart_local->hour eq '23' && $datestart_local->minute eq '59' ) { + $dtstart = $datestart->ymd(q{}); + $dtend = $datestart->clone()->add(days => 1)->ymd(q{}), + } + else { # Checkouts due any other time start at 00:00 and end at the due time + $dtstart = DateTime::Format::ICal->format_datetime($datestart->clone()->truncate( to => "day")); + $dtend = DateTime::Format::ICal->format_datetime($datestart); + } + $vevent->add_properties( summary => $summary, description => $description, - dtstamp => DateTime::Format::ICal->format_datetime($timestamp), - dtstart => DateTime::Format::ICal->format_datetime($datestart), + dtstart => $dtstart, + dtend => $datestart->clone()->add(days => 1)->ymd(q{}), uid => $uid, ); # Add it to the calendar -- 2.30.2