From 58cf5b01addb58569254cb8a7efa406fa3aa9a31 Mon Sep 17 00:00:00 2001 From: Andrew McMillan Date: Tue, 9 Jan 2018 23:10:55 +0000 Subject: [PATCH] Correctly handle durations without units like "PT" While this has always been handled in basic event parsing the handling in VALARM components for related triggers was missing. --- inc/WritableCollection.php | 4 +++- inc/caldav-PUT-functions.php | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/inc/WritableCollection.php b/inc/WritableCollection.php index d190d975..fc033784 100644 --- a/inc/WritableCollection.php +++ b/inc/WritableCollection.php @@ -139,7 +139,8 @@ class WritableCollection extends DAVResource { else { $dtend = 'NULL'; if ( $first->GetPValue('DURATION') != '' AND $dtstart != '' ) { - $duration = preg_replace( '#[PT]#', ' ', $first->GetPValue('DURATION') ); + $duration = preg_replace( '#[PT]#', '', $first->GetPValue('DURATION') ); + if ($duration == '') $duration = '0 seconds'; $dtend = '(:dtstart::timestamp with time zone + :duration::interval)'; $calitem_params[':duration'] = $duration; } @@ -343,6 +344,7 @@ EOSQL; if ( !preg_match('{^-?P(:?\d+W)?(:?\d+D)?(:?T(:?\d+H)?(:?\d+M)?(:?\d+S)?)?$}', $duration ) ) continue; $minus = (substr($duration,0,1) == '-'); $related_trigger = trim(preg_replace( '#[PT-]#', ' ', $duration )); + if ($related_trigger == '') $related_trigger = '0 seconds'; if ( $minus ) { $related_trigger = preg_replace( '{(\d+[WDHMS])}', '-$1 ', $related_trigger ); } diff --git a/inc/caldav-PUT-functions.php b/inc/caldav-PUT-functions.php index 42dc449e..50ea42c2 100644 --- a/inc/caldav-PUT-functions.php +++ b/inc/caldav-PUT-functions.php @@ -1215,6 +1215,7 @@ function write_alarms( $dav_id, vComponent $ical ) { if ( !preg_match('{^-?P(:?\d+W)?(:?\d+D)?(:?T(:?\d+H)?(:?\d+M)?(:?\d+S)?)?$}', $duration ) ) continue; $minus = (substr($duration,0,1) == '-'); $related_trigger = trim(preg_replace( '#[PT-]#', ' ', $duration )); + if ($related_trigger == '') $related_trigger = '0 seconds'; if ( $minus ) { $related_trigger = preg_replace( '{(\d+[WDHMS])}', '-$1 ', $related_trigger ); }