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

java.sql.Date subtracts one year from dates before 1 A.D.

XMLWordPrintable

      A DESCRIPTION OF THE PROBLEM :
      For the year 0 A.D. as well as years in the B.C.E. era, java.sql.Date subtracts one year, thus moving 0 A.D. to 1 B.C.E. and 1 B.C.E to 2 B.C.E. In addition the java.sql.Date.toString() method does not show that years in the B.C.E. era are negative.
      Conversion from java.time.LocalDate to java.sql.Date is not the opposite of conversion from java.sql.Date to java.time.LocalDate.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      LocalDate local0 = LocalDate.of(0, Month.JANUARY, 1);
      java.sql.Date sql0 = java.sql.Date.valueOf(local0);
      LocalDate local0back = sql0.toLocalDate();

      LocalDate local1 = LocalDate.of(-1, Month.JANUARY, 1);
      java.sql.Date sql1 = java.sql.Date.valueOf(local1);
      LocalDate local1back = sql1.toLocalDate();


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      sql0 shall represent the same date as local0 in year 0.
      local0back shall equal local0.
      sql1 shall represent the same date as local1 in year -1.
      local1back shall equal local1.
      ACTUAL -
      sql0 represents the same date as local0, but in year -1.
      local0back represents the same date as local0, but in year 1.
      sql1 represents the same date as local1, but in year -2.
      local1back represents the same date as local1, but in year 2.

      ---------- BEGIN SOURCE ----------
      As stated in "Steps to Reproduce".
      ---------- END SOURCE ----------

      FREQUENCY : always


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

              Created:
              Updated: