Make WordPress Core


Ignore:
Timestamp:
05/06/2010 08:40:29 PM (15 years ago)
Author:
westi
Message:

Improve cross DST future post publishing behaviour to try and publish at the correct time if we have PHP5 timezone support available to help. Fixes #9285 props technosailor.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/formatting.php

    r14428 r14487  
    15541554 * Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the
    15551555 * value of the 'gmt_offset' option. Return format can be overridden using the
    1556  * $format parameter
     1556 * $format parameter. If PHP5 is supported, the function uses the DateTime and
     1557 * DateTimeZone objects to respect time zone differences in DST.
    15571558 *
    15581559 * @since 1.2.0
     
    15651566function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') {
    15661567    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);
    1567     $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
    1568     $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600);
     1568    $tz = get_option('timezone_string');
     1569    if( class_exists('DateTime') && $tz ) {
     1570        //PHP5
     1571        date_default_timezone_set( $tz );
     1572        $datetime = new DateTime( $string );
     1573        $datetime->setTimezone( new DateTimeZone('UTC') );
     1574        $offset = $datetime->getOffset();
     1575        $datetime->modify( '+' . $offset / 3600 . ' hours');
     1576        $string_gmt = gmdate($format, $datetime->format('U'));
     1577
     1578        date_default_timezone_set('UTC');
     1579    }
     1580    else {
     1581        //PHP4
     1582        $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
     1583        $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600);
     1584    }
    15691585    return $string_gmt;
    15701586}
Note: See TracChangeset for help on using the changeset viewer.