From 041ce26348f76d2e37bae9b994079cc078eafd7f Mon Sep 17 00:00:00 2001 From: Michael Boesherz Date: Tue, 23 Jan 2024 08:07:13 +0100 Subject: [PATCH] change date time imports completely --- src/Import/CalendarEventsImport.php | 30 +++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/src/Import/CalendarEventsImport.php b/src/Import/CalendarEventsImport.php index 36bde49..8c1f2d2 100644 --- a/src/Import/CalendarEventsImport.php +++ b/src/Import/CalendarEventsImport.php @@ -15,6 +15,7 @@ use Contao\CalendarEventsModel; use Contao\CalendarModel; use Contao\ContentModel; +use Contao\Date; use Contao\StringUtil; use Contao\System; use numero2\ChurchDeskBundle\API\ChurchDeskApi; @@ -157,27 +158,32 @@ private function importEvent( array $new, CalendarModel $calendar ): ?int { $event->alias = $event->churchdesk_id.'-'.StringUtil::standardize($event->title); $event->teaser = $new['summary']; - $event->addTime = $new['allDay'] ? '' : '1'; - $event->startDate = strtotime($new['startDate']); + $startDate = new Date(strtotime($new['startDate'])); + $event->startDate = $startDate->dayBegin; + $event->startTime = $event->startDate; + + $endDate = new Date(strtotime($new['endDate'])); + $event->endDate = $endDate->dayBegin; - $event->endDate = $event->startDate; - if( date("Y-m-d", $event->startDate) !== date("Y-m-d", strtotime($new['endDate'])) ) { - $event->endDate = strtotime($new['endDate']); + if( $event->startDate === $event->endDate ) { + $event->endDate = null; } + $event->addTime = $new['allDay'] ? '' : '1'; if( $event->addTime ) { $event->startTime = strtotime($new['startDate']); - $event->endTime = strtotime($new['endDate']); + $event->endTime = $event->startTime; - } else { + if( $new['showEndtime'] ) { + $event->endTime = strtotime($new['endDate']); + } - $event->startTime = strtotime($new['startDate']); - $event->endTime = strtotime(date("Y-m-d", $event->endDate) . '23:59:59'); - } + } else { - if( !$new['showEndtime'] ) { - $event->endTime = $event->startTime; + if( (strlen($event->endDate) && $event->endTime == $event->endTime) || $event->startTime == $event->endTime ) { + $event->endTime = (strtotime('+ 1 day', $event->endTime) - 1); + } } $event->location = $new['locationName'];