WordPress.org

Make WordPress Core

Ticket #9285: 9285.diff

File 9285.diff, 2.1 KB (added by technosailor, 10 years ago)

Initial proof of concept. This code worked in unit testing outside of WP but fails to calculate DST correctly in WP. Releasing as a POC anyway and will continue to improve.

  • wp-includes/formatting.php

     
    15551555 *
    15561556 * Requires and returns a date in the Y-m-d H:i:s format. Simply subtracts the
    15571557 * value of the 'gmt_offset' option. Return format can be overridden using the
    1558  * $format parameter
     1558 * $format parameter. If PHP5 is supported, the function uses the DateTime and
     1559 * DateTimeZone objects to respect time zone differences in DST.
    15591560 *
    15601561 * @since 1.2.0
    15611562 *
     
    15661567 */
    15671568function get_gmt_from_date($string, $format = 'Y-m-d H:i:s') {
    15681569        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);
    1569         $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
    1570         $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600);
     1570        $tz = get_option('timezone_string');
     1571        if( class_exists('DateTime') && $tz )
     1572        {
     1573                //PHP5
     1574                date_default_timezone_set( $tz );
     1575                $datetime = new DateTime( $string );
     1576                $offset = $datetime->getOffset();
     1577                $datetime->setTimezone( new DateTimeZone('UTC') );
     1578                $datetime->modify( '+' . $offset / 3600 . ' hours');
     1579
     1580                $string_gmt = gmdate($format, $datetime->format('U'));
     1581        }
     1582        else
     1583        {
     1584                //PHP4
     1585                $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
     1586                $string_gmt = gmdate($format, $string_time - get_option('gmt_offset') * 3600);
     1587        }
    15711588        return $string_gmt;
    15721589}
    15731590
  • wp-includes/post.php

     
    41104110 */
    41114111function _future_post_hook( $deprecated = '', $post ) {
    41124112        wp_clear_scheduled_hook( 'publish_future_post', array( $post->ID ) );
    4113         wp_schedule_single_event( strtotime( $post->post_date_gmt. ' GMT' ), 'publish_future_post', array( $post->ID ) );
     4113        wp_schedule_single_event( get_gmt_from_date( $post->post_date ) . ' GMT', 'publish_future_post', array( $post->ID ) );
    41144114}
    41154115
    41164116/**