Make WordPress Core

Opened 21 months ago

Last modified 18 months ago

#25768 new defect (bug)

date_i18n() is wrong for certain formats, escapes sequences and daylight saving time

Reported by: raubvogel Owned by:
Milestone: Future Release Priority: normal
Severity: major Version: 3.7.1
Component: Date/Time Keywords: has-patch needs-testing needs-unit-tests
Focuses: Cc:


date_i18n() returns wrong values in the following cases:

  • If time zone is not GMT date_i18n( 'c', time() ) does not return the correct difference to GMT part, e.g., 2013-10-30T14:00:00+00:00 instead of 2013-10-30T14:00:00+01:00.
  • The time zone offset is sometimes wrong:
    * Test is called in time zone Europe/Berlin at a date where daylight saving time is off!
    * (Daylight saving time in Europe/Berlin was switched off at 2013-10-27)
    // results 2013-10-29T22:15:03+01:00 while daylight saving time (Europe/Berlin) is off; result is correct
    echo(date_i18n('Y-m-d\TH:i:sP', 1383084903));
    // results 2013-10-11T19:37:20+01:00 while daylight saving time (Europe/Berlin) is on; result is wrong! should be +02:00!
    echo(date_i18n('Y-m-d\TH:i:sP', 1381520240));
  • date_i18n( 'D | \D | \\D | \\\D | \\\\D | \\\\\D | \\\\\\D' ) does not escaping properly.

The implementation of date_i18n() is not very well at all. Therefore it was completely rewritten solving the issues above. Performance should be better too. I added some tests too.

This ticket is a result of the discussion in ticket #20973. You can find a more detailed discussion there.

Attachments (3)

functions.php.patch (7.4 KB) - added by raubvogel 21 months ago.
tests.php (1.3 KB) - added by raubvogel 21 months ago.
core-fixes.php (5.0 KB) - added by raubvogel 21 months ago.
Fixes date_i18n() by filtering (no core modification).

Download all attachments as: .zip

Change History (6)

@raubvogel21 months ago

@raubvogel21 months ago

comment:1 @raubvogel21 months ago

A further issue with date_i18n() that is not fixed with my patch is: If get_option('timezone_string') is empty, date_i18n() ignores the time zone.

I believe, it’s not easy to fix this. One cannot simply find a time zone string by gmt offset (get_option('gmt_offset')) because it seems that there does not exist a time zone string for each possible offset (have a look timezone_name_from_abbr() too).

@raubvogel21 months ago

Fixes date_i18n() by filtering (no core modification).

comment:2 follow-up: @nacin19 months ago

  • Keywords needs-unit-tests added; dev-feedback removed
  • Milestone changed from Awaiting Review to Future Release

Hi raubvogel, thanks for the great effort here.

I'm order for this to proceed, I think we're going to need a significant amount of test coverage, including tests that pass for the existing code as well (to help guard against regressions). It would be best if we had PHPUnit tests for this: http://make.wordpress.org/core/handbook/automated-testing/.

comment:3 in reply to: ↑ 2 @raubvogel18 months ago

Replying to nacin: Thanks for Your attention! Indeed, we need much testing … At the moment I have not enough time to write automated tests :-( But in a few weeks maybe. However, it would be great if date_i18n() could be fixed.

Last edited 18 months ago by raubvogel (previous) (diff)
Note: See TracTickets for help on using tickets.