2

I'm trying to integrate PHP's date time and timezone features into my applications. What I have working now:

  • Every time is stored in the database as a Unix timestamp
  • Every time manipulation is all done using the timestamp
  • The only time it exists as a user-friendly format is right when it is displayed to the user

Yes, I know MySQL has an internal date time primitive object, but I don't fully understand how it works, and it just seems like a pain storing time in that format.

I also wrote my own very simple timezone library, consisting of literal (-12, 11) hour offsets with some friendly name assigned to each of the offsets. This is supposed to be changed later on to a full fledged timezone library, because I know the pains of creating a new timezone library (https://www.youtube.com/watch?v=-5wpm-gesOY). I have tried PHP's internal timezone library and everything seems to work perfectly.

There is a canonical list of timezones provided by PHP that can be accessed at DateTimeZone::listIdentifiers(). I sort of expect PHP itself will communicate with some outside time keeping database to change the timezones dynamically if any country changes its timezone details. My question is, does this actually happen? If it does happen, is there any guarantee that a specific timezone (say America/Guatemala) will still be recognized by PHP over time and not throw an error when timezones change?

157 239n
  • 349
  • 3
  • 15

2 Answers2

3

PHP time zones are based on the IANA TZ Database, and delivered via the timezonedb PECL package. The current version as of this posting is 2019.3, which aligns with IANA's current 2019c release. The timezonedb package has been maintained by Derick Rethans since 2005, and while there is no guarantee - there is no reason to believe that he or another PHP core contributor would not continue this maintenance indefinitely.

Note that each release of PHP includes the latest version of timezonedb at the time of release. So in most cases you do not need to update the package yourself. Just keep your PHP instance up to date with the latest releases and you will get the latest time zone data included.

The example of a future change to America/Guatamala would be handled upstream in the TZ database discussion list itself. That project is core critical Internet infrastructure governed by IETF BCP 175 / RFC 6557. There is virtually zero risk of this project going stale, as it is relied upon by literally every major operating system, programming platform, and countless libraries and independent projects.

As far as your custom library, glad you watched the Computerphile video, but you should also read the time timezone tag wiki here on Stack Overflow - especially pay attention to the section labeled "Time Zone != Offset". It is simply not sufficient to assign a friendly name to a fixed offset, hence why a database of time zones and their changes over time needs to be maintained.

To reiterate from the video, please do not use a custom time zone implementation - you are much better off taking a dependency on the work of others. In this case - use the built in time zone functionality from PHP.

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
2

As you can see here, PHP is pretty much alive and will be maintained over the next years. So if a change will be done, it will be communicated at the earliest point. In the last releases things have been marked es deprecated, before they 've been completely removed in a following version. So if a timezone constant will be removed, you will be informed in a future version with a deprecated notice. No componend will be removed without marking it at deprecated before removing. Doing so enables you to have much more time than you need to find a solution.

Marcel
  • 4,854
  • 1
  • 14
  • 24