Skip to content

Instantly share code, notes, and snippets.

@alexwoollam
Last active June 14, 2018 10:42
Show Gist options
  • Save alexwoollam/233012607b7da7a6d6070401891496b7 to your computer and use it in GitHub Desktop.
Save alexwoollam/233012607b7da7a6d6070401891496b7 to your computer and use it in GitHub Desktop.
possible ai1ec bst/gmt fix
<?php
$query = "SELECT * FROM {$wpdb->posts} JOIN {$wpdb->prefix}ai1ec_events on ({$wpdb->prefix}ai1ec_events.post_id={$wpdb->posts}.ID)
WHERE post_type='ai1ec_event' AND post_status='publish' AND {$wpdb->prefix}ai1ec_events.start > '".time()."' ORDER BY {$wpdb->prefix}ai1ec_events.start limit 3";
$results = $wpdb->get_results( $query ); // get result form the query
ob_start();
foreach($results as $result){
$title = ($result->post_title); // Returns the post type title
$event_date = ($result->start); // Returns the date
$datetime = new Datetime();
$datetime->setTimezone($result->timezone_name);
$datetime->setTimestamp($result->start);
$datetime->setTime(0, 0, 0);
$bstMonth = date('Y/03/d', strtotime('last sunday of march')); //set start of BST
$gmtMonth = date('Y/10/d', strtotime('last sunday of october')); //set start of GMT
$event_date_sanitized = $datetime->format('Y/m/d'); //format ai1ce date to match above date formates
if($result->allday){ //check if allday
if($event_date_sanitized >= $bstMonth && $event_date_sanitized <= $gmtMonth){ //check if gmt or bst...
$datetime->modify('+1 day'); //add a day, due to the all day starting at 11pm the previous day
} elseif($event_date_sanitized >= $gmtMonth) {
$datetime->modify('+0 day'); //leave as is if GMT.
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment