pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Oliver Jowett <oliver@opencloud.com>
To: pgsql-jdbc@postgresql.org <pgsql-jdbc@postgresql.org>
Subject: TimeTest zone offset weirdness
Date: Tue, 26 Jul 2005 15:02:34 +1200
Message-ID: <42E5A7CA.6070109@opencloud.com> (raw)

I'm currently looking at TimeTest.testGetTimeZone() which has:

 final Time midnight = new Time(0, 0, 0);
 Calendar cal = Calendar.getInstance();
 cal.setTimeZone(TimeZone.getTimeZone("GMT"));
 long localOffset = Calendar.getInstance().get(Calendar.ZONE_OFFSET);
 [...]
 time = rs.getTime(1, cal);
 assertEquals(midnight.getTime() , time.getTime() + localOffset);

The value in the database that's being retrieved is '00:00:00' -- it is
a TIME WITHOUT TIME ZONE.

As I interpret things:
- 'midnight' should represent 1970-01-01 00:00:00 in the local timezone,
i.e. local midnight.
- 'time' should represent 1970-01-01 00:00:00 GMT, i.e. the database
value interpreted in the provided (GMT) calendar.

However as localOffset is the number of milliseconds that the local
timezone is *ahead* of GMT, shouldn't that test be for 'time.getTime() -
localOffset'?

e.g. in the NZ timezone, localOffset is 43200000 (milliseconds) as NZ is
12 hours ahead of GMT in January 1970. Then midnight.getTime() is
-43200000 as NZ reaches local midnight before GMT.

Given that this doesn't fail in the current driver, presumably this
means that getTime() is currently returning a Time with milliseconds =
-86400000 ... which is surely wrong.

With the timestamp-related changes I'm doing I also overhauled the Time
and Date parsers; now getTime() is returning a Time with milliseconds =
0 and the assertion fails.

Is this actually an existing test/driver error or am I misinterpreting
what the behaviour should be?

-O



Message-ID: <42E5A7CA.6070109@opencloud.com>
Permalink:  ../42E5A7CA.6070109@opencloud.com/
Also on:    postgresql.org/message-id/42E5A7CA.6070109@opencloud.com

 · 

reply

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
  Subject: Re: TimeTest zone offset weirdness
  In-Reply-To: <42E5A7CA.6070109@opencloud.com>
  References: <42E5A7CA.6070109@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