Re: Time Zone design issues

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: novnov <novnovice(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Time Zone design issues
Date: 2007-09-10 14:56:46
Message-ID: 20070910145645.GA16512@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, Sep 10, 2007 at 07:46:17AM -0700, novnov wrote:
> But 'apps all know to adjust for TZ'; really? In this case I'm creating the
> app, I can't imagine that it will automatically know to adjust for TZ? The
> postgres function now() would output now as far as the server is concerned
> (per it's local time setting I suppose), but very surprising is there is
> enough magic to report to user time as adjusted to their time zone as
> recorded in the db?

Look up the definition of the time() function. In UNIX time is measured
in seconds since 1 Jan 1970 UTC. This is a number that is obvisouly the
same no matter where you are in the world. The C library has a function
called localtime() that does all the magic of converting to whatever
you consider local time.

The postgres function now() is the same: it returns a number of seconds.
Only when you actually go to display it does it do the localtime()
dance (internally) to make it look nice. That why you can set the
timezone to whatever you like and everything works the same.

I can log into a number of servers in the world and I just have it
setup to export TZ="my timezone" and everything is in my timezone, no
matter where the machine is or whatever anyone else on the machine is
doing. It's not magic, just someone 30 years ago making the smart
choice.

Have a nice day,
--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> From each according to his ability. To each according to his ability to litigate.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Max 2007-09-10 15:24:43 Re: arrays of foreign keys
Previous Message Tom Lane 2007-09-10 14:54:04 Re: Postgresql 7.3 on Red Hat Enterprise 5 (Problem with SEMMNI, SEMMNS)