@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 ChronoLocalDateTime<D> minus(long amountToSubtract, TemporalUnit unit) { return toLocalDate().getChronology().ensureChronoLocalDateTime(super.minus(amountToSubtract, unit)); }
@Override public ChronoLocalDateTime<D> minus(TemporalAmount amount) { return toLocalDate().getChronology().ensureChronoLocalDateTime(super.minus(amount)); }
@Override public abstract ChronoLocalDateTime<D> with(TemporalField field, long newValue);
@Override public abstract ChronoLocalDateTime<D> plus(long amountToAdd, TemporalUnit unit);
@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)); }
/** * Obtains a zoned date-time in this chronology from another temporal object. * <p> * This creates a date-time in this chronology based on the specified {@code TemporalAccessor}. * <p> * This should obtain a {@code ZoneId} using {@link ZoneId#from(TemporalAccessor)}. * The date-time should be obtained by obtaining an {@code Instant}. * If that fails, the local date-time should be used. * * @param temporal the temporal object to convert, not null * @return the zoned date-time in this chronology, not null * @throws DateTimeException if unable to create the date-time */ @SuppressWarnings({ "rawtypes", "unchecked" }) public ChronoZonedDateTime<?> zonedDateTime(TemporalAccessor temporal) { try { ZoneId zone = ZoneId.from(temporal); try { Instant instant = Instant.from(temporal); return zonedDateTime(instant, zone); } catch (DateTimeException ex1) { ChronoLocalDateTime cldt = localDateTime(temporal); ChronoLocalDateTimeImpl cldtImpl = ensureChronoLocalDateTime(cldt); return ChronoZonedDateTimeImpl.ofBest(cldtImpl, zone, null); } } catch (DateTimeException ex) { throw new DateTimeException("Unable to obtain ChronoZonedDateTime from TemporalAccessor: " + temporal.getClass(), ex); } }
@Override public ChronoLocalDateTimeImpl<D> plus(long amountToAdd, TemporalUnit unit) { if (unit instanceof ChronoUnit) { ChronoUnit f = (ChronoUnit) unit; switch (f) { case NANOS: return plusNanos(amountToAdd); case MICROS: return plusDays(amountToAdd / MICROS_PER_DAY).plusNanos((amountToAdd % MICROS_PER_DAY) * 1000); case MILLIS: return plusDays(amountToAdd / MILLIS_PER_DAY).plusNanos((amountToAdd % MILLIS_PER_DAY) * 1000000); case SECONDS: return plusSeconds(amountToAdd); case MINUTES: return plusMinutes(amountToAdd); case HOURS: return plusHours(amountToAdd); case HALF_DAYS: return plusDays(amountToAdd / 256).plusHours((amountToAdd % 256) * 12); // no overflow (256 is multiple of 2) } return with(date.plus(amountToAdd, unit), time); } return date.getChronology().ensureChronoLocalDateTime(unit.addTo(this, amountToAdd)); }