Make WordPress Core

Ticket #25002: mysql2date.diff

File mysql2date.diff, 3.5 KB (added by johnregan3, 12 years ago)

Patch to fix mysql2date issue.

  • wp-includes/functions.php

    diff --git wp-includes/functions.php wp-includes/functions.php
    index abac7b5..009d510 100644
    require( ABSPATH . WPINC . '/option.php' ); 
    1616 * If $translate is true then the given date and format string will
    1717 * be passed to date_i18n() for translation.
    1818 *
     19 * if $gmt is true, ensure defalt_timezone is set to GMT/UTC so that the
     20 * results will correctly reflect the UTC timezone.
     21 *
    1922 * @since 0.71
    2023 *
    2124 * @param string $format Format of the date to return.
    2225 * @param string $date Date string to convert.
    2326 * @param bool $translate Whether the return date should be translated. Default is true.
     27 * @param bool $gmt Return a date with UTC timezone.
    2428 * @return string|int Formatted date string, or Unix timestamp.
    2529 */
    26 function mysql2date( $format, $date, $translate = true ) {
     30function mysql2date( $format, $date, $translate = true, $gmt = false ) {
    2731        if ( empty( $date ) )
    2832                return false;
    2933
    30         if ( 'G' == $format )
    31                 return strtotime( $date . ' +0000' );
     34        //If GMT is requested, ensure the correct timezone is set.
     35        if ( $gmt ) {
     36                //Store the current timezone so it can be restored when we're finished.
     37                $previous_tz = date_default_timezone_get();
     38                date_default_timezone_set('UTC');
     39        }
     40
     41        /**
     42         * Store the new date in a variable.
     43         * We can't simply return it because we may have to restore the default timezone.
     44         *
     45         * Brackets used for clarity.
     46         */
     47        if ( 'G' == $format ) {
     48                $new_date = strtotime( $date . ' +0000' );
     49        } else {
     50                $i = strtotime( $date );
     51        }
     52
     53        if ( 'U' == $format ) {
     54                $new_date = $i;
     55        } else {
     56                //Add the "G != $format" statement so $new_date doesn't change if G really is the requested format.
     57                if ( ( 'G' != $format ) && ( $translate ) )
     58                        $new_date = date_i18n( $format, $i );
    3259
    33         $i = strtotime( $date );
     60                elseif ( 'G' != $format )
     61                        $new_date = date( $format, $i );
     62        }
    3463
    35         if ( 'U' == $format )
    36                 return $i;
     64        //If needed, restore the original timezone.
     65        if ( $gmt )
     66                date_default_timezone_set($previous_tz);
    3767
    38         if ( $translate )
    39                 return date_i18n( $format, $i );
    40         else
    41                 return date( $format, $i );
     68        return $new_date;
    4269}
    4370
    4471/**
  • wp-includes/general-template.php

    diff --git wp-includes/general-template.php wp-includes/general-template.php
    index faef3fa..29836ff 100644
    function get_the_time( $d = '', $post = null ) { 
    14981498 * @return string
    14991499 */
    15001500function get_post_time( $d = 'U', $gmt = false, $post = null, $translate = false ) { // returns timestamp
    1501         $post = get_post($post);
     1501        $post = get_post( $post );
    15021502
    15031503        if ( $gmt )
    15041504                $time = $post->post_date_gmt;
    15051505        else
    15061506                $time = $post->post_date;
    15071507
    1508         $time = mysql2date($d, $time, $translate);
    1509         return apply_filters('get_post_time', $time, $d, $gmt);
     1508        $time = mysql2date( $d, $time, $translate, $gmt );
     1509        return apply_filters( 'get_post_time', $time, $d, $gmt );
    15101510}
    15111511
    15121512/**
    function get_the_modified_time($d = '') { 
    15481548 * @return string Returns timestamp
    15491549 */
    15501550function get_post_modified_time( $d = 'U', $gmt = false, $post = null, $translate = false ) {
    1551         $post = get_post($post);
     1551        $post = get_post( $post );
    15521552
    15531553        if ( $gmt )
    15541554                $time = $post->post_modified_gmt;
    15551555        else
    15561556                $time = $post->post_modified;
    1557         $time = mysql2date($d, $time, $translate);
     1557        $time = mysql2date( $d, $time, $translate, $gmt );
    15581558
    1559         return apply_filters('get_post_modified_time', $time, $d, $gmt);
     1559        return apply_filters( 'get_post_modified_time', $time, $d, $gmt );
    15601560}
    15611561
    15621562/**