Make WordPress Core

Ticket #20398: 20398.diff

File 20398.diff, 1.7 KB (added by scholesmafia, 12 years ago)

Fix to respect DST

  • formatting.

    old new  
    16691669/**
    16701670 * Converts a GMT date into the correct format for the blog.
    16711671 *
    1672  * Requires and returns in the Y-m-d H:i:s format. Simply adds the value of
    1673  * gmt_offset.Return format can be overridden using the $format parameter
     1672 * Requires and returns a date in the Y-m-d H:i:s format. Simply adds the value
     1673 * of the 'gmt_offset' option. Return format can be overridden using the $format
     1674 * parameter. The DateTime and DateTimeZone classes are used to respect time
     1675 * zone differences in DST.
    16741676 *
    16751677 * @since 1.2.0
    16761678 *
     
    16791681 * @return string Formatted date relative to the GMT offset.
    16801682 */
    16811683function get_date_from_gmt($string, $format = 'Y-m-d H:i:s') {
    1682     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);
    1683     $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
    1684     $string_localtime = gmdate($format, $string_time + get_option('gmt_offset')*3600);
     1684    $tz = get_option('timezone_string');
     1685    if ( $tz ) {
     1686        date_default_timezone_set('UTC');
     1687        $datetime = new DateTime( $string );
     1688        $datetime->setTimezone( new DateTimeZone($tz) );
     1689        $string_localtime = $datetime->format($format);
     1690    } else {
     1691        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);
     1692        $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
     1693        $string_localtime = gmdate($format, $string_time + get_option('gmt_offset')*3600);
     1694    }
    16851695    return $string_localtime;
    16861696}
    16871697