Proposed Solutions For Core

We're likely to spend a fair amount of time discussing different solutions. One is the code now used in the Event module (event_timezones.inc), which covers some of the issues here, and is much more correct a solution than what I've seen done till now. But the best is the enemy of the good :-) So I propose a solution based upon Arthur Olson's data files, which you can find at ftp://elsie.nci.nih.gov/pub/. It works like this:

  • Use a program that's been posted to Olson's mailing list by John Cowan, which dumps the TZif binary files on your system (or that you can compile from Olson's source distribution) into an easy-to-parse text form.
  • Use a script to call Cowan's program for all of the zones you want to support, parse the data, and generate SQL tables that contain the data.
  • Load only the zones you need at run time, and cache the data in a form that makes it easy to find the right transition times by binary search.
  • Wrap the PHP gmt time functions so that you can specify the POSIX zone name, and look up the cached zone table. Store all times as Unix time stamps, and hide any games that you play with offsets inside of the wrappers. Developers only need to specify the right time zone to use, and don't need to play with offsets from UTC anymore. Users get their dates properly rendered for their notion of local time, and stop bothering the developers. Lions lie down with lambs, etc. etc.

I've already implemented most of this. While the solution covers more than 500 zones, the code is extremely small.

You can see my code up on my personal site, at http://torenware.com/bazaar/trunk/timezones/php_datetime/. The contents of the drupal/ directory contain the include file with the code, and a simple module to test it with. Just load the sql tables and the sql data, and you can try out the functions.

Enjoy.