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

java.time.DateTimeFormatter: wrong definition of symbol F

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • core-libs
    • None
    • behavioral
    • medium
    • As the definition and implementation of the pattern symbol `F` changes, the code that uses the pattern symbol will behave differently (in a correct manner).
    • Java API
    • SE

      Summary

      Align the definition and its implementation of F pattern symbol in java.time.format.DateTimeFormatter/Builder with java.text.SimpleDateFormat and Unicode Consortium's CLDR.

      Problem

      Currently F pattern translates to ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH which differs from SimpleDateFormat/CLDR. The field definition should align with F pattern symbols in those other definitions.

      Solution

      Change the definition of F from ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH to ChronoField.ALIGNED_WEEK_OF_MONTH.

      Specification

      Change the definition of F pattern symbol in the class description of java.time.format.DateTimeFormatter class as:

      @@ -295,11 +295,11 @@
        *   <tr><th scope="row">Y</th>       <td>week-based-year</td>             <td>year</td>              <td>1996; 96</td>
        *   <tr><th scope="row">w</th>       <td>week-of-week-based-year</td>     <td>number</td>            <td>27</td>
        *   <tr><th scope="row">W</th>       <td>week-of-month</td>               <td>number</td>            <td>4</td>
        *   <tr><th scope="row">E</th>       <td>day-of-week</td>                 <td>text</td>              <td>Tue; Tuesday; T</td>
        *   <tr><th scope="row">e/c</th>     <td>localized day-of-week</td>       <td>number/text</td>       <td>2; 02; Tue; Tuesday; T</td>
      - *   <tr><th scope="row">F</th>       <td>day-of-week-in-month</td>        <td>number</td>            <td>3</td>
      + *   <tr><th scope="row">F</th>       <td>aligned-week-of-month</td>       <td>number</td>            <td>3</td>
        *
        *   <tr><th scope="row">a</th>       <td>am-pm-of-day</td>                <td>text</td>              <td>PM</td>
        *   <tr><th scope="row">B</th>       <td>period-of-day</td>               <td>text</td>              <td>in the morning</td>
        *   <tr><th scope="row">h</th>       <td>clock-hour-of-am-pm (1-12)</td>  <td>number</td>            <td>12</td>
        *   <tr><th scope="row">K</th>       <td>hour-of-am-pm (0-11)</td>        <td>number</td>            <td>0</td>

      Change the definition of F pattern symbol in DateTimeFormatterBuilder.appendValue() method as:

      @@ -1772,11 +1772,11 @@
            *    d       1      appendValue(ChronoField.DAY_OF_MONTH)
            *    dd      2      appendValue(ChronoField.DAY_OF_MONTH, 2)
            *    D       1      appendValue(ChronoField.DAY_OF_YEAR)
            *    DD      2      appendValue(ChronoField.DAY_OF_YEAR, 2, 3, SignStyle.NOT_NEGATIVE)
            *    DDD     3      appendValue(ChronoField.DAY_OF_YEAR, 3)
      -     *    F       1      appendValue(ChronoField.ALIGNED_DAY_OF_WEEK_IN_MONTH)
      +     *    F       1      appendValue(ChronoField.ALIGNED_WEEK_OF_MONTH)
            *    g..g    1..n   appendValue(JulianFields.MODIFIED_JULIAN_DAY, n, 19, SignStyle.NORMAL)
            *    E       1      appendText(ChronoField.DAY_OF_WEEK, TextStyle.SHORT)
            *    EE      2      appendText(ChronoField.DAY_OF_WEEK, TextStyle.SHORT)
            *    EEE     3      appendText(ChronoField.DAY_OF_WEEK, TextStyle.SHORT)
            *    EEEE    4      appendText(ChronoField.DAY_OF_WEEK, TextStyle.FULL)

            naoto Naoto Sato
            webbuggrp Webbug Group
            Joe Wang, Lance Andersen, Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: