Overhaul mysql2date() documentation and parameter names. See #20056.

git-svn-id: http://svn.automattic.com/wordpress/trunk@19974 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
duck_ 2012-02-21 20:03:11 +00:00
parent ebc8ed6395
commit 5e653b76ed

View File

@ -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 );
}
/**