From: Oliver Jowett <oliver@opencloud.com>
To: Christian Cryder <c.s.cryder@gmail.com>
Cc: List <pgsql-jdbc@postgresql.org>
Subject: Re: Timestamp Summary
Date: Wed, 27 Jul 2005 11:29:38 +1200
Message-ID: <42E6C762.1020406@opencloud.com> (raw)
In-Reply-To: <90876a9e05072612405fa91c23@mail.gmail.com>
References: <90876a9e050725094560a4aa6a@mail.gmail.com>
<42E57348.50705@opencloud.com>
<90876a9e05072612405fa91c23@mail.gmail.com>
Christian Cryder wrote:
> If you can think of another way to do it, I'm all ears. Here's the
> crux of the issue (I feel like I've said this so many times now that
> I'm beginning to wonder if there is something fundamentally unclear in
> how I'm saying it).
> a) in a TIMESTAMP WITHOUT TIMEZONE column, 04-03-2005 02:29:00 is a
> perfectly valid time (you can manually insert this value from the
> console, or via a Statement)
Well I was expecting you to deal with it like this:
TimeZone utc = TimeZone.getTimeZone("UTC");
Calendar utcCal = Calendar.getInstance(utc);
// ...
Timestamp ts = rs.getTimestamp(1, utcCal);
// Deal with ts in terms of utcCal, e.g.:
// utcCal.setTime(ts);
// hours = utcCal.get(Calendar.HOUR);
// etc
stmt.setTimestamp(1, ts, utcCal);
In theory that should work just fine for any timestamp with no need to
meddle with either the JVM timezone or the server timezone.
The trick here is that any timestamp can be represented in UTC correctly
since UTC doesn't do any sort of daylight savings.
This isn't going to work in the current driver because it royally screws
up handling the with-Calendar variants of get/setTimestamp, but it
should be OK with my patched version.
Does that solve your problem? Am I missing something here?
> b) JDBC maps all TIMESTAMP columns to java.sql.Timestamp, which HAS
> the notion of Timezone in it. Meaning this date is going to get munged
> (because it's not a valid time in MST, for instance) as soon as you
> read it from the db, unless you set DST off.
This (Timestamp knowing about TimeZone) isn't generally true. The only
timezone-specific bit of Timestamp is the deprecated method that lets
you get the local JVM's default timezone offset. There's no timezone
info actually stored in the Timestamp. You generally want to be using a
Timestamp plus Calendar pair if you want to deal with times in a
particular timezone.
If you're trying to use a timezone that can't represent some date/time
values (such as, by the sounds of it, your default JVM timezone), then
I'm not suprised you're having problems. But that's really a design
issue in your app more than anything -- you're asking Timestamp to do
something that it *can't*.
-O
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-jdbc@postgresql.org
Cc: oliver@opencloud.com, c.s.cryder@gmail.com
Subject: Re: Timestamp Summary
In-Reply-To: <42E6C762.1020406@opencloud.com>
References: <90876a9e050725094560a4aa6a@mail.gmail.com> <42E57348.50705@opencloud.com> <90876a9e05072612405fa91c23@mail.gmail.com> <42E6C762.1020406@opencloud.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox