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

Additional Date-Time Formats

    XMLWordPrintable

    Details

    • Type: CSR
    • Status: Draft
    • Priority: P4
    • Resolution: Unresolved
    • Fix Version/s: tbd
    • Component/s: core-libs
    • Labels:
      None
    • Subcomponent:
    • Compatibility Kind:
      source
    • Compatibility Risk:
      minimal
    • Compatibility Risk Description:
      These are additions of new methods.
    • Interface Kind:
      Java API
    • Scope:
      SE

      Description

      Summary

      Support additional date/time formats defined in CLDR

      Problem

      Currently java.time.format.DateTimeFormatter supports 4 pre-defined format styles, i.e, FormatStyle.FULL/LONG/MEDIUM/SHORT. Users cannot use localized formats in a more flexible manner, such as a format that contains only year and month.

      Solution

      Provide methods analogous to java.time.format.DateTimeFormatter#ofPattern that take Skeleton patterns defined in CLDR. They will return localized formatters based on passed skeletons. Also, add a method in java.time.format.DateTimeFormatterBuilder class that is the basis for the above two methods.

      Specification

      Add the following methods to java.time.format.DateTimeFormatter class:

      /**
       * Creates a locale specific formatter using the specified Skeleton pattern for the default locale. Skeleton
       * pattern is based on CLDR's
       * <a href="http://cldr.unicode.org/translation/date-time-1/date-time-patterns#TOC-Additional-Date-Time-Formats">
       * Additional Date-Time Formats</a>.
       * For example, {@code yMMM} will format 2020-06-16 as 'Jun 2020' in US locale.
       * <p>
       * The formatter will use the {@link Locale#getDefault(Locale.Category) default FORMAT locale} and
       * the chronology returned from {@link Chronology#ofLocale(Locale)} with that locale.
       * <p>
       * The returned formatter has no override zone.
       * It uses {@link ResolverStyle#SMART SMART} resolver style.
       *
       * @param skeleton the skeleton pattern to use, not null
       * @return the formatter based on the pattern, not null
       * @throws IllegalArgumentException if the skeleton pattern is invalid
       * @see #ofPattern(String)
       * @since 18
       */
      public static DateTimeFormatter ofLocalizedPattern(String skeleton)
      
      /**
       * Creates a locale specific formatter using the specified Skeleton pattern and locale. Skeleton
       * pattern is based on CLDR's
       * <a href="http://cldr.unicode.org/translation/date-time-1/date-time-patterns#TOC-Additional-Date-Time-Formats">
       * Additional Date-Time Formats</a>.
       * For example, {@code yMMM} will format 2020-06-16 as 'Jun 2020' in US locale.
       * <p>
       * The formatter will use the specified locale and
       * the chronology returned from {@link Chronology#ofLocale(Locale)} with that locale.
       * <p>
       * The returned formatter has no override zone.
       * It uses {@link ResolverStyle#SMART SMART} resolver style.
       *
       * @param skeleton the skeleton pattern to use, not null
       * @param locale the locale to use, not null
       * @return the formatter based on the pattern, not null
       * @throws IllegalArgumentException if the skeleton pattern is invalid
       * @see #ofPattern(String, Locale)
       * @since 18
       */
      public static DateTimeFormatter ofLocalizedPattern(String skeleton, Locale locale)

      Add the following method to java.time.format.DateTimeFormatterBuilder class:

      /**
       * Appends a localized pattern to the formatter using the specified skeleton
       * pattern, locale, and chronology. Skeleton pattern is based on CLDR's
       * <a href="http://cldr.unicode.org/translation/date-time-1/date-time-patterns#TOC-Additional-Date-Time-Formats">
       * Additional Date-Time Formats</a>.
       * For example, {@code yMMM} will format 2011-12-03 as 'Dec 2011' in US locale.
       * @param skeleton the skeleton pattern to use, not null
       * @param locale the locale to use, not null
       * @param chrono the chronology to use, not null
       * @return this, for chaining, not null
       * @throws IllegalArgumentException if the skeleton pattern is invalid
       * @see #appendPattern(String)
       * @since 18
       */
      public DateTimeFormatterBuilder appendLocalizedPattern(String skeleton, Locale locale, Chronology chrono)

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                Created:
                Updated: