@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj instanceof ChronoPeriodImpl) { ChronoPeriodImpl other = (ChronoPeriodImpl) obj; return years == other.years && months == other.months && days == other.days && chronology.equals(other.chronology); } return false; }
private static boolean isIso(TemporalAccessor temporal) { return Chronology.from(temporal).equals(IsoChronology.INSTANCE); }
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); } }
/** * Casts the {@code Temporal} to {@code ChronoLocalDate} with the same chronology. * * @param temporal a date-time to cast, not null * @return the date-time checked and cast to {@code ChronoLocalDate}, not null * @throws ClassCastException if the date-time cannot be cast to ChronoLocalDate * or the chronology is not equal this Chrono */ <D extends ChronoLocalDate> D ensureChronoLocalDate(Temporal temporal) { @SuppressWarnings("unchecked") D other = (D) temporal; if (this.equals(other.getChronology()) == false) { throw new ClassCastException("Chrono mismatch, expected: " + getId() + ", actual: " + other.getChronology().getId()); } return other; }
if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) { throw new DateTimeException("Adjustment only supported on ISO date-time");
if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) { throw new DateTimeException("Adjustment only supported on ISO date-time");
if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) { throw new DateTimeException("Adjustment only supported on ISO date-time");
/** * Casts the {@code Temporal} to {@code ChronoLocalDateTime} with the same chronology. * * @param temporal a date-time to cast, not null * @return the date-time checked and cast to {@code ChronoLocalDateTime}, not null * @throws ClassCastException if the date-time cannot be cast to ChronoLocalDateTimeImpl * or the chronology is not equal this Chrono */ <D extends ChronoLocalDate> ChronoLocalDateTimeImpl<D> ensureChronoLocalDateTime(Temporal temporal) { @SuppressWarnings("unchecked") ChronoLocalDateTimeImpl<D> other = (ChronoLocalDateTimeImpl<D>) temporal; if (this.equals(other.toLocalDate().getChronology()) == false) { throw new ClassCastException("Chrono mismatch, required: " + getId() + ", supplied: " + other.toLocalDate().getChronology().getId()); } return other; }
/** * Casts the {@code Temporal} to {@code ChronoZonedDateTimeImpl} with the same chronology. * * @param temporal a date-time to cast, not null * @return the date-time checked and cast to {@code ChronoZonedDateTimeImpl}, not null * @throws ClassCastException if the date-time cannot be cast to ChronoZonedDateTimeImpl * or the chronology is not equal this Chrono */ <D extends ChronoLocalDate> ChronoZonedDateTimeImpl<D> ensureChronoZonedDateTime(Temporal temporal) { @SuppressWarnings("unchecked") ChronoZonedDateTimeImpl<D> other = (ChronoZonedDateTimeImpl<D>) temporal; if (this.equals(other.toLocalDate().getChronology()) == false) { throw new ClassCastException("Chrono mismatch, required: " + getId() + ", supplied: " + other.toLocalDate().getChronology().getId()); } return other; }
if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) { throw new DateTimeException("Adjustment only supported on ISO date-time");
if (!Chronology.from(temporal).equals(IsoChronology.INSTANCE)) { throw new DateTimeException("Adjustment only supported on ISO date-time");
if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) { throw new DateTimeException("Adjustment only supported on ISO date-time");
if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) { throw new DateTimeException("Adjustment only supported on ISO date-time");
if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) { throw new DateTimeException("Adjustment only supported on ISO date-time");
@Override public ChronoPeriod plus(TemporalAmount amountToAdd) { if (amountToAdd instanceof ChronoPeriodImpl) { ChronoPeriodImpl amount = (ChronoPeriodImpl) amountToAdd; if (amount.getChronology().equals(getChronology())) { return new ChronoPeriodImpl( chronology, Jdk8Methods.safeAdd(years, amount.years), Jdk8Methods.safeAdd(months, amount.months), Jdk8Methods.safeAdd(days, amount.days)); } } throw new DateTimeException("Unable to add amount: " + amountToAdd); }
@Override public ChronoPeriod minus(TemporalAmount amountToSubtract) { if (amountToSubtract instanceof ChronoPeriodImpl) { ChronoPeriodImpl amount = (ChronoPeriodImpl) amountToSubtract; if (amount.getChronology().equals(getChronology())) { return new ChronoPeriodImpl( chronology, Jdk8Methods.safeSubtract(years, amount.years), Jdk8Methods.safeSubtract(months, amount.months), Jdk8Methods.safeSubtract(days, amount.days)); } } throw new DateTimeException("Unable to subtract amount: " + amountToSubtract); }
if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) { throw new DateTimeException("Adjustment only supported on ISO date-time");
@Override public Temporal addTo(Temporal temporal) { Jdk8Methods.requireNonNull(temporal, "temporal"); Chronology temporalChrono = temporal.query(TemporalQueries.chronology()); if (temporalChrono != null && chronology.equals(temporalChrono) == false) { throw new DateTimeException("Invalid chronology, required: " + chronology.getId() + ", but was: " + temporalChrono.getId()); } if (years != 0) { temporal = temporal.plus(years, YEARS); } if (months != 0) { temporal = temporal.plus(months, MONTHS); } if (days != 0) { temporal = temporal.plus(days, DAYS); } return temporal; }
@Override public Temporal subtractFrom(Temporal temporal) { Jdk8Methods.requireNonNull(temporal, "temporal"); Chronology temporalChrono = temporal.query(TemporalQueries.chronology()); if (temporalChrono != null && chronology.equals(temporalChrono) == false) { throw new DateTimeException("Invalid chronology, required: " + chronology.getId() + ", but was: " + temporalChrono.getId()); } if (years != 0) { temporal = temporal.minus(years, YEARS); } if (months != 0) { temporal = temporal.minus(months, MONTHS); } if (days != 0) { temporal = temporal.minus(days, DAYS); } return temporal; }