/** * Returns absolute value of the difference according to time unit. * * @param temporal1 the first {@link Temporal} * @param temporal2 the second {@link Temporal} * @return absolute value of the difference according to time unit. */ protected long getDifference(Temporal temporal1, Temporal temporal2) { return abs(unit.between(temporal1, temporal2)); }
/** * Returns absolute value of the difference according to time unit. * * @param temporal1 the first {@link Temporal} * @param temporal2 the second {@link Temporal} * @return absolute value of the difference according to time unit. */ protected long getDifference(Temporal temporal1, Temporal temporal2) { return abs(unit.between(temporal1, temporal2)); }
public long until(final Temporal endExclusive, final TemporalUnit unit) { if (unit instanceof CalendarDateUnit) { return ((CalendarDateUnit) unit).count(millis, CalendarDate.millis(endExclusive)); } else if (unit instanceof ChronoUnit) { return this.toInstant().until(endExclusive, unit); } else { return unit.between(this, endExclusive); } }
public long until(final Temporal endExclusive, final TemporalUnit unit) { if (unit instanceof CalendarDateUnit) { return ((CalendarDateUnit) unit).count(millis, CalendarDate.millis(endExclusive)); } else if (unit instanceof ChronoUnit) { return this.toInstant().until(endExclusive, unit); } else { return unit.between(this, endExclusive); } }
@Override public long until(Temporal endExclusive, TemporalUnit unit) { ChronoLocalDate end = getChronology().date(endExclusive); if (unit instanceof ChronoUnit) { return LocalDate.from(this).until(end, unit); // TODO: this is wrong } return unit.between(this, end); }
@Override public Object filter(Object var, JinjavaInterpreter interpreter, Object[] args, Map<String, Object> kwargs) { if (args.length < 2) { throw new InterpretException(String.format("%s filter requires a datetime and a string parameter", getName())); } ZonedDateTime start = getZonedDateTime(var); ZonedDateTime end = getZonedDateTime(args[0]); Object args1 = args[1]; if (!(args1 instanceof String)) { throw new InterpretException(String.format("%s filter requires a string as the second parameter", getName())); } TemporalUnit temporalUnit = BaseDateFilter.getTemporalUnit((String) args[1]); return temporalUnit.between(start, end); }
@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 long until(Temporal endExclusive, TemporalUnit unit) { LocalDate end = LocalDate.from(endExclusive); if (unit instanceof ChronoUnit) { switch ((ChronoUnit) unit) { case DAYS: return daysUntil(end); case WEEKS: return daysUntil(end) / 7; case MONTHS: return monthsUntil(end); case YEARS: return monthsUntil(end) / 12; case DECADES: return monthsUntil(end) / 120; case CENTURIES: return monthsUntil(end) / 1200; case MILLENNIA: return monthsUntil(end) / 12000; case ERAS: return end.getLong(ERA) - getLong(ERA); } throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } return unit.between(this, end); } [...] private long monthsUntil(LocalDate end) { long packed1 = getProlepticMonth() * 32L + getDayOfMonth(); // no overflow long packed2 = end.getProlepticMonth() * 32L + end.getDayOfMonth(); // no overflow return (packed2 - packed1) / 32; }
return dateTime.until(end.dateTime, unit); return unit.between(this, end);
return unit.between(this, end);
return unit.between(this, end);
return unit.between(this, end);
return unit.between(this, end);
return unit.between(this, end);
return unit.between(this, end);
return unit.between(this, end);
return unit.between(this, end);
long until(AbstractDate end, TemporalUnit unit) { if (unit instanceof ChronoUnit) { switch ((ChronoUnit) unit) { case DAYS: return daysUntil(end); case WEEKS: return weeksUntil(end); case MONTHS: return monthsUntil(end); case YEARS: return monthsUntil(end) / lengthOfYearInMonths(); case DECADES: return monthsUntil(end) / (lengthOfYearInMonths() * 10); case CENTURIES: return monthsUntil(end) / (lengthOfYearInMonths() * 100); case MILLENNIA: return monthsUntil(end) / (lengthOfYearInMonths() * 1000); case ERAS: return end.getLong(ERA) - getLong(ERA); default: break; } throw new UnsupportedTemporalTypeException("Unsupported unit: " + unit); } return unit.between(this, end); }
@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); }
return unit.between(this, end);