[wp-trac] [WordPress Trac] #20973: date_i18n() produces invalid output for shorthand formats

WordPress Trac wp-trac at lists.automattic.com
Fri Jun 15 13:39:50 UTC 2012


#20973: date_i18n() produces invalid output for shorthand formats
--------------------------+-----------------------------
 Reporter:  Rarst         |      Owner:
     Type:  defect (bug)  |     Status:  new
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  Date/Time     |    Version:  3.4
 Severity:  normal        |   Keywords:
--------------------------+-----------------------------
 date_i18n() function relies on parsing passed format to make adjustments.
 However shorthand formats are not handled and produce invalid output.

 Example:

 {{{
 var_dump( date_i18n( 'Y-m-d\TH:i:sP', time() ) ); //
 2012-06-15T13:34:03+03:00 << ok
 var_dump( date_i18n( DATE_W3C, time() ) ); // 2012-06-15T13:34:03+03:00 <<
 ok
 var_dump( date_i18n( 'c', time() ) ); // 2012-06-15T13:34:03+00:00 <<
 broken time zone!
 }}}


 Hook-level fix:

 {{{
 add_filter( 'date_i18n', 'fix_c_time_format', 10, 3 );

 function fix_c_time_format( $date, $format, $timestamp ) {

     if ( 'c' == $format )
         $date = date_i18n( DATE_W3C, $timestamp );

     return $date;
 }
 }}}

 See [http://wordpress.stackexchange.com/q/54700/847 Why time functions
 show invalid time zone when using 'c' time format?]

 Possibly related (can't say for sure from description) #13538

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/20973>
WordPress Trac <http://core.trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list