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

Wrong behaviour for three letter Pattern for the month September

XMLWordPrintable

    • generic
    • generic

      ADDITIONAL SYSTEM INFORMATION :
      OS name: "mac os x", version: "14.6.1", arch: "aarch64", family: "mac"
      Java version: 24, vendor: Oracle Corporation,


      A DESCRIPTION OF THE PROBLEM :
      The problem is based on the usage of "Pattern Letters and Symbols" in relationship with DateTimeFormatter.ofPattern("E LLL d HH:mm:ss yyyy XX").format(datetime);
      The usage of the three letter "LLL" is described https://docs.oracle.com/en/java/javase/24/docs/api/java.base/java/time/format/DateTimeFormatter.html#patterns using the symbol "L" three times means having a result of "Oct" (length of three) as an example for October etc.
      Also a supplemental hint from the documentation: "Number/Text: If the count of pattern letters is 3 or greater, use the Text rules above. Otherwise use the Number rules above."
      That means that for all months the resulting output should contain only three letters like "Oct", "Jan", "Feb" etc. but unfortunately the output for September results in "Sept" (four characters instead). The September seemed to be the only exception (see actual result). For all other months it results correctly in three letter results.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Use the following code:

      var time = LocalDateTime.of(2023, 9, 12, 15, 47, 32, 200);
      var datetime = ZonedDateTime.of(time, ZoneId.systemDefault());
      String formatted = DateTimeFormatter.ofPattern("E LLL d HH:mm:ss yyyy XX").format(datetime);
      System.out.println(formatted);

      I can also change the usage for ZoneId to this:
      var datetime = ZonedDateTime.of(time, ZoneId.of("Europe/Berlin"));
      and issue still persists.
      Also changing to:
      var datetime = ZonedDateTime.of(time, ZoneId.of("America/Phoenix"));
      does not change a thing. Issue stil persists.


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Sun Apr 13 00:08:27 2025 +0200
      Tue Sep 12 15:47:32 2023 +0200
      Thu Sep 12 15:47:32 2024 +0200
      Tue Oct 17 22:49:38 2023 +0200
      Tue Jan 17 22:49:38 2023 +0100
      Fri Feb 17 22:49:38 2023 +0100
      Fri Mar 17 22:49:38 2023 +0100
      Mon Apr 17 22:49:38 2023 +0200
      Wed May 17 22:49:38 2023 +0200
      Sat Jun 17 22:49:38 2023 +0200
      Mon Jul 17 22:49:38 2023 +0200
      Thu Aug 17 22:49:38 2023 +0200
      Sun Sep 17 22:49:38 2023 +0200
      Tue Oct 17 22:49:38 2023 +0200
      Fri Nov 17 22:49:38 2023 +0100
      Sun Dec 17 22:49:38 2023 +0100
      ACTUAL -
      Sun Apr 13 00:08:27 2025 +0200
      Tue Sept 12 15:47:32 2023 +0200
      Thu Sept 12 15:47:32 2024 +0200
      Tue Oct 17 22:49:38 2023 +0200
      Tue Jan 17 22:49:38 2023 +0100
      Fri Feb 17 22:49:38 2023 +0100
      Fri Mar 17 22:49:38 2023 +0100
      Mon Apr 17 22:49:38 2023 +0200
      Wed May 17 22:49:38 2023 +0200
      Sat Jun 17 22:49:38 2023 +0200
      Mon Jul 17 22:49:38 2023 +0200
      Thu Aug 17 22:49:38 2023 +0200
      Sun Sept 17 22:49:38 2023 +0200
      Tue Oct 17 22:49:38 2023 +0200
      Fri Nov 17 22:49:38 2023 +0100
      Sun Dec 17 22:49:38 2023 +0100

      ---------- BEGIN SOURCE ----------

      import java.time.Instant;
      import java.time.LocalDateTime;
      import java.time.ZoneId;
      import java.time.ZonedDateTime;
      import java.time.format.DateTimeFormatter;

      public class FormattingIssue {

        private static final String FORMATTING = "E LLL d HH:mm:ss yyyy XX";

        static void formattingCurrentZonedDateTime() {
          var time = Instant.now();
          var datetime = ZonedDateTime.ofInstant(time, ZoneId.systemDefault());
          String formatted = DateTimeFormatter.ofPattern(FORMATTING).format(datetime);
          System.out.println(formatted);
        }

        static void formattingSeptember23ZonedDateTime() {
          var time = LocalDateTime.of(2023, 9, 12, 15, 47, 32, 200);
          var datetime = ZonedDateTime.of(time, ZoneId.systemDefault());
          String formatted = DateTimeFormatter.ofPattern(FORMATTING).format(datetime);
          System.out.println(formatted);
        }

        static void formattingSeptember24ZonedDateTime() {
          var time = LocalDateTime.of(2024, 9, 12, 15, 47, 32, 200);
          var datetime = ZonedDateTime.of(time, ZoneId.systemDefault());
          String formatted = DateTimeFormatter.ofPattern(FORMATTING).format(datetime);
          System.out.println(formatted);
        }

        static void formattingOctoberZonedDateTime() {
          var time = LocalDateTime.of(2023, 10, 17, 22, 49, 38, 251);
          var datetime = ZonedDateTime.of(time, ZoneId.systemDefault());
          String formatted = DateTimeFormatter.ofPattern(FORMATTING).format(datetime);
          System.out.println(formatted);
        }

        static void formattingMonthsZonedDateTime() {
          for (var month = 1; month <= 12; month++) {
            var time = LocalDateTime.of(2023, month, 17, 22, 49, 38, 251);
            var datetime = ZonedDateTime.of(time, ZoneId.systemDefault());
            String formatted = DateTimeFormatter.ofPattern(FORMATTING).format(datetime);
            System.out.println(formatted);
          }
        }

        public static void main(String[] args) {
          formattingCurrentZonedDateTime();
          formattingSeptember23ZonedDateTime();
          formattingSeptember24ZonedDateTime();
          formattingOctoberZonedDateTime();
          formattingMonthsZonedDateTime();
        }
      }

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

            tongwan Andrew Wang
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: