Skip to content

Commit

Permalink
Merge branch 'TMS-974' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
eebbi committed Nov 13, 2023
2 parents 0302c28 + 659aff9 commit 99334a3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 18 deletions.
2 changes: 1 addition & 1 deletion lib/Eventz.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public static function normalize_event( $event ) : array {
'date_title' => __( 'Dates', 'tms-theme-base' ),
'date' => static::get_event_date( $event ),
'dates' => static::get_event_dates( $event ),
'recurring' => count( $event->event->dates ) > 1,
'recurring' => isset( $event->event->dates ) ? count( $event->event->dates ) > 1 : null,
'time_title' => __( 'Time', 'tms-theme-base' ),
'time' => static::get_event_time( $event ),
// Include raw dates for possible sorting.
Expand Down
54 changes: 37 additions & 17 deletions models/page-events-search.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,30 +318,50 @@ protected function create_recurring_events( $events ) {
if ( count( $event['dates'] ) > 1 ) {
foreach ( $event['dates'] as $date ) {
$clone = $event;
// Split the string into date and time range
list( $datePart, $timeRange ) = explode( ' ', $date['date'], 2 );

// Parse the date
$newDate = DateTime::createFromFormat( 'd.m.Y', $datePart );
// Split the dates and times into parts
list( $startPart, $endPart ) = explode( ' - ', $date['date'], 2 );
list( $startDate, $startTime ) = explode( ' ', $startPart, 2 );

// Split the time range into start and end times
list( $startTime, $endTime ) = explode( ' - ', $timeRange );
// Check if endPart includes date & time
if ( strpos($endPart, ' ') ) {
list( $endDate, $endTime ) = explode( ' ', $endPart, 2 );
}
else {
$endTime = $endPart;
}

// Parse the dates
$newStartDate = DateTime::createFromFormat( 'd.m.Y', $startDate );
$newEndDate = $endDate ? DateTime::createFromFormat( 'd.m.Y', $endDate ) : null;

// Parse the start and end times
$startDateTime = DateTime::createFromFormat( 'H.i', $startTime );
$startDateTime->setDate( $newDate->format( 'Y' ), $newDate->format( 'm' ), $newDate->format( 'd' ) );
$endDateTime = DateTime::createFromFormat( 'H.i', $endTime );
$endDateTime->setDate( $newDate->format( 'Y' ), $newDate->format( 'm' ), $newDate->format( 'd' ) );

$clone['date'] = $newDate->format( 'd.m.Y' );
$startDateTime->setDate( $newStartDate->format( 'Y' ), $newStartDate->format( 'm' ), $newStartDate->format( 'd' ) );
if ( $newEndDate ) {
$endDateTime = DateTime::createFromFormat( 'H.i', $endTime );
$endDateTime->setDate( $newEndDate->format( 'Y' ), $newEndDate->format( 'm' ), $newEndDate->format( 'd' ) );
}

// Create time & date-ranges
if ( $endTime ) {
$timeRange = $startTime . ' - ' . $endTime;
}
else {
$timeRange = $startTime;
}

if ( $newEndDate ) {
$dateRange = $newStartDate->format( 'd.m.Y' ) . ' - ' . $newEndDate->format( 'd.m.Y' );
}
else {
$dateRange = $newStartDate->format( 'd.m.Y' );
}

$clone['date'] = $dateRange;
$clone['start_date_raw'] = $startDateTime;
$clone['end_date_raw'] = $endDateTime;
$clone['url'] = $event['url'] . '&date=' . urlencode( $datePart ) . '&time=' . urlencode( $timeRange );
$clone['time'] = sprintf(
'%s - %s',
$startDateTime->format( 'H.i' ),
$endDateTime->format( 'H.i' )
);
$clone['url'] = $event['url'] . '&date=' . urlencode( $dateRange ) . '&time=' . urlencode( $timeRange );

$recurring_events[] = $clone;
}
Expand Down

0 comments on commit 99334a3

Please sign in to comment.