How do I enumerate all possible timezones from a PHP script or compiled 'C'
program?
Given a specific timezone, how do I get the time adjustment from UTC (which
can vary, based on daylight savings rules)?
I've reviewed the zoneinfo stuff ... can't find the rules anywhere ... am
lost.
Thanks.
--
David T. Ashley (d...@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
There are an infinite number of possible timezones. Most of them,
such as the one exactly 100 * pi hours west of GMT, are not used
by anyone (at least not anyone sane).
>Given a specific timezone, how do I get the time adjustment from UTC (which
>can vary, based on daylight savings rules)?
You can get a list of tzinfo-supplied timezones in PHP with
timezone_abbreviations_list() or timezone_identifiers_list(). For
C, you could try enumerating the files in the tzinfo directory.
You may get multiple names for the same time zone. For the offset,
look at timezone_offset_get(). However, it may be much simpler to
just use the time zone specified as the local time zone and use
functions such as localtime() or date() to compute human-readable
local times.
I'm locked into using PHP 4 for reasons that are too long to mention here.
The functions cited are available starting in PHP 5. Thanks, though.
In the /usr/share/zoneinfo directory (I'm assuming that is what you meant),
there are a bunch of files and directories, but they seem to have binary
contents, and I don't know the format. Enumerating the directory tree is no
problem, just that I don't know what is what in terms of relationship to
UTC.
For example:
[dashley@pamc zoneinfo]$ ls
Africa Chile Factory Iceland Mexico posix Universal
America CST6CDT GB Indian Mideast posixrules US
Antarctica Cuba GB-Eire Iran MST PRC UTC
Arctic EET GMT iso3166.tab MST7MDT PST8PDT WET
Asia Egypt GMT0 Israel Navajo right W-SU
Atlantic Eire GMT-0 Jamaica NZ ROC zone.tab
Australia EST GMT+0 Japan NZ-CHAT ROK Zulu
Brazil EST5EDT Greenwich Kwajalein Pacific Singapore
Canada Etc Hongkong Libya Poland Turkey
CET Europe HST MET Portugal UCT
[dashley@pamc zoneinfo]$ cd Brazil/
[dashley@pamc Brazil]$ ls
Acre DeNoronha East West
[dashley@pamc Brazil]$ cat Acre
Šļfļý\ĀđņPPšÞ@Ú8ĘPÚėPÜýÐÜđu@Ýû1PÞ@ßÝķPāTO@ôõz@öĀPũ:ĀøQHPøĮá@ú
îÐúĐĀûė"PüĀÉŠPxóĀ QÐ 3ëĀ!
P"
äĀĸĸĀpĸĸĮĀĸĸđ° LMTACSTACT[dashley@pamc Brazil]$
Thanks, Dave.
Why would you want to know the format? There are functions for rendering
the time in various different timezones. (Specifically, you can set the
timezone with tzset() and you get the local time with localtime().)
If that is not sufficient for your application, can you be more specific
about what you're trying to achieve?
- Logan
> In the /usr/share/zoneinfo directory (I'm assuming that is what you meant),
> there are a bunch of files and directories, but they seem to have binary
> contents, and I don't know the format.
See "man zdump".
Examples:
[ti@ophelia (pts/5) ~]$ /usr/sbin/zdump "UTC"
UTC Thu Jun 14 12:11:43 2007 UTC
[ti@ophelia (pts/5) ~]$ /usr/sbin/zdump "Australia/Yancowinna"
Australia/Yancowinna Thu Jun 14 21:41:47 2007 CST
[ti@ophelia (pts/5) ~]$ /usr/sbin/zdump "Australia/NSW"
Australia/NSW Thu Jun 14 22:11:50 2007 EST
(For those who are interested, the eastern mainland states of Australia,
are divided into counties, though these divisions are rarely used.
Yancowinna is a county in the extreme west of New South Wales, notable for
two facts: it contains Broken Hill, an old opal mining town which was the
filming location for most of "Priscilla, Queen of the Desert"; and it uses
a different timezone from the rest of the state.)
Anyway, zdump is able to tell you the current time in any given timezone.
By comparing that with the time in UTC, you ought to be able to find its
UTC offset programmatically.
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 110 days, 19:52.]
URLs in demiblog
http://tobyinkster.co.uk/blog/2007/05/31/demiblog-urls/
> How do I enumerate all possible timezones from a PHP script or compiled 'C'
> program?
Most websites I've seen just give the user 24 possible choices, for the
24 commonly-used time zones.
> Given a specific timezone, how do I get the time adjustment from UTC (which
> can vary, based on daylight savings rules)?
Most systems should have a localtime() function which calculates that for
you automatically.
--
John Gordon A is for Amy, who fell down the stairs
gor...@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
> "Gordon Burditt" <gor...@hammy.burditt.org> wrote in message
> news:1371gmc...@corp.supernews.com...
> >>In a web database (PHP), per user, I'd like to allow each user to
> >>specify their timezone (this would change how times are adjusted for
> >>display for that user).
> >>
> >>How do I enumerate all possible timezones from a PHP script or
> >>compiled 'C' program?
> >
> >>Given a specific timezone, how do I get the time adjustment from UTC
> >>(which can vary, based on daylight savings rules)?
[...]
> I'm locked into using PHP 4 for reasons that are too long to mention here.
> The functions cited are available starting in PHP 5. Thanks, though.
>
> In the /usr/share/zoneinfo directory (I'm assuming that is what you meant),
> there are a bunch of files and directories, but they seem to have binary
> contents, and I don't know the format. Enumerating the directory tree is no
> problem, just that I don't know what is what in terms of relationship to
> UTC.
You shouldn't need to know the adjustment, just combine the directory &
file names to construct a timezone name, and use it to set the TZ
environment variable, as per this example from
<http://www.boutell.com/newfaq/creating/datestamp.html>:
<?php
putenv('TZ=America/New_York');
echo date("Y-m-d h:i:sa", time());
?>
By default, the date function of PHP also outputs the date and time
for the web server's time zone. But the putenv function changes this
by setting the effective time zone to the city we want. Linux users
can find a list of valid time zone names in the /usr/share/zoneinfo
directory (there are subdirectories for continents and so forth).
> Most websites I've seen just give the user 24 possible choices, for the
> 24 commonly-used time zones.
Well, that's just silly. Until about 50 years ago, Bombay was UTC+4:51;
until about 20 years ago, Nepal was UTC+5:40; Ireland was UTC-0:25;
Netherlands were UTC+0:20; Liberia used to be UTC-0:44.
Even now, there are plenty of places that use fractional time zones -- they
are n:15, n:30 and n:45 offset from UTC. And it's not just crappy little
islands that use them. India, population > 1 billion, uses UTC+5:30.
Certain Canadian and Australian states use fractional timezones
Whatsmore UTC-12 and UTC+12 both exist -- they are are not the same as each
other. There's UTC+13 and UTC+14 too.
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 111 days, 2:02.]