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

java.sql.Timestamp from/to java.time.Instant conversion consistently off for datetimes in the far past

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      java version "1.8.0_60"
      Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
      Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)

      ADDITIONAL OS VERSION INFORMATION :
      OS X 10.11.5 El Capitan

      A DESCRIPTION OF THE PROBLEM :
      For dates before 1582, Timestamp.from(...) and toInstant() are consistently off by a few days.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Run the following program:

      import java.sql.Timestamp;
      import java.time.Instant;

      public class Time {
        public static void main(String[] args) {
          Instant i = Instant.parse("1582-01-01T00:00:00Z");
          Timestamp t = Timestamp.valueOf("1582-01-01 00:00:00");

          System.out.println(t.toInstant());
          System.out.println(Timestamp.from(i));
        }
      }

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Should return 1582-01-01T00:00:00Z
      ACTUAL -
      Returns offset dates.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      import java.sql.Timestamp;
      import java.time.Instant;

      public class Time {
        public static void main(String[] args) {
          Instant i = Instant.parse("1582-01-01T00:00:00Z");
          Timestamp t = Timestamp.valueOf("1582-01-01 00:00:00");

          System.out.println(t.toInstant());
          System.out.println(Timestamp.from(i));
        }
      }
      ---------- END SOURCE ----------

            lancea Lance Andersen
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: