/** * Replaces the date instance from the stream with a valid one. * * @return the resolved date, never null */ private Object readResolve() { return new HijrahDate(this.gregorianEpochDay); }
@Override HijrahDate plusDays(long days) { return new HijrahDate(this.gregorianEpochDay + days); }
static HijrahDate ofEpochDay(long epochDay) { return new HijrahDate(epochDay); }
/** * Obtains an instance of {@code HijrahDate} from a date. * * @param date the date to use, not null * @return the Hijrah date, never null * @throws IllegalCalendarFieldValueException if the year is invalid */ static HijrahDate of(LocalDate date) { long gregorianDays = date.toEpochDay(); return new HijrahDate(gregorianDays); }
/** * 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); }
@Override public HijrahDate with(TemporalField field, long newValue) { if (field instanceof ChronoField) { ChronoField f = (ChronoField) field; f.checkValidValue(newValue); // TODO: validate value int nvalue = (int) newValue; switch (f) { case DAY_OF_WEEK: return plusDays(newValue - dayOfWeek.getValue()); case ALIGNED_DAY_OF_WEEK_IN_MONTH: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_MONTH)); case ALIGNED_DAY_OF_WEEK_IN_YEAR: return plusDays(newValue - getLong(ALIGNED_DAY_OF_WEEK_IN_YEAR)); case DAY_OF_MONTH: return resolvePreviousValid(yearOfEra, monthOfYear, nvalue); case DAY_OF_YEAR: return resolvePreviousValid(yearOfEra, ((nvalue - 1) / 30) + 1, ((nvalue - 1) % 30) + 1); case EPOCH_DAY: return new HijrahDate(nvalue); case ALIGNED_WEEK_OF_MONTH: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_MONTH)) * 7); case ALIGNED_WEEK_OF_YEAR: return plusDays((newValue - getLong(ALIGNED_WEEK_OF_YEAR)) * 7); case MONTH_OF_YEAR: return resolvePreviousValid(yearOfEra, nvalue, dayOfMonth); case YEAR_OF_ERA: return resolvePreviousValid(yearOfEra >= 1 ? nvalue : 1 - nvalue, monthOfYear, dayOfMonth); case YEAR: return resolvePreviousValid(nvalue, monthOfYear, dayOfMonth); case ERA: return resolvePreviousValid(1 - yearOfEra, monthOfYear, dayOfMonth); } throw new UnsupportedTemporalTypeException("Unsupported field: " + field); } return field.adjustInto(this, newValue); }