By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,933 Members | 1,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,933 IT Pros & Developers. It's quick & easy.

Question about timezones

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
* 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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.