### Eclipse Workspace Patch 1.0
#P wordpress-trunk
|
|
|
|
| 6 | 6 | */ |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | | * Converts MySQL DATETIME field to user specified date format. |
| | 9 | * Format MySQL Datetime |
| | 10 | * |
| | 11 | * Converts MySQL DATETIME field to specified format. |
| | 12 | * |
| | 13 | * Format: |
| 10 | 14 | * |
| 11 | | * If $dateformatstring has 'G' value, then gmmktime() function will be used to |
| 12 | | * make the time. If $dateformatstring is set to 'U', then mktime() function |
| 13 | | * will be used to make the time. |
| 14 | | * |
| 15 | | * The $translate will only be used, if it is set to true and it is by default |
| 16 | | * and if the $wp_locale object has the month and weekday set. |
| 17 | | * |
| | 15 | * 'G' : strtotime ( date +0000 ) |
| | 16 | * 'U' : strtotime ( date ) |
| | 17 | * other : format according to php date() function |
| | 18 | * |
| | 19 | * @link http://www.php.net/strtotime |
| | 20 | * @link http://www.php.net/date |
| | 21 | * |
| | 22 | * Prevent locale formattings by setting the optional $translate parameter |
| | 23 | * to false. |
| | 24 | * |
| 18 | 25 | * @since 0.71 |
| 19 | | * |
| 20 | | * @param string $dateformatstring Either 'G', 'U', or php date format. |
| 21 | | * @param string $mysqlstring Time from mysql DATETIME field. |
| 22 | | * @param bool $translate Optional. Default is true. Will switch format to locale. |
| 23 | | * @return string Date formated by $dateformatstring or locale (if available). |
| | 26 | * @param string $dateformatstring Either 'G', 'U', or php date format. |
| | 27 | * @param string $mysqlstring Time from mysql DATETIME field. |
| | 28 | * @param bool $translate (optional) Format to locale, default is true. |
| | 29 | * @return string|false Formatted date, false on error. |
| 24 | 30 | */ |
| 25 | | function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) { |
| 26 | | global $wp_locale; |
| 27 | | $m = $mysqlstring; |
| 28 | | if ( empty( $m ) ) |
| | 31 | function mysql2date( $dateformatstring, $mysqlstring, $translate = true ) { |
| | 32 | if ( empty( $mysqlstring ) ) |
| 29 | 33 | return false; |
| 30 | 34 | |
| 31 | | if( 'G' == $dateformatstring ) { |
| 32 | | return strtotime( $m . ' +0000' ); |
| 33 | | } |
| | 35 | if( 'G' == $dateformatstring ) |
| | 36 | return strtotime( $mysqlstring . ' +0000' ); |
| 34 | 37 | |
| 35 | | $i = strtotime( $m ); |
| | 38 | $timestamp = strtotime( $mysqlstring ); |
| | 39 | |
| | 40 | if ( false === $timestamp ) |
| | 41 | return false; |
| 36 | 42 | |
| 37 | 43 | if( 'U' == $dateformatstring ) |
| 38 | | return $i; |
| | 44 | return $time; |
| 39 | 45 | |
| 40 | | if ( $translate) |
| 41 | | return date_i18n( $dateformatstring, $i ); |
| | 46 | if ( $translate ) |
| | 47 | return date_i18n( $dateformatstring, $timestamp ); |
| 42 | 48 | else |
| 43 | | return date( $dateformatstring, $i ); |
| | 49 | return date( $dateformatstring, $timestamp ); |
| 44 | 50 | } |
| 45 | 51 | |
| 46 | 52 | /** |