-
-
Save joshfeck/c6d11834362749815829a6a30e91e61f to your computer and use it in GitHub Desktop.
Show timezone next to datetimes displayed on the Event Espresso event page.
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 | |
//* 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