[development] finding time zone name string
Chris Johnson
cxjohnson at gmail.com
Sat Dec 5 01:23:57 UTC 2009
I need to write some code which will produce the user's desired time
zone string (e.g. "Europe/Paris", "America/Chicago", etc.) using
Drupal 6.
Drupal 6 core only stores the user's time zone as minutes offset from
GMT, and likewise stores minutes offsets from GMT for the site default
time zone.
Using the popular contrib date module adds a timezone field to the
{users} table as well as another variable in the {variable} table with
the string I need, but of course, this module is not always present.
The most direct way to convert the minute offset to the standardized
string is using the PHP 5.1.3 and later function
timezone_name_from_abbr(). [despite its horribly wrong design :-) ]
My questions are:
1. Is there an existing function or functions in Drupal core, or more
likely the contrib date module, I should be calling to do this? I'm
thinking I will do an existence check for the date module, and code
differently if it is enabled and in use, for example.
2. What if neither the user nor the site has a time zone set? It
appears not setting a time zone for a site explicitly defaults to GMT,
since the default minute offset in the most of the variable_get()
calls is zero, hence GMT.
3. Should I bother to code a check for PHP version, and try to
implement a replacement for timezone_name_from_abbr() if PHP is less
than 5.1.3?
Thanks.
..chris
More information about the development
mailing list