Skip to content

Instantly share code, notes, and snippets.

@joshfeck
Created January 24, 2018 18:03
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 joshfeck/c6d11834362749815829a6a30e91e61f to your computer and use it in GitHub Desktop.
Save joshfeck/c6d11834362749815829a6a30e91e61f to your computer and use it in GitHub Desktop.
Show timezone next to datetimes displayed on the Event Espresso event page.
<?php
//* Please do NOT include the opening php tag, except of course if you're starting with a blank file
add_filter(
'FHEE__espresso_list_of_event_dates__datetime_html',
'my_add_eastern_timezone_display',
9,
2
);
function my_add_eastern_timezone_display($html, $datetime){
if (get_option('timezone_string')) {
$timezone_string = get_option('timezone_string');
}
if ($datetime instanceof EE_Datetime && function_exists('timezone_transitions_get')) {
$found = false;
$date_time_zone_selected = new DateTimeZone($timezone_string);
$tz_offset = timezone_offset_get($date_time_zone_selected, date_create());
$end_time = $datetime->end();
$tr['isdst'] = false;
foreach (timezone_transitions_get($date_time_zone_selected) as $tr) {
if ($tr['ts'] > $end_time) {
$found = true;
break;
}
}
if ($found) {
$output = $tr['isdst']
? ' EST'
: ' EDT';
} else {
$output = '';
}
$html .= '<span>' . $output . '</span>';
}
return $html;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment