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

WordPress Trac noreply at wordpress.org
Sun Oct 13 23:32:48 UTC 2013


#20973: date_i18n() produces invalid output for shorthand formats
--------------------------+------------------------------
 Reporter:  Rarst         |       Owner:
     Type:  defect (bug)  |      Status:  reopened
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Date/Time     |     Version:  3.4
 Severity:  normal        |  Resolution:
 Keywords:  has-patch     |
--------------------------+------------------------------

Comment (by raubvogel):

 I have completely rewritten {{{date_i18n()}}} now. I did tests by
 {{{
 #!php
 // day
 var_dump( 'day: ' . date_i18n( '\d:d | \D:D | \j:j | \l:l | \N:N | \S:S |
 \w:w | \z:z' ) );
 // week
 var_dump( 'week: ' . date_i18n( '\W:W' ) );
 // month
 var_dump( 'month: ' . date_i18n( '\F:F | \m:m | \M:M | \n:n | \t:t' ) );
 // year
 var_dump( 'year: ' . date_i18n( '\L:L | \o:o | \Y:Y | \y:y' ) );
 // time
 var_dump( 'time: ' . date_i18n( '\a:a | \A:A | \B:B | \g:g | \G:G | \h:h |
 \H:H | \i:i | \s:s | \u:u' ) );
 // timezone
 var_dump( 'timezone: ' . date_i18n( '\e:e | \I:I | \O:O | \P:P | \T:T |
 \Z:Z' ) );
 // full date/time
 var_dump( 'full date/time: ' . date_i18n( '\c:c | \r:r | \U:U' ) );

 // unix time
 var_dump( 'unix time: ' . time() );

 // escape test
 var_dump( 'escape test: ' . date_i18n( 'D | \D | \\D | \\\D | \\\\D |
 \\\\\D | \\\\\\D' ) );
 // escape test with PHP’s date()
 var_dump( 'escape test date(): ' . date ( 'D | \D | \\D | \\\D | \\\\D |
 \\\\\D | \\\\\\D' ) );
 }}}
 The outputs are (German localization)
 {{{
 string 'day: d:14 | D:Mo | j:14 | l:Montag | N:1 | S:th | w:1 | z:286'
 (length=61)
 string 'week: W:42' (length=10)
 string 'month: F:Oktober | m:10 | M:Okt | n:10 | t:31' (length=45)
 string 'year: L:0 | o:2013 | Y:2013 | y:13' (length=34)
 string 'time: a:am | A:AM | B:012 | g:1 | G:1 | h:01 | H:01 | i:17 | s:40
 | u:000000' (length=76)
 string 'timezone: e:Europe/Berlin | I:1 | O:+0200 | P:+02:00 | T:CEST |
 Z:7200' (length=70)
 string 'full date/time: c:2013-10-14T01:17:40+02:00 | r:Mo, 14 Okt 2013
 01:17:40 +0200 | U:1381706260' (length=93)
 string 'unix time: 1381706260' (length=21)
 string 'escape test: Mo | D | D | \Mo | \Mo | \D | \D' (length=45)
 string 'escape test date(): Sun | D | D | \Sun | \Sun | \D | \D'
 (length=55)
 }}}
 As you can see translation for 'S' (and 'e' too?) is still missing (needs
 extension of WP_Locale class). I think {{{date_i18n()}}} needs more
 testing. If you compare the patch with the old {{{date_i18n()}}}, you will
 see that there are no regular expressions any more. Some other
 improvements should boost performance too. By reviewing the the old
 {{{date_i18n()}}} I recognised that escaping of literals in the date
 format string was not handled properly (regex are wrong). Can some please
 check this too? What do you think about my patch?

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


More information about the wp-trac mailing list