WordPress.org

Make WordPress Core

Changeset 19974


Ignore:
Timestamp:
02/21/2012 08:03:11 PM (6 years ago)
Author:
duck_
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/functions.php

    r19973 r19974  
    99
    1010/**
    11  * Converts MySQL DATETIME field to user specified date format.
    12  *
    13  * The $translate parameter will only be used, if it is set to true and it is by
    14  * default and if the $wp_locale object has the month and weekday set.
     11 * Converts given date string into a different format.
     12 *
     13 * $format should be either a PHP date format string, e.g. 'U' for a Unix
     14 * timestamp, or 'G' for a Unix timestamp assuming that $date is GMT.
     15 *
     16 * If $translate is true then the given date and format string will
     17 * be passed to date_i18n() for translation.
    1518 *
    1619 * @since 0.71
    1720 *
    18  * @param string $dateformatstring Either 'G', 'U', or PHP date format.
    19  * @param string $mysqlstring Time from mysql DATETIME field.
    20  * @param bool $translate Optional. Default is true. Will switch format to locale.
    21  * @return string Date formatted by $dateformatstring or locale (if available).
    22  */
    23 function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) {
    24     $m = $mysqlstring;
    25     if ( empty( $m ) )
     21 * @param string $format Format of the date to return.
     22 * @param string $date Date string to convert.
     23 * @param bool $translate Whether the return date should be translated. Default is true.
     24 * @return string|int Formatted date string, or Unix timestamp.
     25 */
     26function mysql2date( $format, $date, $translate = true ) {
     27    if ( empty( $date ) )
    2628        return false;
    2729
    28     if ( 'G' == $dateformatstring )
    29         return strtotime( $m . ' +0000' );
    30 
    31     $i = strtotime( $m );
    32 
    33     if ( 'U' == $dateformatstring )
     30    if ( 'G' == $format )
     31        return strtotime( $date . ' +0000' );
     32
     33    $i = strtotime( $date );
     34
     35    if ( 'U' == $format )
    3436        return $i;
    3537
    3638    if ( $translate )
    37         return date_i18n( $dateformatstring, $i );
     39        return date_i18n( $format, $i );
    3840    else
    39         return date( $dateformatstring, $i );
     41        return date( $format, $i );
    4042}
    4143
Note: See TracChangeset for help on using the changeset viewer.