static ChronoPeriod between(ChronoLocalDate startDateInclusive, ChronoLocalDate endDateExclusive) { return startDateInclusive.until(endDateExclusive); }
/** * Obtains a {@code ChronoPeriod} consisting of amount of time between two dates. * <p> * The start date is included, but the end date is not. * The period is calculated using {@link ChronoLocalDate#until(ChronoLocalDate)}. * As such, the calculation is chronology specific. * <p> * The chronology of the first date is used. * The chronology of the second date is ignored, with the date being converted * to the target chronology system before the calculation starts. * <p> * The result of this method can be a negative period if the end is before the start. * In most cases, the positive/negative sign will be the same in each of the supported fields. * * @param startDateInclusive the start date, inclusive, specifying the chronology of the calculation, not null * @param endDateExclusive the end date, exclusive, in any chronology, not null * @return the period between this date and the end date, not null * @see ChronoLocalDate#until(ChronoLocalDate) */ public static ChronoPeriod between(ChronoLocalDate startDateInclusive, ChronoLocalDate endDateExclusive) { Jdk8Methods.requireNonNull(startDateInclusive, "startDateInclusive"); Jdk8Methods.requireNonNull(endDateExclusive, "endDateExclusive"); return startDateInclusive.until(endDateExclusive); }
@Override public long until(Temporal endExclusive, TemporalUnit unit) { @SuppressWarnings("unchecked") ChronoLocalDateTime<D> end = (ChronoLocalDateTime<D>) toLocalDate().getChronology().localDateTime(endExclusive); if (unit instanceof ChronoUnit) { ChronoUnit f = (ChronoUnit) unit; if (f.isTimeBased()) { long amount = end.getLong(EPOCH_DAY) - date.getLong(EPOCH_DAY); switch (f) { case NANOS: amount = Jdk8Methods.safeMultiply(amount, NANOS_PER_DAY); break; case MICROS: amount = Jdk8Methods.safeMultiply(amount, MICROS_PER_DAY); break; case MILLIS: amount = Jdk8Methods.safeMultiply(amount, MILLIS_PER_DAY); break; case SECONDS: amount = Jdk8Methods.safeMultiply(amount, SECONDS_PER_DAY); break; case MINUTES: amount = Jdk8Methods.safeMultiply(amount, MINUTES_PER_DAY); break; case HOURS: amount = Jdk8Methods.safeMultiply(amount, HOURS_PER_DAY); break; case HALF_DAYS: amount = Jdk8Methods.safeMultiply(amount, 2); break; } return Jdk8Methods.safeAdd(amount, time.until(end.toLocalTime(), unit)); } ChronoLocalDate endDate = end.toLocalDate(); if (end.toLocalTime().isBefore(time)) { endDate = endDate.minus(1, ChronoUnit.DAYS); } return date.until(endDate, unit); } return unit.between(this, end); }