From 5e653b76ed1218ce9cec33f0786ec6e1ca9d6f79 Mon Sep 17 00:00:00 2001 From: duck_ Date: Tue, 21 Feb 2012 20:03:11 +0000 Subject: [PATCH] Overhaul mysql2date() documentation and parameter names. See #20056. git-svn-id: http://svn.automattic.com/wordpress/trunk@19974 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/functions.php | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/wp-includes/functions.php b/wp-includes/functions.php index 54093dd2f1..16de3cd1e0 100644 --- a/wp-includes/functions.php +++ b/wp-includes/functions.php @@ -8,35 +8,37 @@ require( ABSPATH . WPINC . '/option.php' ); /** - * Converts MySQL DATETIME field to user specified date format. + * Converts given date string into a different format. * - * The $translate parameter will only be used, if it is set to true and it is by - * default and if the $wp_locale object has the month and weekday set. + * $format should be either a PHP date format string, e.g. 'U' for a Unix + * timestamp, or 'G' for a Unix timestamp assuming that $date is GMT. + * + * If $translate is true then the given date and format string will + * be passed to date_i18n() for translation. * * @since 0.71 * - * @param string $dateformatstring Either 'G', 'U', or PHP date format. - * @param string $mysqlstring Time from mysql DATETIME field. - * @param bool $translate Optional. Default is true. Will switch format to locale. - * @return string Date formatted by $dateformatstring or locale (if available). + * @param string $format Format of the date to return. + * @param string $date Date string to convert. + * @param bool $translate Whether the return date should be translated. Default is true. + * @return string|int Formatted date string, or Unix timestamp. */ -function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) { - $m = $mysqlstring; - if ( empty( $m ) ) +function mysql2date( $format, $date, $translate = true ) { + if ( empty( $date ) ) return false; - if ( 'G' == $dateformatstring ) - return strtotime( $m . ' +0000' ); + if ( 'G' == $format ) + return strtotime( $date . ' +0000' ); - $i = strtotime( $m ); + $i = strtotime( $date ); - if ( 'U' == $dateformatstring ) + if ( 'U' == $format ) return $i; if ( $translate ) - return date_i18n( $dateformatstring, $i ); + return date_i18n( $format, $i ); else - return date( $dateformatstring, $i ); + return date( $format, $i ); } /**