Avoid an uncaught exception in get_gmt_from_date(). The return value is imperfect - date( $format, 0 ) - but better than a fatal error. props wonderboymusic. fixes #20942.
git-svn-id: http://core.svn.wordpress.org/trunk@22435 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
33fe750dce
commit
a73aa40cb5
|
@ -1892,10 +1892,16 @@ function _wp_iso_convert( $match ) {
|
||||||
*/
|
*/
|
||||||
function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') {
|
function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') {
|
||||||
preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);
|
preg_match('#([0-9]{1,4})-([0-9]{1,2})-([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $string, $matches);
|
||||||
|
if ( ! $matches )
|
||||||
|
return date( $format, 0 );
|
||||||
|
|
||||||
$tz = get_option('timezone_string');
|
$tz = get_option('timezone_string');
|
||||||
if ( $tz ) {
|
if ( $tz ) {
|
||||||
date_default_timezone_set( $tz );
|
date_default_timezone_set( $tz );
|
||||||
$datetime = new DateTime( $string );
|
$datetime = date_create( $string );
|
||||||
|
if ( ! $datetime )
|
||||||
|
return date( $format, 0 );
|
||||||
|
|
||||||
$datetime->setTimezone( new DateTimeZone('UTC') );
|
$datetime->setTimezone( new DateTimeZone('UTC') );
|
||||||
$offset = $datetime->getOffset();
|
$offset = $datetime->getOffset();
|
||||||
$datetime->modify( '+' . $offset / HOUR_IN_SECONDS . ' hours');
|
$datetime->modify( '+' . $offset / HOUR_IN_SECONDS . ' hours');
|
||||||
|
|
Loading…
Reference in New Issue