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

LocalDate not supporting 29th February even if the year is Leap Year while changing an existing date to February in a leap year withmonth(

XMLWordPrintable

    • generic
    • generic

      FULL PRODUCT VERSION :
      JDK 1.8_101

      ADDITIONAL OS VERSION INFORMATION :
      Windows 10

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      An existing date with 29 as day of month is changed to Feb in a leap year using withMonth() and withYear() methods.

      A DESCRIPTION OF THE PROBLEM :
      An existing date with 29 as day of month is changed to Feb in a leap year using withMonth() and withYear() methods. The date is squared off to February 28 by program.

      Expected behaviour:
      The date should be 29 February if the given year is leap year.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
       LocalDate testDay = LocalDate.of(1947, Month.AUGUST, 29);
              System.out.println("Test Day: " + testDay);

              independenceDay = testDay.withMonth(2).withYear(2000);
              System.out.println("Local Date Test with given Month and Year: " + independenceDay);

      Run the above lines of code with LocalDate

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Expected behaviour:
      The date should be 29 February if the given year in the withYear() is leap year.
      ACTUAL -
       LocalDate testDay = LocalDate.of(1947, Month.AUGUST, 29);
              System.out.println("Test Day: " + testDay);

             LocalDate independenceDay = testDay.withMonth(2).withYear(2000);
              System.out.println("Local Date Test with given Month and Year: " + independenceDay);

      The output is:
      Test Day: 1947-08-29
      Local Date Test with given Month and Year: 2000-02-28

      //Expected output:
      Test Day: 1947-08-29
      Local Date Test with given Month and Year: 2000-02-29

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      package DateTime;

      import java.time.ZonedDateTime;
      import java.time.LocalDate;
      import java.time.LocalDateTime;
      import java.time.LocalTime;
      import java.time.Month;
      import java.time.ZoneId;

      public class DateTimeClass
      {
          public static void main(String args[])
          {
              DateTimeClass dateTimeTester = new DateTimeClass();
              dateTimeTester.testLocalDateTime();
             
          }

          public void testLocalDateTime()
          {

              LocalDate testDay = LocalDate.of(1947, Month.AUGUST, 29);
              System.out.println("Test Day: " + testDay);

              LocalDate independenceDay = testDay.withMonth(2).withYear(2000);
              System.out.println("Local Date Test with given Month and Year: " + independenceDay);

           
          }

        
      }
      ---------- END SOURCE ----------

            psonal Pallavi Sonal (Inactive)
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: