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

ChronoUnit.MONTHS.between() not giving correct result when date is in February

XMLWordPrintable

    • master
    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      MacOS Version 14.7 (23H124)
      openjdk version "23" 2024-09-17
      OpenJDK Runtime Environment (build 23+37-2369)
      OpenJDK 64-Bit Server VM (build 23+37-2369, mixed mode, sharing)

      A DESCRIPTION OF THE PROBLEM :
      ChronoUnit.MONTH is expected to return the number of months between two given Temporals. However it fails in the following case.
      ChronoUnit.MONTH.between(LocalDateTime.parse("2024-09-29T06:03:00"), LocalDateTime.parse("2025-02-28T06:04:00")) returns 4 instead of 5.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      import java.time.temporal.ChronoUnit;
      import java.time.LocalDateTime;

      ChronoUnit.MONTHS.between(LocalDateTime.parse("2024-09-29T06:03:00"), LocalDateTime.parse("2025-02-28T06:04:00"));


      ---------- BEGIN SOURCE ----------
      import java.time.temporal.ChronoUnit;
      import java.time.LocalDateTime;

      ChronoUnit.MONTHS.between(LocalDateTime.parse("2024-09-29T06:03:00"), LocalDateTime.parse("2025-02-28T06:04:00"));
      ---------- END SOURCE ----------

            naoto Naoto Sato
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            9 Start watching this issue

              Created:
              Updated:
              Resolved: