WordPress.org

Make WordPress Core

Opened 4 months ago

Last modified 44 hours ago

#44985 new enhancement

timezone_string should be valid when offset time zone mode is used

Reported by: Rarst Owned by:
Milestone: Awaiting Review Priority: normal
Severity: normal Version:
Component: Date/Time Keywords: needs-patch needs-unit-tests
Focuses: Cc:

Description

timezone_string time zone settings mode is backwards compatible, overriding gmt_offset mode with correct offset:

// Kiev
var_dump( get_option( 'gmt_offset' ), get_option( 'timezone_string' ) );
// float(3) string(11) "Europe/Kiev"

However the reverse isn't true, if settings are in offset mode the time zone string is empty and invalid:

// UTC+3
var_dump( get_option( 'gmt_offset' ), get_option( 'timezone_string' ) );
// string(1) "3" string(0) ""

In part this is because on older PHP versions there is no valid string that would correspond to an hours offset. But from PHP 5.5.10 it would work with timezone strings in +03:00 format just fine.

I think generating valid time zone strings in offset mode for new PHP versions is low hanging and makes things much more robust for downstream developers, making it harder for them to unknowingly screw up by relying on timezone_string alone.

We still need unified timezone retrieval in #24730, but that doesn't displace making timezone_string by itself more reliable.

Will work on a patch.

Change History (5)

This ticket was mentioned in Slack in #core-datetime by rarst. View the logs.


4 months ago

#2 follow-up: @JPry
4 months ago

@Rarst

I've worked on this recently in a plugin with the idea of fully allowing for any GMT offset or timezone string. If it helps, there are a few challenges that you'll find with this:

  1. Not all GMT offsets map to a timezone string
  2. Some (most?) GMT offsets map to more than one timezone string
  3. Beginning with PHP 7, the timezone strings that can be determined with the timezone_name_from_abbr() and timezone_abbreviations_list() functions has changed. You'll get different results for PHP < 7.0 and PHP >= 7.0.

Hopefully that helps save you a few headaches. 🙂

#3 in reply to: ↑ 2 ; follow-up: @Rarst
4 months ago

Replying to JPry:

We are not doing any mapping for this one. It is impossible to reliably inflate the data from less meaningful to more meaningful.

I am merely talking about making timezone_string return +NN:NN format offsets on newer PHP versions, which can use that as valid input, just as any geographical timezone string.

#4 in reply to: ↑ 3 @JPry
4 months ago

Replying to Rarst:

I am merely talking about making timezone_string return +NN:NN format offsets on newer PHP versions, which can use that as valid input, just as any geographical timezone string.

Ah, I misunderstood your description. Looking forward to seeing the enhancement.

#5 @pento
44 hours ago

  • Version trunk deleted
Note: See TracTickets for help on using tickets.