#25768 closed defect (bug) (fixed)
date_i18n() is wrong for certain formats, escapes sequences and daylight saving time
Reported by: | raubvogel | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 5.3 | Priority: | normal |
Severity: | normal | Version: | 3.7.1 |
Component: | Date/Time | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
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 (6)
Change History (18)
#2
follow-up:
↓ 3
@
11 years 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/.
#3
in reply to:
↑ 2
@
11 years 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.
#6
@
5 years ago
- Keywords has-unit-tests added; needs-testing needs-unit-tests dev-feedback removed
Added unit tests and refreshed patch (awesome work @remcotolsma !) with latest take on wp_timezone()
from #24730 and some extra handling for legacy use cases.
I imagine bulk of new implementation will get moved to an upcoming wp_date()
and date_i18n()
will be reduced to a legacy wrapper.
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 looktimezone_name_from_abbr()
too).