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

Java Localdate minus month have bug when moving back from June to March

    Details

    • Subcomponent:
    • CPU:
      x86_64
    • OS:
      windows_10

      Description

      ADDITIONAL SYSTEM INFORMATION :
      Windows Java 8

      A DESCRIPTION OF THE PROBLEM :
        LocalDate previousQuarterDate = LocalDate.of(2018,6,30).minus(Period.ofMonths(3));
      This should give me 03/31/2018, instead we are getting 03/30/2018

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        LocalDate previousQuarterDate = LocalDate.of(2018,6,30).minus(Period.ofMonths(3));

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      03/31/2018
      ACTUAL -
      03/30/2018

      ---------- BEGIN SOURCE ----------
      import java.time.Duration;
      import java.time.LocalDate;
      import java.time.Month;
      import java.time.temporal.ChronoUnit;
      import java.time.temporal.TemporalAdjusters;
      import java.time.Period;

      public class HelloWorld{

           public static void main(String []args){
               
               LocalDate previousQuarterDate = LocalDate.of(2018,6,30).minus(Period.ofMonths(3));
              System.out.println(previousQuarterDate);
           }
      }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      import java.time.Duration;
      import java.time.LocalDate;
      import java.time.Month;
      import java.time.temporal.ChronoUnit;
      import java.time.temporal.TemporalAdjusters;
      import java.time.Period;

      public class HelloWorld{

           public static void main(String []args){
               
               LocalDate previousQuarterDate = LocalDate.of(2018,6,30).minus(Period.ofMonths(3)).with(TemporalAdjusters.lastDayOfMonth());;
              System.out.println(previousQuarterDate);
           }
      }

        Attachments

          Activity

            People

            • Assignee:
              psonal Pallavi Sonal
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: