Last active
August 29, 2015 14:28
-
-
Save barryhughes/b376c49b447460b2d122 to your computer and use it in GitHub Desktop.
For all day events, express the dates in the local timezone (ie undo the cast to UTC)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Given an iCal item representing an all day event, replaces the start and end dates | |
* which will normally have been converted to UTC with their local timezone equivalents. | |
* | |
* @param array $ical_item | |
* @param WP_Post $event | |
* | |
* @return array | |
*/ | |
function ical_noconvert_all_day_events( array $ical_item, WP_Post $event ) { | |
if ( ! tribe_event_is_all_day( $event->ID ) ) return $ical_item; | |
// The end date gets special handling: we bump it forward one day to create | |
// what iCal will (hopefully) interpret as an inclusive date range from | |
// $start to $end - 1 day | |
$end_date = date_create( $event->_EventEndDate )->modify( '+1 day' )->format( 'Y-m-d' ); | |
$start = str_replace( '-', '', Tribe__Events__Date_Utils::date_only( $event->_EventStartDate ) ); | |
$end = str_replace( '-', '', Tribe__Events__Date_Utils::date_only( $end_date ) ); | |
foreach ( $ical_item as &$field ) { | |
if ( 0 === strpos( $field, 'DTSTART' ) ) | |
$field = 'DTSTART;VALUE=DATE:' . $start; | |
if ( 0 === strpos( $field, 'DTEND' ) ) | |
$field = 'DTEND;VALUE=DATE:' . $end; | |
} | |
return $ical_item; | |
} | |
// Maybe modify items included in the iCal feed | |
add_filter( 'tribe_ical_feed_item', 'ical_noconvert_all_day_events', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment