#34835 closed defect (bug) (fixed)
date_i18n() produces invalid output for numerical time zones
Reported by: | Rarst | Owned by: | flixos90 |
---|---|---|---|
Milestone: | 5.1 | Priority: | normal |
Severity: | normal | Version: | 3.1 |
Component: | Date/Time | Keywords: | has-patch |
Focuses: | Cc: |
Description
date_i18n()
only attempts to use get_option( 'timezone_string' )
for timezone information. This option is empty when numerical offset is saved as time zone in settings.
Code to reproduce:
// Kiev var_dump( get_option( 'timezone_string' ), get_option( 'gmt_offset' ) ); // 'Europe/Kiev', 2 var_dump( date_i18n( DATE_W3C, get_the_date( 'U' ) ) ); // 2015-12-03T12:22:22+02:00 correct // UTC+2 var_dump( get_option( 'timezone_string' ), get_option( 'gmt_offset' ) ); // '', '2' var_dump( date_i18n( DATE_W3C, get_the_date( 'U' ) ) ); // 2015-12-03T12:22:22+00:00 wrong
Attachments (4)
Change History (15)
#3
@
9 years ago
The code tests if the options is returned and skips the code that uses it if not set
#5
@
9 years ago
in the code, we test for if the option is empty/false and ship the use if it is
<?php $timezone_string = get_option( 'timezone_string' ); if ( $timezone_string ) {....
So it doesn't error but it doesn't return a date with the offset
the problem is that you can have a more than one time zone for more than one offset and the summer/winter time changes are per timezone no offset.
There is a mapping from time zone to offset but not from offset to time zone as don't know which time zone to set
Maybe the need to discourage the setting of the offset in the options and that way always have a timezone.
The default enter for get_option( 'timezone_string' ) is emtpy not even GMT
#6
@
9 years ago
While the reliable conversion from offset to timezone string isn't possible it should still use offset in date output. Otherwise it's just clearly broken value, off from real value by that many hours.
Obviously only using real timezones would be preferable, but I am not sure if it's desirable/possible to drop offsets from UI (backwards compat and everything).
@
7 years ago
Implements correct output for numeric offsets, without going through time zone object.
#8
@
6 years ago
- Milestone changed from Awaiting Review to 5.0
- Owner set to flixos90
- Status changed from new to reviewing
Related: #25768