Skip to content

Instantly share code, notes, and snippets.

@codearachnid
Last active December 12, 2015 03:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codearachnid/4705028 to your computer and use it in GitHub Desktop.
Save codearachnid/4705028 to your computer and use it in GitHub Desktop.
Fix for Facebook Event API "bug" that forces all events to use PAC time. http://tri.be/support/forums/topic/maybe-usefull-code-for-timezones-fix/ * Make sure you remove this once you're using any version of Tribe's Facebook Events greater than version 1.0.4
<?php
// fix for http://tri.be/support/forums/topic/maybe-usefull-code-for-timezones-fix/
// remove this once you're using any version of Tribe's Facebook Events greater than version 1.0.4
add_filter( 'tribe_fb_parse_facebook_event', 'tribe_patch_facebook_timezone');
function tribe_patch_facebook_timezone( $event_params ){
// build date string
$start_date = $event_params['EventStartDate'] . ' ' . str_pad($event_params['EventStartHour'], 2, '0', STR_PAD_LEFT) . ':' . str_pad($event_params['EventStartMinute'], 2, '0', STR_PAD_LEFT) . ' ' . $event_params['EventStartMeridian'];
$end_date = $event_params['EventEndDate'] . ' ' . str_pad($event_params['EventEndHour'], 2, '0', STR_PAD_LEFT) . ':' . str_pad($event_params['EventEndMinute'], 2, '0', STR_PAD_LEFT) . ' ' . $event_params['EventEndMeridian'];
$timezone = 'America/Los_Angeles';
tribe_patch_convert_to_timezone( $start_date, $timezone );
tribe_patch_convert_to_timezone( $end_date, $timezone );
// set the dates
$event_params['EventStartDate'] = TribeDateUtils::dateOnly( $start_date );
$event_params['EventEndDate'] = TribeDateUtils::dateOnly( $end_date );
if ( empty($event_params['EventAllDay']) ) {
$event_params['EventStartHour'] = TribeDateUtils::hourOnly( $start_date );
$event_params['EventStartMinute'] = TribeDateUtils::minutesOnly( $start_date );
$event_params['EventStartMeridian'] = TribeDateUtils::meridianOnly( $start_date );
$event_params['EventEndHour'] = TribeDateUtils::hourOnly( $end_date );
$event_params['EventEndMinute'] = TribeDateUtils::minutesOnly( $end_date );
$event_params['EventEndMeridian'] = TribeDateUtils::meridianOnly( $end_date );
}
return $event_params;
}
function tribe_patch_convert_to_timezone( &$datetime, $timezone = 'GMT', $return_format = 'c' ){
$gmt_offset = get_option( 'gmt_offset' );
$datetime_obj = new DateTime( $datetime, new DateTimeZone( $timezone ) );
$datetime_obj->setTimezone(new DateTimeZone('GMT'));
$datetime_obj->modify( $gmt_offset . ' hours' );
$datetime = $datetime_obj->format( $return_format );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment