Skip to content

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Returns the blog timezone as a DateTimeZone object
<?php
/*
* Returns the blog's timezone as a DateTimeZone object
*
*/
function sh_get_blog_timezone(){
$timezone = wp_cache_get( 'sh_blog_timezone' );
if ( false === $timezone || ! ($timezone instanceof DateTimeZone) ) {
$tzstring =get_option('timezone_string');
$offset = get_option('gmt_offset');
// Remove old Etc mappings. Fallback to gmt_offset.
if ( !empty($tzstring) && false !== strpos($tzstring,'Etc/GMT') )
$tzstring = '';
if( empty($tzstring) && $offset!=0 ):
//use offset
$offset *= 3600; // convert hour offset to seconds
$allowed_zones = timezone_abbreviations_list();
foreach ($allowed_zones as $abbr):
foreach ($abbr as $city):
if ($city['offset'] == $offset){
$tzstring=$city['timezone_id'];
break 2;
}
endforeach;
endforeach;
endif;
//Issue with the timezone selected, set to 'UTC'
if( empty($tzstring) ):
$tzstring = 'UTC';
endif;
$timezone = new DateTimeZone($tzstring);
wp_cache_set( 'sh_blog_timezone', $timezone );
}
return $timezone;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.