Re: Unit test patches - Mailing list pgsql-jdbc
From | John Lister |
---|---|
Subject | Re: Unit test patches |
Date | |
Msg-id | 4A0337A4.7090505@kickstone.com Whole thread Raw |
In response to | Re: Unit test patches (Kris Jurka <books@ejurka.com>) |
Responses |
Re: Unit test patches
|
List | pgsql-jdbc |
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 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);
pgsql-jdbc by date: