WordPress.org

Make WordPress Core

Ticket #9313: MYSQL_DATETIME format string constant.diff

File MYSQL_DATETIME format string constant.diff, 15.8 KB (added by simonwheatley, 9 years ago)

A patch to change all dateformat strings like "Y-m-d H:i:s" to refer to a constant instead

  • Users/simon/Projects/WordPress/site/wordpress/wp-includes/feed-rss2.php

     
    3636                <title><?php the_title_rss() ?></title>
    3737                <link><?php the_permalink_rss() ?></link>
    3838                <comments><?php comments_link(); ?></comments>
    39                 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
     39                <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time(MYSQL_DATETIME, true), false); ?></pubDate>
    4040                <dc:creator><?php the_author() ?></dc:creator>
    4141                <?php the_category_rss() ?>
    4242
  • Users/simon/Projects/WordPress/site/wordpress/wp-includes/js/tinymce/plugins/spellchecker/classes/utils/Logger.php

     
    216216                $logFile = str_replace('{level}', strtolower($levelName), $logFile);
    217217
    218218                $text = $this->_format;
    219                 $text = str_replace('{time}', date("Y-m-d H:i:s"), $text);
     219                $text = str_replace('{time}', date(MYSQL_DATETIME), $text);
    220220                $text = str_replace('{level}', strtolower($levelName), $text);
    221221                $text = str_replace('{message}', $message, $text);
    222222                $message = $text . "\r\n";
  • Users/simon/Projects/WordPress/site/wordpress/wp-includes/functions.php

     
    9191function current_time( $type, $gmt = 0 ) {
    9292        switch ( $type ) {
    9393                case 'mysql':
    94                         return ( $gmt ) ? gmdate( 'Y-m-d H:i:s' ) : gmdate( 'Y-m-d H:i:s', ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
     94                        return ( $gmt ) ? gmdate( MYSQL_DATETIME ) : gmdate( MYSQL_DATETIME, ( time() + ( get_option( 'gmt_offset' ) * 3600 ) ) );
    9595                        break;
    9696                case 'timestamp':
    9797                        return ( $gmt ) ? time() : time() + ( get_option( 'gmt_offset' ) * 3600 );
  • Users/simon/Projects/WordPress/site/wordpress/wp-includes/registration.php

     
    8585 * 'description' - A string containing content about the user.
    8686 * 'rich_editing' - A string for whether to enable the rich editor or not. False
    8787 *              if not empty.
    88  * 'user_registered' - The date the user registered. Format is 'Y-m-d H:i:s'.
     88 * 'user_registered' - The date the user registered. Format is MYSQL_DATETIME.
    8989 * 'role' - A string used to set the user's role.
    9090 * 'jabber' - User's Jabber account.
    9191 * 'aim' - User's AOL IM account.
     
    174174                $yim = '';
    175175
    176176        if ( empty($user_registered) )
    177                 $user_registered = gmdate('Y-m-d H:i:s');
     177                $user_registered = gmdate(MYSQL_DATETIME);
    178178
    179179        $data = compact( 'user_pass', 'user_email', 'user_url', 'user_nicename', 'display_name', 'user_registered' );
    180180        $data = stripslashes_deep( $data );
  • Users/simon/Projects/WordPress/site/wordpress/wp-includes/feed-atom-comments.php

     
    6565                </author>
    6666
    6767                <id><?php comment_guid(); ?></id>
    68                 <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_comment_time('Y-m-d H:i:s', true), false); ?></updated>
    69                 <published><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_comment_time('Y-m-d H:i:s', true), false); ?></published>
     68                <updated><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_comment_time(MYSQL_DATETIME, true), false); ?></updated>
     69                <published><?php echo mysql2date('Y-m-d\TH:i:s\Z', get_comment_time(MYSQL_DATETIME, true), false); ?></published>
    7070<?php if ( post_password_required($comment_post) ) : ?>
    7171                <content type="html" xml:base="<?php comment_link(); ?>"><![CDATA[<?php echo get_the_password_form(); ?>]]></content>
    7272<?php else : // post pass ?>
  • Users/simon/Projects/WordPress/site/wordpress/wp-includes/formatting.php

     
    13251325function get_gmt_from_date($string) {
    13261326        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);
    13271327        $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
    1328         $string_gmt = gmdate('Y-m-d H:i:s', $string_time - get_option('gmt_offset') * 3600);
     1328        $string_gmt = gmdate(MYSQL_DATETIME, $string_time - get_option('gmt_offset') * 3600);
    13291329        return $string_gmt;
    13301330}
    13311331
     
    13431343function get_date_from_gmt($string) {
    13441344        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);
    13451345        $string_time = gmmktime($matches[4], $matches[5], $matches[6], $matches[2], $matches[3], $matches[1]);
    1346         $string_localtime = gmdate('Y-m-d H:i:s', $string_time + get_option('gmt_offset')*3600);
     1346        $string_localtime = gmdate(MYSQL_DATETIME, $string_time + get_option('gmt_offset')*3600);
    13471347        return $string_localtime;
    13481348}
    13491349
     
    13931393                $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);
    13941394                $timestamp -= $offset;
    13951395
    1396                 return gmdate('Y-m-d H:i:s', $timestamp);
     1396                return gmdate(MYSQL_DATETIME, $timestamp);
    13971397
    13981398        } else if ($timezone == 'user') {
    13991399                return preg_replace('#([0-9]{4})([0-9]{2})([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(Z|[\+|\-][0-9]{2,4}){0,1}#', '$1-$2-$3 $4:$5:$6', $date_string);
  • Users/simon/Projects/WordPress/site/wordpress/wp-includes/feed-rss2-comments.php

     
    4949                ?></title>
    5050                <link><?php comment_link() ?></link>
    5151                <dc:creator><?php echo get_comment_author_rss() ?></dc:creator>
    52                 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time('Y-m-d H:i:s', true), false); ?></pubDate>
     52                <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_comment_time(MYSQL_DATETIME, true), false); ?></pubDate>
    5353                <guid isPermaLink="false"><?php comment_guid() ?></guid>
    5454<?php if ( post_password_required($comment_post) ) : ?>
    5555                <description><?php echo ent2ncr(__('Protected Comments: Please enter your password to view comments.')); ?></description>
  • Users/simon/Projects/WordPress/site/wordpress/wp-app.php

     
    6060        global $app_logging;
    6161        if ($app_logging) {
    6262                $fp = fopen( 'wp-app.log', 'a+');
    63                 $date = gmdate( 'Y-m-d H:i:s' );
     63                $date = gmdate( MYSQL_DATETIME );
    6464                fwrite($fp, "\n\n$date - $label\n$msg\n");
    6565                fclose($fp);
    6666        }
     
    16071607                if(!$pubtime) {
    16081608                        return array(current_time('mysql'),current_time('mysql',1));
    16091609                } else {
    1610                         return array(date("Y-m-d H:i:s", $pubtime), gmdate("Y-m-d H:i:s", $pubtime));
     1610                        return array(date(MYSQL_DATETIME, $pubtime), gmdate(MYSQL_DATETIME, $pubtime));
    16111611                }
    16121612        }
    16131613
  • Users/simon/Projects/WordPress/site/wordpress/wp-mail.php

     
    127127                                $time_zn = intval($date_arr[4]) * 36;
    128128                                $ddate_U = gmmktime($ddate_H, $ddate_i, $ddate_s, $ddate_m, $ddate_d, $ddate_Y);
    129129                                $ddate_U = $ddate_U - $time_zn;
    130                                 $post_date = gmdate('Y-m-d H:i:s', $ddate_U + $time_difference);
    131                                 $post_date_gmt = gmdate('Y-m-d H:i:s', $ddate_U);
     130                                $post_date = gmdate(MYSQL_DATETIME, $ddate_U + $time_difference);
     131                                $post_date_gmt = gmdate(MYSQL_DATETIME, $ddate_U);
    132132                        }
    133133                }
    134134        }
  • Users/simon/Projects/WordPress/site/wordpress/wp-settings.php

     
    456456if ( !defined( 'AUTOSAVE_INTERVAL' ) )
    457457        define( 'AUTOSAVE_INTERVAL', 60 );
    458458
     459/**
     460 * A constant to give a date format string for anywhere we need a MySQL-like
     461 * datetime format.
     462 * @since ???
     463 */
     464define( 'MYSQL_DATETIME', 'Y-m-d H:i:s' );
    459465
    460466require (ABSPATH . WPINC . '/vars.php');
    461467
  • Users/simon/Projects/WordPress/site/wordpress/wp-admin/includes/upgrade.php

     
    127127        $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (7, 2)" );
    128128
    129129        // First post
    130         $now = date('Y-m-d H:i:s');
    131         $now_gmt = gmdate('Y-m-d H:i:s');
     130        $now = date(MYSQL_DATETIME);
     131        $now_gmt = gmdate(MYSQL_DATETIME);
    132132        $first_post_guid = get_option('home') . '/?p=1';
    133133        $wpdb->query("INSERT INTO $wpdb->posts (post_author, post_date, post_date_gmt, post_content, post_excerpt, post_title, post_category, post_name, post_modified, post_modified_gmt, guid, comment_count, to_ping, pinged, post_content_filtered) VALUES ($user_id, '$now', '$now_gmt', '".$wpdb->escape(__('Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!'))."', '', '".$wpdb->escape(__('Hello world!'))."', '0', '".$wpdb->escape(_c('hello-world|Default post slug'))."', '$now', '$now_gmt', '$first_post_guid', '1', '', '', '')");
    134134        $wpdb->query( "INSERT INTO $wpdb->term_relationships (`object_id`, `term_taxonomy_id`) VALUES (1, 1)" );
  • Users/simon/Projects/WordPress/site/wordpress/wp-admin/includes/export.php

     
    272272<item>
    273273<title><?php echo apply_filters('the_title_rss', $post->post_title); ?></title>
    274274<link><?php the_permalink_rss() ?></link>
    275 <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
     275<pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time(MYSQL_DATETIME, true), false); ?></pubDate>
    276276<dc:creator><?php echo wxr_cdata(get_the_author()); ?></dc:creator>
    277277<?php wxr_post_taxonomy() ?>
    278278
  • Users/simon/Projects/WordPress/site/wordpress/wp-admin/import/livejournal.php

     
    6363
    6464                        preg_match('|<eventtime>(.*?)</eventtime>|is', $post, $post_date);
    6565                        $post_date = strtotime($post_date[1]);
    66                         $post_date = date('Y-m-d H:i:s', $post_date);
     66                        $post_date = date(MYSQL_DATETIME, $post_date);
    6767
    6868                        preg_match('|<event>(.*?)</event>|is', $post, $post_content);
    6969                        $post_content = str_replace(array ('<![CDATA[', ']]>'), '', trim($post_content[1]));
     
    113113
    114114                                        preg_match('|<eventtime>(.*?)</eventtime>|is', $comment, $comment_date);
    115115                                        $comment_date = trim($comment_date[1]);
    116                                         $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
     116                                        $comment_date = date(MYSQL_DATETIME, strtotime($comment_date));
    117117
    118118                                        preg_match('|<name>(.*?)</name>|is', $comment, $comment_author);
    119119                                        $comment_author = $wpdb->escape(trim($comment_author[1]));
  • Users/simon/Projects/WordPress/site/wordpress/wp-admin/import/blogware.php

     
    6767
    6868                        preg_match('|<pubDate>(.*?)</pubDate>|is', $post, $post_date);
    6969                        $post_date = strtotime($post_date[1]);
    70                         $post_date = gmdate('Y-m-d H:i:s', $post_date);
     70                        $post_date = gmdate(MYSQL_DATETIME, $post_date);
    7171
    7272                        preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
    7373                        $categories = $categories[1];
     
    136136
    137137                                        preg_match('|<pubDate>(.*?)</pubDate>|is', $comment, $comment_date);
    138138                                        $comment_date = trim($comment_date[1]);
    139                                         $comment_date = date('Y-m-d H:i:s', strtotime($comment_date));
     139                                        $comment_date = date(MYSQL_DATETIME, strtotime($comment_date));
    140140
    141141                                        preg_match('|<author>(.*?)</author>|is', $comment, $comment_author);
    142142                                        $comment_author = $wpdb->escape(trim($comment_author[1]));
  • Users/simon/Projects/WordPress/site/wordpress/wp-admin/import/rss.php

     
    7070                                $post_date_gmt = strtotime($post_date_gmt);
    7171                        }
    7272
    73                         $post_date_gmt = gmdate('Y-m-d H:i:s', $post_date_gmt);
     73                        $post_date_gmt = gmdate(MYSQL_DATETIME, $post_date_gmt);
    7474                        $post_date = get_date_from_gmt( $post_date_gmt );
    7575
    7676                        preg_match_all('|<category>(.*?)</category>|is', $post, $categories);
  • Users/simon/Projects/WordPress/site/wordpress/wp-admin/import/mt.php

     
    403403                        } else if ( 0 === strpos($line, "DATE:") ) {
    404404                                $date = trim( substr($line, strlen("DATE:")) );
    405405                                $date = strtotime($date);
    406                                 $date = date('Y-m-d H:i:s', $date);
     406                                $date = date(MYSQL_DATETIME, $date);
    407407                                $date_gmt = get_gmt_from_date($date);
    408408                                if ( '' == $context ) {
    409409                                        $post->post_modified = $date;
  • Users/simon/Projects/WordPress/site/wordpress/wp-admin/import/blogger.php

     
    517517                $timestamp = gmmktime($date_bits[4], $date_bits[5], $date_bits[6], $date_bits[2], $date_bits[3], $date_bits[1]);
    518518                $timestamp -= $offset; // Convert from Blogger local time to GMT
    519519                $timestamp += get_option('gmt_offset') * 3600; // Convert from GMT to WP local time
    520                 return gmdate('Y-m-d H:i:s', $timestamp);
     520                return gmdate(MYSQL_DATETIME, $timestamp);
    521521        }
    522522
    523523        function no_apos( $string ) {