Name: avC70361 Date: 01/28/98
java.sql.Time instances created with constructor java.sql.Time(long millis) in
different time-zones with the same millis value are not equal. This is caused by
the fact that the constructor wipes date fields and then sets hour, minute and
second fields to values extracted from millis parameter using default
TimeZone. Therefore, when created in time-zones with different offsets two
java.sql.Time instances are representing different points in time.
Here is the test demonstrating the bug:
----------SQLTimeTest.java----------
import java.sql.Time;
import java.util.TimeZone;
public class SQLTimeTest {
public static void main(String args[]) {
long date = 123456789L;
TimeZone.setDefault(TimeZone.getTimeZone("GMT"));
Time time1 = new Time(date);
System.out.println("Original time : " + new java.util.Date(date));
TimeZone.setDefault(TimeZone.getTimeZone("PST"));
Time time2 = new Time(date);
if (time1.equals(time2)) {
System.out.println("Passed.");
} else {
System.out.println("Failed: java.sql.Time instances created in GMT and PST time-zones are not equal.\njava.sql.Time created using GMT = " + time1 + "\njava.sql.Time created using PST = " + time2);
}
}
}
------------The test output----------
> java SQLTimeTest
Original time : Fri Jan 02 10:17:36 GMT+00:00 1970
Failed: java.sql.Time instances created in GMT and PST time-zones are not equal.
java.sql.Time created using GMT = 10:17:36
java.sql.Time created using PST = 02:17:36
======================================================================