From: John Lister <john.lister@kickstone.com>
To: Kris Jurka <books@ejurka.com>
Cc: pgsql-jdbc@postgresql.org
Subject: Re: Unit test patches
Date: Thu, 07 May 2009 20:33:56 +0100
Message-ID: <4A0337A4.7090505@kickstone.com> (raw)
In-Reply-To: <49FF62D4.2010406@ejurka.com>
References: <49FAC740.1060607@kickstone.com>
<Pine.BSO.4.64.0905031241160.20196@leary.csoft.net>
<49FDDA33.5070009@kickstone.com>
<28431.1241374645@sss.pgh.pa.us>
<49FDEDA2.7040107@kickstone.com>
<Pine.BSO.4.64.0905032030060.7980@leary.csoft.net>
<4A020049.9050702@kickstone.com>
<49FF62D4.2010406@ejurka.com>
Kris Jurka wrote:
> John Lister wrote:
>
>> for all of these i do this first:
>> Time t=new Time(28862000); // this should be 8:01:02 UTC
>>
>> Now the odd bit
>> Europe/London (DST auto-adjust enabled but not active) - 09:01:02
>> - This is wrong, it should be equiv to GMT
>
> Yes, but not at the unix epoch. See the section titled "Permanent
> summer, 1968–1971"
>
> http://www.nmm.ac.uk/explore/astronomy-and-time/time-facts/british-summer-time/
>
I assumed that something was going on around the epoch, but didn't
realise that - amazing what you learn about your own country.
Still there is bizarre behaviour with the java time stuff (nothing new
there then...)
Assuming timezone=Europe/London then
TimeZone t=TimeZone.getDefault();
t.inDaylightTime(new Date(28862000L)) == false
t.getRawOffset() == 0
t.getOffset(28862000L) == 3600000
It would seem that inDaylightTime doesn't take into account historical
stuff...
Anyway patch attached that fixes the problem for all (tested)
timezones.. Can you let me know how you get on...
Also, for the failing test - I'm fairly sure the driver shouldn't be
inserting "9:01:02" for the value of "5:1:2+03" when the current
timezone is "Europe/London" without DST - as it uses the epoch to
calculate the offsets which while historically correct are now
incorrect. Note that setting it to simply GMT works as expected.
I suspect that the date component should be initialised to the current
date instead of 1/1/1970 for internal manipulation within the driver and
reset before returning anything to the user as a sql.Time value.
Thoughts
JOHN
Attachments:TimeTest.java.patch (text/plain, 2.4K) download
Index: TimeTest.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/test/jdbc2/TimeTest.java,v
retrieving revision 1.18
diff -u -r1.18 TimeTest.java
--- TimeTest.java 8 Jan 2008 06:56:31 -0000 1.18+++ TimeTest.java 7 May 2009 19:07:16 -0000@@ -59,9 +59,9 @@
cal.setTimeZone(TimeZone.getTimeZone("GMT"));
- long localOffset = Calendar.getInstance().get(Calendar.ZONE_OFFSET);+ int localOffset=Calendar.getInstance().getTimeZone().getOffset(midnight.getTime());- /* set the time to midnight to make this easy */+ // set the time to midnight to make this easy
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'00:00:00','00:00:00'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "'00:00:00.1','00:00:00.01'")));
assertEquals(1, stmt.executeUpdate(TestUtil.insertSQL("testtime", "CAST(CAST(now() AS timestamp without time zone) AS time),now()")));
@@ -265,11 +265,7 @@
t = rs.getTime(1);
assertNotNull(t);
java.sql.Time tmpTime = java.sql.Time.valueOf("5:1:2");
- int localoffset = java.util.Calendar.getInstance().getTimeZone().getRawOffset();- if (java.util.Calendar.getInstance().getTimeZone().inDaylightTime(tmpTime))- {- localoffset += 60 * 60 * 1000;- }+ int localoffset=java.util.Calendar.getInstance().getTimeZone().getOffset(tmpTime.getTime());
int Timeoffset = 3 * 60 * 60 * 1000;
tmpTime.setTime(tmpTime.getTime() + Timeoffset + localoffset);
assertEquals(makeTime(tmpTime.getHours(), tmpTime.getMinutes(), tmpTime.getSeconds()), t);
@@ -278,11 +274,7 @@
t = rs.getTime(1);
assertNotNull(t);
tmpTime = java.sql.Time.valueOf("23:59:59");
- localoffset = java.util.Calendar.getInstance().getTimeZone().getRawOffset();- if (java.util.Calendar.getInstance().getTimeZone().inDaylightTime(tmpTime))- {- localoffset += 60 * 60 * 1000;- }+ localoffset=java.util.Calendar.getInstance().getTimeZone().getOffset(tmpTime.getTime());
Timeoffset = -11 * 60 * 60 * 1000;
tmpTime.setTime(tmpTime.getTime() + Timeoffset + localoffset);
assertEquals(makeTime(tmpTime.getHours(), tmpTime.getMinutes(), tmpTime.getSeconds()), t);
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: john.lister@kickstone.com, books@ejurka.com
Subject: Re: Unit test patches
In-Reply-To: <4A0337A4.7090505@kickstone.com>
References: <49FAC740.1060607@kickstone.com> <Pine.BSO.4.64.0905031241160.20196@leary.csoft.net> <49FDDA33.5070009@kickstone.com> <28431.1241374645@sss.pgh.pa.us> <49FDEDA2.7040107@kickstone.com> <Pine.BSO.4.64.0905032030060.7980@leary.csoft.net> <4A020049.9050702@kickstone.com> <49FF62D4.2010406@ejurka.com> <4A0337A4.7090505@kickstone.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