473,788 Members | 2,893 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3861
>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_abbrev iations_list() or timezone_identi fiers_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.b urditt.orgwrote in message
news:13******** *****@corp.supe rnews.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_abbrev iations_list() or timezone_identi fiers_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 programmaticall y.

--
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.co m"David T. Ashley" <dt*@e3ft.comwr ites:
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.co m B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

Jun 14 '07 #6
In article <IP************ *************** ***@giganews.co m>,
"David T. Ashley" <dt*@e3ft.comwr ote:
"Gordon Burditt" <go****@hammy.b urditt.orgwrote in message
news:13******** *****@corp.supe rnews.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=Amer ica/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
1150
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 http://www.postgresql.org/docs/7.4/static/datetime-keywords.html it notes that time zone information is system dependent, (I interpret to mean that anything I find in /usr/share/zoneinfo on linux should be supported, can someone confirm that?) so how can an external app determine which timezones are...
1
1813
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. I posted a very similar item to python-dev, but they said to post it here. Tutor also said that if anything is to be considered as PEP worthy, it should be run through here first. So...here goes. Whenever I use enumerate, I am doing so...
1
2135
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 different timezones? For example: Date1 = 11:30, 4/18/06, NY Date2 = 16:30, 4/18/06, LN These times should be considered equal (since of course LN time is +5 NY
2
2458
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 saving time when applicable. If there are special cases where country + state isn't enough that's ok, a solution that's correct 95% of the time would be better than no solution at all. Thanks much,
21
2332
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 than in the current enumerate, tightens up code in many cases, and seems that it would break no
5
7805
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 find out the current time? .. Can I do this in web.config? If so how exactly?
7
4266
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 UTC dates sent by the browser are being adjusted for timezones by the server, but we do not want dates adjusted for timezones. For example, the user enters the date of a transaction as '25 May 2007'. That ends up as a javascript Date()...
3
3087
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 having to update a database constantly with the times and dates that certain countries set their clocks back or forward. Can this be done, or do I need to connect to a time server? Ideally, I need a time server that will return a JavaScript...
27
5323
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 there a smaller and more practical set? If not, some suggestions on how to handle the registration form effectively would help me a lot. thanks Sanjay
0
9656
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9498
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10173
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9967
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5536
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3674
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.