Thread: patch: fix TimeTest in timezones ahead of GMT

patch: fix TimeTest in timezones ahead of GMT

From
Oliver Jowett
Date:
This patch fixes the TimeTest test failure I noted earlier. I believe
this failure only happens in timezones that are ahead of GMT (I am +1200
currently).

-O
Index: org/postgresql/test/jdbc2/TimeTest.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/TimeTest.java,v
retrieving revision 1.10
diff -c -r1.10 TimeTest.java
*** org/postgresql/test/jdbc2/TimeTest.java    2 Apr 2004 07:28:57 -0000    1.10
--- org/postgresql/test/jdbc2/TimeTest.java    13 Apr 2004 23:38:43 -0000
***************
*** 36,41 ****
--- 36,45 ----
          TestUtil.closeDB(con);
      }

+     private long extractMillis(long time) {
+         return (time >= 0) ? (time % 1000) : (time % 1000 + 1000);
+     }
+
      /*
      *
      * Test use of calendar
***************
*** 78,109 ****

             time = rs.getTime(1);
             assertNotNull(time);
!            assertEquals(100, time.getTime() % 1000);
             timestamp = rs.getTimestamp(1);
             assertNotNull(timestamp);

!        // Pre 1.4 JVM's considered the nanos field completely separate
!        // and wouldn't return it in getTime()
!        if (TestUtil.haveMinimumJVMVersion("1.4")) {
!                assertEquals(100, timestamp.getTime() % 1000);
!        } else {
!            assertEquals(100, (timestamp.getTime() + timestamp.getNanos() / 1000000) % 1000);
!        }
             assertEquals(100000000, timestamp.getNanos());

             timetz = rs.getTime(2);
             assertNotNull(timetz);
!            assertEquals(10, timetz.getTime() % 1000);
             timestamptz = rs.getTimestamp(2);
             assertNotNull(timestamptz);

!        // Pre 1.4 JVM's considered the nanos field completely separate
!        // and wouldn't return it in getTime()
!        if (TestUtil.haveMinimumJVMVersion("1.4")) {
!                assertEquals(10, timestamptz.getTime() % 1000);
!        } else {
!            assertEquals(10, (timestamptz.getTime() + timestamptz.getNanos() / 1000000) % 1000);
!        }
             assertEquals(10000000, timestamptz.getNanos());

             assertTrue(rs.next());
--- 82,113 ----

             time = rs.getTime(1);
             assertNotNull(time);
!            assertEquals(100, extractMillis(time.getTime()));
             timestamp = rs.getTimestamp(1);
             assertNotNull(timestamp);

!            // Pre 1.4 JVM's considered the nanos field completely separate
!            // and wouldn't return it in getTime()
!            if (TestUtil.haveMinimumJVMVersion("1.4")) {
!                assertEquals(100, extractMillis(timestamp.getTime()));
!            } else {
!                assertEquals(100, extractMillis(timestamp.getTime() + timestamp.getNanos() / 1000000));
!            }
             assertEquals(100000000, timestamp.getNanos());

             timetz = rs.getTime(2);
             assertNotNull(timetz);
!            assertEquals(10, extractMillis(timetz.getTime()));
             timestamptz = rs.getTimestamp(2);
             assertNotNull(timestamptz);

!            // Pre 1.4 JVM's considered the nanos field completely separate
!            // and wouldn't return it in getTime()
!            if (TestUtil.haveMinimumJVMVersion("1.4")) {
!                assertEquals(10, extractMillis(timestamptz.getTime()));
!            } else {
!                assertEquals(10, extractMillis(timestamptz.getTime() + timestamptz.getNanos() / 1000000));
!            }
             assertEquals(10000000, timestamptz.getNanos());

             assertTrue(rs.next());

Re: patch: fix TimeTest in timezones ahead of GMT

From
Dave Cramer
Date:
I thought kris already posted a patch for this ?

Dave
On Tue, 2004-04-13 at 19:43, Oliver Jowett wrote:
> This patch fixes the TimeTest test failure I noted earlier. I believe
> this failure only happens in timezones that are ahead of GMT (I am +1200
> currently).
>
> -O
>
>
> !DSPAM:407c7d227401462733056!
>
> ______________________________________________________________________
> Index: org/postgresql/test/jdbc2/TimeTest.java
> ===================================================================
> RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/test/jdbc2/TimeTest.java,v
> retrieving revision 1.10
> diff -c -r1.10 TimeTest.java
> *** org/postgresql/test/jdbc2/TimeTest.java    2 Apr 2004 07:28:57 -0000    1.10
> --- org/postgresql/test/jdbc2/TimeTest.java    13 Apr 2004 23:38:43 -0000
> ***************
> *** 36,41 ****
> --- 36,45 ----
>           TestUtil.closeDB(con);
>       }
>
> +     private long extractMillis(long time) {
> +         return (time >= 0) ? (time % 1000) : (time % 1000 + 1000);
> +     }
> +
>       /*
>       *
>       * Test use of calendar
> ***************
> *** 78,109 ****
>
>              time = rs.getTime(1);
>              assertNotNull(time);
> !            assertEquals(100, time.getTime() % 1000);
>              timestamp = rs.getTimestamp(1);
>              assertNotNull(timestamp);
>
> !        // Pre 1.4 JVM's considered the nanos field completely separate
> !        // and wouldn't return it in getTime()
> !        if (TestUtil.haveMinimumJVMVersion("1.4")) {
> !                assertEquals(100, timestamp.getTime() % 1000);
> !        } else {
> !            assertEquals(100, (timestamp.getTime() + timestamp.getNanos() / 1000000) % 1000);
> !        }
>              assertEquals(100000000, timestamp.getNanos());
>
>              timetz = rs.getTime(2);
>              assertNotNull(timetz);
> !            assertEquals(10, timetz.getTime() % 1000);
>              timestamptz = rs.getTimestamp(2);
>              assertNotNull(timestamptz);
>
> !        // Pre 1.4 JVM's considered the nanos field completely separate
> !        // and wouldn't return it in getTime()
> !        if (TestUtil.haveMinimumJVMVersion("1.4")) {
> !                assertEquals(10, timestamptz.getTime() % 1000);
> !        } else {
> !            assertEquals(10, (timestamptz.getTime() + timestamptz.getNanos() / 1000000) % 1000);
> !        }
>              assertEquals(10000000, timestamptz.getNanos());
>
>              assertTrue(rs.next());
> --- 82,113 ----
>
>              time = rs.getTime(1);
>              assertNotNull(time);
> !            assertEquals(100, extractMillis(time.getTime()));
>              timestamp = rs.getTimestamp(1);
>              assertNotNull(timestamp);
>
> !            // Pre 1.4 JVM's considered the nanos field completely separate
> !            // and wouldn't return it in getTime()
> !            if (TestUtil.haveMinimumJVMVersion("1.4")) {
> !                assertEquals(100, extractMillis(timestamp.getTime()));
> !            } else {
> !                assertEquals(100, extractMillis(timestamp.getTime() + timestamp.getNanos() / 1000000));
> !            }
>              assertEquals(100000000, timestamp.getNanos());
>
>              timetz = rs.getTime(2);
>              assertNotNull(timetz);
> !            assertEquals(10, extractMillis(timetz.getTime()));
>              timestamptz = rs.getTimestamp(2);
>              assertNotNull(timestamptz);
>
> !            // Pre 1.4 JVM's considered the nanos field completely separate
> !            // and wouldn't return it in getTime()
> !            if (TestUtil.haveMinimumJVMVersion("1.4")) {
> !                assertEquals(10, extractMillis(timestamptz.getTime()));
> !            } else {
> !                assertEquals(10, extractMillis(timestamptz.getTime() + timestamptz.getNanos() / 1000000));
> !            }
>              assertEquals(10000000, timestamptz.getNanos());
>
>              assertTrue(rs.next());
>
>
> !DSPAM:407c7d227401462733056!
>
> ______________________________________________________________________
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
>
> !DSPAM:407c7d227401462733056!
--
Dave Cramer
519 939 0336
ICQ # 14675561


Re: patch: fix TimeTest in timezones ahead of GMT

From
Oliver Jowett
Date:
Dave Cramer wrote:
> I thought kris already posted a patch for this ?

I don't remember seeing one, and I can't find it in the archives?

There was a patch applied in the same area to do with failures on JDKs
before 1.4, but that didn't fix the failures I was seeing (I'm running
1.4.2).

-O

Re: patch: fix TimeTest in timezones ahead of GMT

From
Kris Jurka
Date:

On Wed, 14 Apr 2004, Oliver Jowett wrote:

> This patch fixes the TimeTest test failure I noted earlier. I believe
> this failure only happens in timezones that are ahead of GMT (I am +1200
> currently).
>

Patch applied.

Kris Jurka