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

Support for IsoFields in JapaneseDate/MinguoDate/ThaiBuddhistDate

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • core-libs
    • None
    • source
    • minimal
    • This is a new default method in a public interface.
    • Java API
    • SE

      Summary

      Support java.time.temporal.IsoFields such as QUARTER_OF_YEAR and DAY_OF_QUARTER in ChronoLocalDate classes for Japanese, Minguo, and ThaiBuddhist chronologies.

      Problem

      The fields in IsoFields class are only available in java.time.LocalDate for the ISOChronology. The concept of those fields can also be applied to other chronologies that are based on ISO 8601, but there's no way to utilize them.

      Solution

      Define a new default method in java.time.chrono.Chronology to determine if a chronology is ISO based or not. IsoFields then checks whether the chronology is ISO based or not by calling the method so that its fields can be applied to the chronology in question. The default method returns false, each ISO based chronology implements the method to return true.

      Specification

      Add the following default method in java.time.chrono.Chronology:

      /**
       * Checks if this chronology is ISO based.
       * <p>
       * An ISO based chronology has the same basic structure as the {@link IsoChronology
       * ISO chronology}, i.e., the chronology has the same number of months, the number
       * of days in each month, and day-of-year and leap years are the same as ISO chronology.
       * It also supports the concept of week-based-year of ISO chronology.
       * For example, the {@link MinguoChronology Minguo}, {@link ThaiBuddhistChronology
       * ThaiThaiBuddhist} and {@link JapaneseChronology Japanese} chronologies are ISO based.
       *
       * @implSpec
       * The default implementation returns {@code false}.
       *
       * @return {@code true} only if all the fields of {@link IsoFields} are supported by
       *          this chronology. Otherwise, returns {@code false}.
       * @see IsoChronology
       * @see JapaneseChronology
       * @see MinguoChronology
       * @see ThaiBuddhistChronology
       * @see IsoFields
       * @since 19
       */
      default boolean isIsoBased()

      IsoChronology, JapaneseChronology, MinguoChronology, and ThaiBuddhistChronology override the above method as (replace IsoChronology as appropriate):

      /**
       * {@code IsoChronology} is an ISO based chronology, which supports fields
       * in {@link IsoFields}, such as {@link IsoFields#DAY_OF_QUARTER DAY_OF_QUARTER}
       * and {@link IsoFields#QUARTER_OF_YEAR QUARTER_OF_YEAR}.
       * @see IsoFields
       * @return {@code true}
       * @since 19
       */
      @Override
      public boolean isIsoBased() 

            naoto Naoto Sato
            naoto Naoto Sato
            Joe Wang, Roger Riggs
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: