Class EraRules


  • public class EraRules
    extends java.lang.Object
    EraRules represents calendar era rules specified in supplementalData/calendarData.
    • Field Detail

      • MAX_ENCODED_START_YEAR

        private static final int MAX_ENCODED_START_YEAR
        See Also:
        Constant Field Values
      • MIN_ENCODED_START_YEAR

        private static final int MIN_ENCODED_START_YEAR
        See Also:
        Constant Field Values
      • MIN_ENCODED_START

        public static final int MIN_ENCODED_START
      • startDates

        private int[] startDates
      • numEras

        private int numEras
      • currentEra

        private int currentEra
    • Constructor Detail

      • EraRules

        private EraRules​(int[] startDates,
                         int numEras)
    • Method Detail

      • getInstance

        public static EraRules getInstance​(CalType calType,
                                           boolean includeTentativeEra)
      • getNumberOfEras

        public int getNumberOfEras()
        Gets number of effective eras
        Returns:
        number of effective eras
      • getStartDate

        public int[] getStartDate​(int eraIdx,
                                  int[] fillIn)
        Gets start date of an era
        Parameters:
        eraIdx - Era index
        fillIn - Receives date fields if supplied. If null, or size of array is less than 3, then a new int[] will be newly allocated.
        Returns:
        An int array including values of year, month, day of month in this order. When an era has no start date, the result will be January 1st in year whose value is minimum integer.
      • getStartYear

        public int getStartYear​(int eraIdx)
        Gets start year of an era
        Parameters:
        eraIdx - Era index
        Returns:
        The first year of an era. When a era has no start date, minimum integer value is returned.
      • getEraIndex

        public int getEraIndex​(int year,
                               int month,
                               int day)
        Returns era index for the specified year/month/day.
        Parameters:
        year - Year
        month - Month (1-base)
        day - Day of month
        Returns:
        era index (or 0, when the specified date is before the first era)
      • getCurrentEraIndex

        public int getCurrentEraIndex()
        Gets the current era index. This is calculated only once for an instance of EraRules. The current era calculation is based on the default time zone at the time of instantiation.
        Returns:
        era index of current era (or 0, when current date is before the first era)
      • initCurrentEra

        private void initCurrentEra()
      • isSet

        private static boolean isSet​(int startDate)
      • isValidRuleStartDate

        private static boolean isValidRuleStartDate​(int year,
                                                    int month,
                                                    int day)
      • encodeDate

        private static int encodeDate​(int year,
                                      int month,
                                      int day)
        Encode year/month/date to a single integer. year is high 16 bits (-32768 to 32767), month is next 8 bits and day of month is last 8 bits.
        Parameters:
        year - year
        month - month (1-base)
        day - day of month
        Returns:
        an encoded date.
      • decodeDate

        private static int[] decodeDate​(int encodedDate,
                                        int[] fillIn)
      • compareEncodedDateWithYMD

        private static int compareEncodedDateWithYMD​(int encoded,
                                                     int year,
                                                     int month,
                                                     int day)
        Compare an encoded date with another date specified by year/month/day.
        Parameters:
        encoded - An encoded date
        year - Year of another date
        month - Month of another date
        day - Day of another date
        Returns:
        -1 when encoded date is earlier, 0 when two dates are same, and 1 when encoded date is later.