@Override protected HijrahEra eraOf(final String id) { return HijrahEra.valueOf(id); }
@Override public List<Era> eras() { return Arrays.<Era>asList(HijrahEra.values()); }
void writeExternal(DataOutput out) throws IOException { out.writeByte(this.getValue()); }
static HijrahEra readExternal(DataInput in) throws IOException { byte eraValue = in.readByte(); return HijrahEra.of(eraValue); }
/** * Gets the era numeric value. * <p> * The current era (from ISO date 622-06-19 onwards) has the value 1. * The previous era has the value 0. * * @return the era value, from 0 (BEFORE_AH) to 1 (AH) */ @Override public int getValue() { return ordinal(); }
/** * Obtains an instance of {@code HijrahDate} from the era, year-of-era * month-of-year and day-of-month. * * @param era the era to represent, not null * @param yearOfEra the year-of-era to represent, from 1 to 9999 * @param monthOfYear the month-of-year to represent, from 1 to 12 * @param dayOfMonth the day-of-month to represent, from 1 to 31 * @return the Hijrah date, never null * @throws IllegalCalendarFieldValueException if the value of any field is out of range * @throws InvalidCalendarFieldException if the day-of-month is invalid for the month-year */ static HijrahDate of(HijrahEra era, int yearOfEra, int monthOfYear, int dayOfMonth) { Jdk8Methods.requireNonNull(era, "era"); checkValidYearOfEra(yearOfEra); checkValidMonth(monthOfYear); checkValidDayOfMonth(dayOfMonth); long gregorianDays = getGregorianEpochDay(era.prolepticYear(yearOfEra), monthOfYear, dayOfMonth); return new HijrahDate(gregorianDays); }
private static Object readInternal(byte type, ObjectInput in) throws IOException, ClassNotFoundException { switch (type) { case JAPANESE_DATE_TYPE: return JapaneseDate.readExternal(in); case JAPANESE_ERA_TYPE: return JapaneseEra.readExternal(in); case HIJRAH_DATE_TYPE: return HijrahDate.readExternal(in); case HIJRAH_ERA_TYPE: return HijrahEra.readExternal(in); case MINGUO_DATE_TYPE: return MinguoDate.readExternal(in); case MINGUO_ERA_TYPE: return MinguoEra.readExternal(in); case THAIBUDDHIST_DATE_TYPE: return ThaiBuddhistDate.readExternal(in); case THAIBUDDHIST_ERA_TYPE: return ThaiBuddhistEra.readExternal(in); case CHRONO_TYPE: return Chronology.readExternal(in); case CHRONO_LOCALDATETIME_TYPE: return ChronoLocalDateTimeImpl.readExternal(in); case CHRONO_ZONEDDATETIME_TYPE: return ChronoZonedDateTimeImpl.readExternal(in); default: throw new StreamCorruptedException("Unknown serialized type"); } }
@Override public Temporal adjustInto(Temporal temporal) { return temporal.with(ERA, getValue()); }
/** * Constructs an instance with the specified date. * * @param gregorianDay the number of days from 0001/01/01 (Gregorian), caller calculated */ private HijrahDate(long gregorianDay) { int[] dateInfo = getHijrahDateInfo(gregorianDay); checkValidYearOfEra(dateInfo[1]); checkValidMonth(dateInfo[2]); checkValidDayOfMonth(dateInfo[3]); checkValidDayOfYear(dateInfo[4]); this.era = HijrahEra.of(dateInfo[0]); this.yearOfEra = dateInfo[1]; this.monthOfYear = dateInfo[2]; this.dayOfMonth = dateInfo[3]; this.dayOfYear = dateInfo[4]; this.dayOfWeek = DayOfWeek.of(dateInfo[5]); this.gregorianEpochDay = gregorianDay; this.isLeapYear = isLeapYear(this.yearOfEra); }
@Override protected HijrahEra eraOf(final String id) { return HijrahEra.valueOf(id); }
@Override public long getLong(TemporalField field) { if (field == ERA) { return getValue(); } else if (field instanceof ChronoField) { throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.getFrom(this); }
@Override protected HijrahEra eraOf(final String id) { return HijrahEra.valueOf(id); }
@Override public long getLong(TemporalField field) { if (field instanceof ChronoField) { switch ((ChronoField) field) { case DAY_OF_WEEK: return dayOfWeek.getValue(); case ALIGNED_DAY_OF_WEEK_IN_MONTH: return ((dayOfWeek.getValue() - 1) % 7) + 1; case ALIGNED_DAY_OF_WEEK_IN_YEAR: return ((dayOfYear - 1) % 7) + 1; case DAY_OF_MONTH: return this.dayOfMonth; case DAY_OF_YEAR: return this.dayOfYear; case EPOCH_DAY: return toEpochDay(); case ALIGNED_WEEK_OF_MONTH: return ((dayOfMonth - 1) / 7) + 1; case ALIGNED_WEEK_OF_YEAR: return ((dayOfYear - 1) / 7) + 1; case MONTH_OF_YEAR: return monthOfYear; case YEAR_OF_ERA: return yearOfEra; case YEAR: return yearOfEra; case ERA: return era.getValue(); } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.getFrom(this); }
@Override protected HijrahEra eraOf(final String id) { return HijrahEra.valueOf(id); }