Stephen R
Stephen R

Reputation: 3907

How does PHP calculate historic time zones?

Time zones, offsets, and start end dates for DST (and DST itself existing at all) have changed over the years; and the differences worldwide make up a quite complex grid of zones and UTC offsets for different locations.

Does PHP do anything to calculate this for historic dates? If I put in a date in 1928 for a particular time zone, does PHP calculate what the offset rules were for that location, on that date, in 1928?

Upvotes: 2

Views: 238

Answers (2)

Matt Johnson-Pint
Matt Johnson-Pint

Reputation: 241525

Time zones, offsets, and start end dates for DST (and DST itself existing at all) have changed over the years; and the differences worldwide make up a quite complex grid of zones and UTC offsets for different locations.

Yes indeed. The history of time zones on Earth is an extremely complicated subject, as each time zone is delineated by an individual governmental entity. While pretty much everyone now agrees on using Coordinated Universal Time (UTC) as a basis for timekeeping, there is no such standardized agreement when it comes to local time. "Time zones" thus consist of:

  • A standard offset from UTC
  • Potentially another offset from UTC that applies at a different time of year, typically called "daylight saving time" or "summer time"
  • The schedule composing the exact dates and times that transition between standard time and daylight saving time
  • The cities or geographical borders unto which the time zone(s) apply
  • Changes to any of of the above, at any point in time
  • The history of how these rules have changed in the past
  • Some reasonable speculation about how these rules may remain or change for some period into the future

This subject domain is covered by the "TZ Database", also known as the IANA time zone database, Olson time zone database, zoneinfo, tzdata, tzdb, and a few other names. It is maintained openly by community via IANA, ruled by BDFL governance described in IETF BCP 175 / RFC 6557. It is widely implemented on many different platforms and programming languages.

Does PHP do anything to calculate this for historic dates?

PHP implements the TZ Database via the PECL "timezonedb" package. Each version of PHP is distributed with the latest version of timezonedb already included. It can also be updated independently, but it's often easier just to update to the latest PHP release.

You can read all about this in the PHP Date and Time documentation.

If I put in a date in 1928 for a particular time zone, does PHP calculate what the offset rules were for that location, on that date, in 1928?

That depends on which time zone you are asking about. In general, YES. However, the TZ Database only guarantees data from 1970 forward. However, there are many time zones where prior time zone data is available - when it is known.

The TZDB's policy on this is that they create time zone entries only for zones where the clocks have unique rules after 1970 - even if they differed before this. For zones that do meet this criteria, they backfill with information as it becomes known. There are often discussions on the TZ Mailing List about historical time zone information, and if a reasonable source is provided then often it is corrected in the TZ Database.

As an example the TZDB zone "America/Chicago" has data since 1883. However it also encompases the entire US Central Time zone, of which there were deviations before 1970 for other cities, that are not captured in the TZDB.

As a counterexample, the TZDB zone "Asia/Thimphu" representing Bhutan only has time zone data since 1947. If you ask for a date in 1928, it will use the Local Mean Time (LMT) entry instead. This can be confusing for some, as LMT is calculated based on latitude and longitude, rather than determined by government. In this case Asia/Thimphu has an LMT offset of UTC+05:56:36, whereas after 1947 it was known to have UTC+05:30 offset, until 1987 when it became UTC+06:00.

Upvotes: 1

jspit
jspit

Reputation: 7703

PHP has internally stored a list of all timezone offsets changes. The getTransitions () method returns a numerically indexed array containing an associative array with all transitions. You can view this list like this:

$timeZoneChicago = new DateTimeZone('America/Chicago');
$transArray = $timeZoneChicago->getTransitions();
echo "<pre>".var_export($transArray,true)."</pre>";

The entries for the future are pure speculation.

Upvotes: 2

Related Questions