473,388 Members | 906 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,388 software developers and data experts.

Question about timezones

Hi,

The operating system I run (Linux) comes with many, many timezone files
for many different places in the world. For example:

$ TZ='Australia/Sydney' date
Fri Oct 8 06:15:31 EST 2004
$ TZ='Europe/Amsterdam' date
Thu Oct 7 22:15:38 CEST 2004
$ TZ='Africa/Bissau' date
Thu Oct 7 20:18:44 GMT 2004
$ TZ='America/Phoenix' date
Thu Oct 7 13:19:33 MST 2004

Is there any way I can use these from within postgresql? Those files
contains details about daylight saving changes and other useful details
like that, which a simple PST or EST won't cover. Or should I simply do
all my date/time conversion in my application?

Any ideas?
--
Martijn van Oosterhout <kl*****@svana.org> http://svana.org/kleptog/
Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
tool for doing 5% of the work and then sitting around waiting for someone
else to do the other 95% so you can sue them.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFBZaV9Y5Twig3Ge+YRApJeAKCdssMcZvYf/tI+kz4dGHfhSUPQ4QCgybof
8IKubXWTwLzezo3xCP10FrQ=
=gy0g
-----END PGP SIGNATURE-----

Nov 23 '05 #1
4 2000
* Martijn van Oosterhout <kl*****@svana.org> [2004-10-07 22:22:24 +0200]:
Is there any way I can use these from within postgresql? Those files
contains details about daylight saving changes and other useful
details like that, which a simple PST or EST won't cover. Or should
I simply do all my date/time conversion in my application?


The time zone support seems pretty exhaustive. Check out section B-r
in the document below.

http://www.postgresql.org/docs/7.4/s...-keywords.html

HTH,

--
Steven Klassen - Lead Programmer
Command Prompt, Inc. - http://www.commandprompt.com/
PostgreSQL Replication & Support Services, (503) 667-4564

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Nov 23 '05 #2
On Thu, Oct 07, 2004 at 01:43:49PM -0700, Steven Klassen wrote:
* Martijn van Oosterhout <kl*****@svana.org> [2004-10-07 22:22:24 +0200]:
Is there any way I can use these from within postgresql? Those files
contains details about daylight saving changes and other useful
details like that, which a simple PST or EST won't cover. Or should
I simply do all my date/time conversion in my application?
The time zone support seems pretty exhaustive. Check out section B-r
in the document below.

http://www.postgresql.org/docs/7.4/s...-keywords.html


But it doesn't seem to work to actually work out times across the
world w.r.t. daylight savings.

For example, this script works out, given a time in one timezone, what
it was in another timezone:

$ sh /tmp/translatetz '2004-12-01 12:0:0' Australia/Sydney Europe/Amsterdam
Wed Dec 1 02:00:00 2004
$ sh /tmp/translatetz '2004-08-01 12:0:0' Australia/Sydney Europe/Amsterdam
Sun Aug 1 04:00:00 2004

But Brisbane doesn't have summer time, so:

$ sh /tmp/translatetz '2004-12-01 12:0:0' Australia/Brisbane Europe/Amsterdam
Wed Dec 1 03:00:00 2004

The closest I've been able to get is:

kleptog=# select timezone('MEWT',timezone('AESST','2004-12-01 12:0:0'::timestamp));
timezone
---------------------
2004-12-01 02:00:00
(1 row)

kleptog=# select timezone('MEST',timezone('AEST','2004-08-01 12:0:0'::timestamp));
timezone
---------------------
2004-08-01 04:00:00
(1 row)

In other words, if I work out myself the appropriate timezones then it
can do it. In that case I may just as well do it all myself. Mind you,
this is 7.3, would a more recent version handle this differently?

--- translatetz ---
#!/bin/sh
X=`TZ=$2 date --date="$1" +%s`
TZ=$3 perl -e 'print scalar(localtime(shift))' $X
--- snip ---
--
Martijn van Oosterhout <kl*****@svana.org> http://svana.org/kleptog/ Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
tool for doing 5% of the work and then sitting around waiting for someone
else to do the other 95% so you can sue them.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFBZk5ZY5Twig3Ge+YRAmntAJ9TNc3XqI59fjoL+V+Z68/Ge1wSDgCcC86c
qF1Kzmm/OTpsPmVDEaENEL8=
=BPj9
-----END PGP SIGNATURE-----

Nov 23 '05 #3
Martijn van Oosterhout <kl*****@svana.org> writes:
But it doesn't seem to work to actually work out times across the
world w.r.t. daylight savings.
...
For example, this script works out, given a time in one timezone, what
it was in another timezone:


What we need for that is the ability for AT TIME ZONE to specify a
DST-aware zone name. Right now it can only take DST-ignorant zone
names. So you can do
('2004-12-01 12:0:0' AT TIME ZONE 'AESST') AT TIME ZONE 'MEWT'
but not
('2004-12-01 12:0:0' AT TIME ZONE 'Australia/Sydney') AT TIME ZONE 'Europe/Amsterdam'
which of course is what you want.

The infrastructure needed for this is finally present in 8.0, ie we have
the timezone data available, but actually teaching AT TIME ZONE about it
didn't get done in time. Likely it will appear in 8.1 (especially if
you step up and do the work ;-)).

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Nov 23 '05 #4
On Fri, Oct 08, 2004 at 09:52:00AM -0400, Tom Lane wrote:
The infrastructure needed for this is finally present in 8.0, ie we have
the timezone data available, but actually teaching AT TIME ZONE about it
didn't get done in time. Likely it will appear in 8.1 (especially if
you step up and do the work ;-)).
I've had a look at the code that is in CVS and it looks like everything
needed is basically there. I think what's basically needed is a system
to keep track of tzname => struct state mappings, probably a hash of
some sort.

I'd consider creating a timezone preserving type, but it's not
necessary for what I'm doing. Is that library already built into 8.0?
If that's the case there is an opportunity to create a contrib module
that hooks into it.

Hmm...
--
Martijn van Oosterhout <kl*****@svana.org> http://svana.org/kleptog/ Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
tool for doing 5% of the work and then sitting around waiting for someone
else to do the other 95% so you can sue them.


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFBco+fY5Twig3Ge+YRAns2AKDVAEedXNcEkyvRaXBZIQ C67mIHxgCglj6J
qg6szfZ90gH4w1AkB4A3Oik=
=zhTx
-----END PGP SIGNATURE-----

Nov 23 '05 #5

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

Similar topics

0
by: B. G. Mahesh | last post by:
hi I am using PHP 4.x and MySQL. The database has the list of countries, cities and timezones. I would like to convert the time from one zone to another zone . It is not that difficult to...
13
by: Michael | last post by:
I would like to set the timezone of a thread to allow me to calculate the UTC time for data sourced from a number of time zones. Although this can be done in C and C++, I annot find how to do...
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: 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...
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...
7
by: David T. Ashley | last post by:
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...
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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,...
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,...

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.