Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8324665 Loose matching of space separators in the lenient date/time parsing mode
  3. JDK-8324992

Release Note: Loose Matching of Space Separators in Lenient Date/Time Parsing Mode

XMLWordPrintable

    • generic
    • generic

      Parsing of date/time strings now allows the "loose matching" of spaces. This enhancement is mainly to address the [incompatible changes](https://www.oracle.com/java/technologies/javase/20-relnote-issues.html#JDK-8284840) introduced in JDK 20 with CLDR version 42. That version replaced ASCII spaces (`U+0020`) between time and the am/pm marker with `NNBSP` (Narrow No-Break Space, `U+202F`) in some locales. The "loose matching" is performed in the "lenient" parsing style for both date/time parsers in `java.time.format` and `java.text` packages. In the "strict" parsing style, those spaces are considered distinct, as before.

      To utilize the "loose matching" in the `java.time.format` package, applications will need to explicitly set the leniency by calling `DateTimeFormatterBuilder.parseLenient()` because the default parsing mode is strict:

      ```
          var dtf = new DateTimeFormatterBuilder()
              .parseLenient()
              .append(DateTimeFormatter.ofLocalizedTime(FormatStyle.SHORT))
              .toFormatter(Locale.ENGLISH);
      ```

      In the `java.text` package, the default parsing mode is lenient. Applications will be able to parse all space separators automatically, which is the default behavior changes with this feature. In case they need to strictly parse the text, they can do:

      ```
          var df = DateFormat.getTimeInstance(DateFormat.SHORT, Locale.ENGLISH);
          df.setLenient(false);
      ```

            naoto Naoto Sato
            naoto Naoto Sato
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: