/** * @access public * @param string $timezone_string */ public static function timezone_select_input($timezone_string = '') { // get WP date time format $datetime_format = get_option('date_format') . ' ' . get_option('time_format'); // if passed a value, then use that, else get WP option $timezone_string = !empty($timezone_string) ? $timezone_string : get_option('timezone_string'); // check if the timezone is valid but don't throw any errors if it isn't $timezone_string = EEH_DTT_Helper::validate_timezone($timezone_string, false); $gmt_offset = get_option('gmt_offset'); $check_zone_info = true; if (empty($timezone_string)) { // Create a UTC+- zone if no timezone string exists $check_zone_info = false; if ($gmt_offset > 0) { $timezone_string = 'UTC+' . $gmt_offset; } elseif ($gmt_offset < 0) { $timezone_string = 'UTC' . $gmt_offset; } else { $timezone_string = 'UTC'; } } ?> <p> <label for="timezone_string"><?php _e('timezone'); ?> </label> <select id="timezone_string" name="timezone_string"> <?php echo wp_timezone_choice($timezone_string); ?> </select> <br /> <span class="description"><?php _e('Choose a city in the same timezone as the event.'); ?> </span> </p> <p> <span><?php printf(__('%1$sUTC%2$s time is %3$s'), '<abbr title="Coordinated Universal Time">', '</abbr>', '<code>' . date_i18n($datetime_format, false, 'gmt') . '</code>'); ?> </span> <?php if (!empty($timezone_string) || !empty($gmt_offset)) { ?> <br /><span><?php printf(__('Local time is %1$s'), '<code>' . date_i18n($datetime_format) . '</code>'); ?> </span> <?php } ?> <?php if ($check_zone_info && $timezone_string) { ?> <br /> <span> <?php // Set TZ so localtime works. date_default_timezone_set($timezone_string); $now = localtime(time(), true); if ($now['tm_isdst']) { _e('This timezone is currently in daylight saving time.'); } else { _e('This timezone is currently in standard time.'); } ?> <br /> <?php if (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()); $right_now = time(); $tr['isdst'] = false; foreach (timezone_transitions_get($date_time_zone_selected) as $tr) { if ($tr['ts'] > $right_now) { $found = true; break; } } if ($found) { $message = $tr['isdst'] ? __(' Daylight saving time begins on: %s.') : __(' Standard time begins on: %s.'); // Add the difference between the current offset and the new offset to ts to get the correct transition time from date_i18n(). printf($message, '<code >' . date_i18n($datetime_format, $tr['ts'] + ($tz_offset - $tr['offset'])) . '</code >'); } else { _e('This timezone does not observe daylight saving time.'); } } // Set back to UTC. date_default_timezone_set('UTC'); ?> </span></p> <?php } }