DateTimeFormatter changes year on last three days of the years 2024 and 2025

XMLWordPrintable

    • Type: Bug
    • Resolution: Not an Issue
    • Priority: P3
    • None
    • Affects Version/s: 25.0.1
    • Component/s: core-libs

      A DESCRIPTION OF THE PROBLEM :
      While formating a LocalDate with the DateTimeFormatter it occurs every time that the last 3 days of 2024 and 2025 where changed like the following:

      2024-12-29 -> 2025-12-29
      2024-12-30 -> 2025-12-30
      2024-12-31 -> 2025-12-31
      2025-12-29 -> 2026-12-29
      2025-12-30 -> 2026-12-30
      2025-12-31 -> 2026-12-31

      I checked this with the following code snippet:
        public void testMyVersion() {
          System.out.println("testMyVersion()");
          DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("YYYYMMdd");
          for (int year = 2000; year < 2041; year++) {
            System.out.println("\nYear " + year);
            LocalDate date1 = LocalDate.of(year, Month.DECEMBER, 27);
            System.out.println(dateFormatter.format(date1));
            LocalDate date2 = LocalDate.of(year, Month.DECEMBER, 28);
            System.out.println(dateFormatter.format(date2));
            LocalDate date3 = LocalDate.of(year, Month.DECEMBER, 29);
            System.out.println(dateFormatter.format(date3));
            LocalDate date4 = LocalDate.of(year, Month.DECEMBER, 30);
            System.out.println(dateFormatter.format(date4));
            LocalDate date5 = LocalDate.of(year, Month.DECEMBER, 31);
            System.out.println(dateFormatter.format(date5));
          }
        }

      It also appears in other years (i.e. 2029, 2030, 2031).

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use the DateTimeFormatter to format a LocalDate like 2025-12-30.

      Code snippet I used to test.

        public void testMyVersion() {
          System.out.println("testMyVersion()");
          DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("YYYYMMdd");
          for (int year = 2000; year < 2041; year++) {
            System.out.println("\nYear " + year);
            LocalDate date1 = LocalDate.of(year, Month.DECEMBER, 27);
            System.out.println(dateFormatter.format(date1));
            LocalDate date2 = LocalDate.of(year, Month.DECEMBER, 28);
            System.out.println(dateFormatter.format(date2));
            LocalDate date3 = LocalDate.of(year, Month.DECEMBER, 29);
            System.out.println(dateFormatter.format(date3));
            LocalDate date4 = LocalDate.of(year, Month.DECEMBER, 30);
            System.out.println(dateFormatter.format(date4));
            LocalDate date5 = LocalDate.of(year, Month.DECEMBER, 31);
            System.out.println(dateFormatter.format(date5));
          }
        }


      ---------- BEGIN SOURCE ----------
        public void testMyVersion() {
          System.out.println("testMyVersion()");
          DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern("YYYYMMdd");
          for (int year = 2000; year < 2041; year++) {
            System.out.println("\nYear " + year);
            LocalDate date1 = LocalDate.of(year, Month.DECEMBER, 27);
            System.out.println(dateFormatter.format(date1));
            LocalDate date2 = LocalDate.of(year, Month.DECEMBER, 28);
            System.out.println(dateFormatter.format(date2));
            LocalDate date3 = LocalDate.of(year, Month.DECEMBER, 29);
            System.out.println(dateFormatter.format(date3));
            LocalDate date4 = LocalDate.of(year, Month.DECEMBER, 30);
            System.out.println(dateFormatter.format(date4));
            LocalDate date5 = LocalDate.of(year, Month.DECEMBER, 31);
            System.out.println(dateFormatter.format(date5));
          }
        }

      ---------- END SOURCE ----------

      FREQUENCY :
      ALWAYS

            Assignee:
            Raghu Kale
            Reporter:
            Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: