Skip to content

Commit

Permalink
change date time imports completely
Browse files Browse the repository at this point in the history
  • Loading branch information
michb committed Jan 23, 2024
1 parent 4ad849d commit 041ce26
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/Import/CalendarEventsImport.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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'];
Expand Down

0 comments on commit 041ce26

Please sign in to comment.