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

Usage of plusMonths and until method used in conjunction gives erroneous result

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 8
    • Fix Version/s: None
    • Component/s: core-libs
    • Labels:

      Description

      A DESCRIPTION OF THE PROBLEM :
      The plusMonth method of LocalDateTime add number of months to the LocalDate (or LocalDateTime) object supplied. This sounds intuitive and trivial. However, there is a catch.

      Take for instance couple of examples when subjected to plusMonths method of LocalDate/Time -

      Format is yyyy-mm-dd

      Adding 1 month to 2020-01-01
      2020-01-01 - adding 1 month to it should give 2020-02-01. Well, too obvious. Thing to note here is that only month part of the date changed.

      Adding 1 month to 2020-01-31
      This one going with the previous logic should return 2020-02-31. But guess what, there is no such date.

      I hope the above examples would have explained that adding months is simpler if it is not any day of month which has the day in the target month. But when not available, it gives the last day of the month.

      Now, this coupled with the use of LocalDate.until(<date>, <chronounit>) was giving misleading results on the exceptional days mentioned above.


        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: