Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4107400

java.sql.Time(long) instances differ when created in different time-zones.

    Details

    • Subcomponent:
    • Resolved In Build:
      1.2beta4
    • CPU:
      sparc
    • OS:
      solaris_2.5
    • Verification:
      Verified

      Description



      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

      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              swhitesunw Seth White (Inactive)
              Reporter:
              ovlasov Oleksandr Vlasov (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: