473,395 Members | 1,348 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to Enumerate and Calculate Timezones?

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've reviewed the zoneinfo stuff ... can't find the rules anywhere ... am
lost.

Thanks.
--
David T. Ashley (dt*@e3ft.com)
http://www.e3ft.com (Consulting Home Page)
http://www.dtashley.com (Personal Home Page)
http://gpl.e3ft.com (GPL Publications and Projects)
Jun 14 '07 #1
7 3835
>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?
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.
Jun 14 '07 #2
"Gordon Burditt" <go****@hammy.burditt.orgwrote in message
news:13*************@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)?

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().
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.

Jun 14 '07 #3
David T. Ashley wrote:
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.
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
Jun 14 '07 #4
David T. Ashley wrote:
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/
Jun 14 '07 #5
In <5a******************************@giganews.com"Dav id T. Ashley" <dt*@e3ft.comwrites:
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
go****@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

Jun 14 '07 #6
In article <IP******************************@giganews.com>,
"David T. Ashley" <dt*@e3ft.comwrote:
"Gordon Burditt" <go****@hammy.burditt.orgwrote in message
news:13*************@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).
Jun 14 '07 #7
John Gordon wrote:
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.]

HenPlus
http://tobyinkster.co.uk/blog/2007/06/14/henplus/
Jun 14 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Robert Treat | last post by:
I am trying to figure out if there is a way to determine the timezones supported in postgresql from within the database. If you look at...
1
by: smichr | last post by:
I see that there is a thread of a similar topic that was posted recently ( enumerate with a start index ) but thought I would start a new thread since what I am suggesting is a little different. ...
1
by: Flack | last post by:
Hey guys, I need to compare two times that the user selects. The user selects the hour, date, and timezone (which can be either NY, LN, or HK timezones). How can I compare two dates of...
2
by: Kevin | last post by:
Hi all, Does anyone know of a script or package that will allow me to calculate the localtime given a country code (and optional state/province for US/Canada)? It should factor in daylight...
21
by: James Stroud | last post by:
I think that it would be handy for enumerate to behave as such: def enumerate(itrbl, start=0, step=1): i = start for it in itrbl: yield (i, it) i += step This allows much more flexibility...
5
by: Alex | last post by:
Hi My website is hosted in the States (EST), but the website itself is targeted for UK users (GMT). How can I offset the time so that the server reports it as GMT when my ASP.NET app needs to...
7
by: =?Utf-8?B?U3R1?= | last post by:
I have a ASP.NET Ajax app (using client library) calling ASP.NET Ajax-enabled web services. We are making use of the javascript proxies generated by ASP.NET Ajax. The problem we have is that the...
3
by: Daz | last post by:
Hello everyone. I am creating a JavaScript project which will allow users to see what time it is in other countries. I am wondering if there's any way to have the server work this out, without...
27
by: Sanjay | last post by:
Hi All, I am using pytz.common_timezones to populate the timezone combo box of some user registration form. But as it has so many timezones (around 400), it is a bit confusing to the users. Is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.