/** * Gets the chronology of this date-time. * <p> * The {@code Chronology} represents the calendar system in use. * The era and other fields in {@link ChronoField} are defined by the chronology. * * @return the chronology, not null */ public Chronology getChronology() { return toLocalDate().getChronology(); }
/** * Gets the chronology of this date-time. * <p> * The {@code Chronology} represents the calendar system in use. * The era and other fields in {@link ChronoField} are defined by the chronology. * * @return the chronology, not null */ public Chronology getChronology() { return toLocalDate().getChronology(); }
/** * A hash code for this date. * * @return a suitable hash code */ @Override public int hashCode() { long epDay = toEpochDay(); return getChronology().hashCode() ^ ((int) (epDay ^ (epDay >>> 32))); }
@Override public ChronoLocalDate minus(TemporalAmount amount) { return getChronology().ensureChronoLocalDate(super.minus(amount)); }
/** * Obtains an instance from an {@code Instant}. * * @param instant the instant to create the date-time from, not null * @param zone the time-zone to use, validated not null * @return the zoned date-time, validated not null */ private ChronoZonedDateTimeImpl<D> create(Instant instant, ZoneId zone) { return ofInstant(toLocalDate().getChronology(), instant, zone); }
/** * Checks if the year is a leap year, as defined by the calendar system. * <p> * A leap-year is a year of a longer length than normal. * The exact meaning is determined by the chronology with the constraint that * a leap-year must imply a year-length longer than a non leap-year. * <p> * The default implementation uses {@link Chronology#isLeapYear(long)}. * * @return true if this date is in a leap year, false otherwise */ public boolean isLeapYear() { return getChronology().isLeapYear(getLong(YEAR)); }
@Override public ChronoLocalDate minus(long amountToSubtract, TemporalUnit unit) { return getChronology().ensureChronoLocalDate(super.minus(amountToSubtract, unit)); }
@Override public ChronoLocalDateTimeImpl<D> with(TemporalAdjuster adjuster) { if (adjuster instanceof ChronoLocalDate) { // The Chrono is checked in with(date,time) return with((ChronoLocalDate) adjuster, time); } else if (adjuster instanceof LocalTime) { return with(date, (LocalTime) adjuster); } else if (adjuster instanceof ChronoLocalDateTimeImpl) { return date.getChronology().ensureChronoLocalDateTime((ChronoLocalDateTimeImpl<?>) adjuster); } return date.getChronology().ensureChronoLocalDateTime((ChronoLocalDateTimeImpl<?>) adjuster.adjustInto(this)); }
@Override public ChronoZonedDateTime<D> minus(TemporalAmount amount) { return toLocalDate().getChronology().ensureChronoZonedDateTime(super.minus(amount)); }
@Override public ChronoLocalDateTime<D> minus(TemporalAmount amount) { return toLocalDate().getChronology().ensureChronoLocalDateTime(super.minus(amount)); }
@Override public ChronoLocalDateTime<D> minus(long amountToSubtract, TemporalUnit unit) { return toLocalDate().getChronology().ensureChronoLocalDateTime(super.minus(amountToSubtract, unit)); }
@Override public ChronoZonedDateTime<D> minus(long amountToSubtract, TemporalUnit unit) { return toLocalDate().getChronology().ensureChronoZonedDateTime(super.minus(amountToSubtract, unit)); }
@Override public abstract ChronoLocalDateTime<D> with(TemporalField field, long newValue);
@Override public abstract ChronoZonedDateTime<D> with(TemporalField field, long newValue);
@Override public abstract ChronoLocalDateTime<D> plus(long amountToAdd, TemporalUnit unit);
private void resolveMakeChanges(TemporalField targetField, ChronoLocalDate date) { if (chrono.equals(date.getChronology()) == false) { throw new DateTimeException("ChronoLocalDate must use the effective parsed chronology: " + chrono); } long epochDay = date.toEpochDay(); Long old = fieldValues.put(ChronoField.EPOCH_DAY, epochDay); if (old != null && old.longValue() != epochDay) { throw new DateTimeException("Conflict found: " + LocalDate.ofEpochDay(old) + " differs from " + LocalDate.ofEpochDay(epochDay) + " while resolving " + targetField); } }
@Override public ChronoZonedDateTime<D> plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { return with(dateTime.plus(amountToAdd, unit)); } return toLocalDate().getChronology().ensureChronoZonedDateTime(unit.addTo(this, amountToAdd)); /// TODO: Generics replacement Risk! }
@Override public long until(Temporal endExclusive, TemporalUnit unit) { @SuppressWarnings("unchecked") ChronoZonedDateTime<D> end = (ChronoZonedDateTime<D>) toLocalDate().getChronology().zonedDateTime(endExclusive); if (unit instanceof ChronoUnit) { end = end.withZoneSameInstant(offset); return dateTime.until(end.toLocalDateTime(), unit); } return unit.between(this, end); }
@Override public ChronoLocalDateTimeImpl<D> with(TemporalField field, long newValue) { if (field instanceof ChronoField) { if (field.isTimeBased()) { return with(date, time.with(field, newValue)); } else { return with(date.with(field, newValue), time); } } return date.getChronology().ensureChronoLocalDateTime(field.adjustInto(this, newValue)); }
@SuppressWarnings("unchecked") @Override public <R> R query(TemporalQuery<R> query) { if (query == TemporalQueries.chronology()) { return (R) getChronology(); } else if (query == TemporalQueries.precision()) { return (R) ChronoUnit.DAYS; } else if (query == TemporalQueries.localDate()) { return (R) LocalDate.ofEpochDay(toEpochDay()); } else if (query == TemporalQueries.localTime() || query == TemporalQueries.zone() || query == TemporalQueries.zoneId() || query == TemporalQueries.offset()) { return null; } return super.query(query); }