pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Hari <hkodungallur@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: JDK5 and TimeTest
Date: 18 Aug 2006 12:02:07 -0700
Message-ID: <1155927727.169145.64490@m73g2000cwd.googlegroups.com> (raw)

Hello,

The TimeTest (jdbc2) fails for the tests with timezone while running
the postgresql-jdbc tests using JDK5. This is using pgsql-jdbc version
8.0.311 and postgresql version 8.0.6.
I was wondering whether someone in the group has enountered the same
and if there is a fix. I am just beginning to debug this and I have a
feeling that it may be because the Calendar implementation JDK5 seems
very different. Any ideas?

Thanks very much!
-Hari
SpikeSource Inc.
http://developer.spikesource.com

----------------------
Where it fails (org/postgresql/test/jdbc2/TimeTest.java):
==> The time is set in testSetTime (this works):
...
...
        ps.setObject(1, "5:1:2-03", java.sql.Types.TIME);
        assertEquals(1, ps.executeUpdate());

        ps.setObject(1, "23:59:59+11", java.sql.Types.TIME);
        assertEquals(1, ps.executeUpdate());
...
...

==> in timeTest method, the above time is accessed and it fails:
...
...
        // If we're checking for timezones.
        if (testSetTime)
        {
            assertTrue(rs.next());
            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 Timeoffset = 3 * 60 * 60 * 1000;
            tmpTime.setTime(tmpTime.getTime() + Timeoffset +
localoffset);
            assertEquals(makeTime(tmpTime.getHours(),
tmpTime.getMinutes(), tmpTime.getSeconds()), t);  // <=== fails here

...
...

The error message is:
  expected:<00:01:02> but was:<05:01:02>
      junit.framework.AssertionFailedError: expected:<00:01:02> but
was:<05:01:02> at
      org.postgresql.test.jdbc2.TimeTest.timeTest(TimeTest.java:275) at

      org.postgresql.test.jdbc2.TimeTest.testSetTime(TimeTest.java:201)


A simple Calendar code like this shows two different output under JDK
1.4 and JDK5:

import java.util.Calendar;

class TestCalendar {
    public static void main(String[] args) {
        Calendar c = Calendar.getInstance();
        System.out.println(c.toString());
    }
}

(Execute it and look at the difference in the SimpleTimeZone object
within the Calendar object. They look entirely different).




view thread (2+ messages)  latest in thread

Message-ID: <1155927727.169145.64490@m73g2000cwd.googlegroups.com>
Permalink:  ../1155927727.169145.64490@m73g2000cwd.googlegroups.com/
Also on:    postgresql.org/message-id/1155927727.169145.64490@m73g2000cwd.googlegroups.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: hkodungallur@gmail.com
  Subject: Re: JDK5 and TimeTest
  In-Reply-To: <1155927727.169145.64490@m73g2000cwd.googlegroups.com>
  References: <1155927727.169145.64490@m73g2000cwd.googlegroups.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