private long increment(long t) { return chronology.add(period, t, 1); }
private long truncateCompoundPeriod(long t) { long current; if (t >= origin) { long next = origin; do { current = next; next = chronology.add(period, current, 1); } while (t >= next); } else { current = origin; do { current = chronology.add(period, current, -1); } while (t < current); } return current; }
@Override public long next(long t) { return chronology.add(period, t, 1); }
/** * Returns a copy of this datetime with the specified duration added. * <p> * If the addition is zero, then <code>this</code> is returned. * * @param durationToAdd the duration to add to this one * @param scalar the amount of times to add, such as -1 to subtract once * @return a copy of this datetime with the duration added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime withDurationAdded(long durationToAdd, int scalar) { if (durationToAdd == 0 || scalar == 0) { return this; } long instant = getChronology().add(getMillis(), durationToAdd, scalar); return withMillis(instant); }
@Nonnull @Override public ExprEval eval(final ObjectBinding bindings) { return ExprEval.of(chronology.add(period, arg.eval(bindings).asLong(), step)); }
@Nonnull @Override public ExprEval eval(final ObjectBinding bindings) { final PeriodGranularity granularity = getGranularity(args, bindings); final Period period = granularity.getPeriod(); final Chronology chronology = ISOChronology.getInstance(granularity.getTimeZone()); final int step = getStep(args, bindings); return ExprEval.of(chronology.add(period, args.get(0).eval(bindings).asLong(), step)); }
/** * Adds a period to this instant specifying how many times to add. * <p> * This will typically change the value of most fields. * * @param period the period to add, null means add zero * @param scalar direction and amount to add, which may be negative * @throws ArithmeticException if the result exceeds the capacity of the instant */ public void add(ReadablePeriod period, int scalar) { if (period != null) { setMillis(getChronology().add(period, getMillis(), scalar)); // set via this class not super } }
/** * Adds a period to this instant specifying how many times to add. * <p> * This will typically change the value of most fields. * * @param period the period to add, null means add zero * @param scalar direction and amount to add, which may be negative * @throws ArithmeticException if the result exceeds the capacity of the instant */ public void add(ReadablePeriod period, int scalar) { if (period != null) { setMillis(getChronology().add(period, getMillis(), scalar)); // set via this class not super } }
/** * Gets a copy of this instant with the specified duration added. * <p> * If the addition is zero, then <code>this</code> is returned. * * @param durationToAdd the duration to add to this one * @param scalar the amount of times to add, such as -1 to subtract once * @return a copy of this instant with the duration added * @throws ArithmeticException if the new instant exceeds the capacity of a long */ public Instant withDurationAdded(long durationToAdd, int scalar) { if (durationToAdd == 0 || scalar == 0) { return this; } long instant = getChronology().add(getMillis(), durationToAdd, scalar); return withMillis(instant); }
/** * Returns a copy of this date with the specified duration added. * <p> * If the addition is zero, then <code>this</code> is returned. * * @param durationToAdd the duration to add to this one * @param scalar the amount of times to add, such as -1 to subtract once * @return a copy of this datetime with the duration added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateMidnight withDurationAdded(long durationToAdd, int scalar) { if (durationToAdd == 0 || scalar == 0) { return this; } long instant = getChronology().add(getMillis(), durationToAdd, scalar); return withMillis(instant); }
/** * Returns a copy of this date with the specified duration added. * <p> * If the addition is zero, then <code>this</code> is returned. * * @param durationToAdd the duration to add to this one * @param scalar the amount of times to add, such as -1 to subtract once * @return a copy of this datetime with the duration added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateMidnight withDurationAdded(long durationToAdd, int scalar) { if (durationToAdd == 0 || scalar == 0) { return this; } long instant = getChronology().add(getMillis(), durationToAdd, scalar); return withMillis(instant); }
/** * Creates a new interval with the specified period after the start instant. * * @param period the period to add to the start to get the new end instant, null means zero * @return an interval with the start from this interval and a calculated end * @throws IllegalArgumentException if the period is negative */ public Interval withPeriodAfterStart(ReadablePeriod period) { if (period == null) { return withDurationAfterStart(null); } Chronology chrono = getChronology(); long startMillis = getStartMillis(); long endMillis = chrono.add(period, startMillis, 1); return new Interval(startMillis, endMillis, chrono); }
/** * Creates a new interval with the specified period before the end instant. * * @param period the period to subtract from the end to get the new start instant, null means zero * @return an interval with the end from this interval and a calculated start * @throws IllegalArgumentException if the period is negative */ public Interval withPeriodBeforeEnd(ReadablePeriod period) { if (period == null) { return withDurationBeforeEnd(null); } Chronology chrono = getChronology(); long endMillis = getEndMillis(); long startMillis = chrono.add(period, endMillis, -1); return new Interval(startMillis, endMillis, chrono); }
/** * Returns a copy of this datetime with the specified duration added. * <p> * If the addition is zero, then <code>this</code> is returned. * * @param durationToAdd the duration to add to this one, null means zero * @param scalar the amount of times to add, such as -1 to subtract once * @return a copy of this datetime with the duration added * @throws ArithmeticException if the result exceeds the internal capacity */ public LocalDateTime withDurationAdded(ReadableDuration durationToAdd, int scalar) { if (durationToAdd == null || scalar == 0) { return this; } long instant = getChronology().add(getLocalMillis(), durationToAdd.getMillis(), scalar); return withLocalMillis(instant); }
/** * Sets the period of this time interval, preserving the start instant * and using the ISOChronology in the default zone for calculations. * * @param period new period for interval, null means zero length * @throws IllegalArgumentException if the end is before the start * @throws ArithmeticException if the end instant exceeds the capacity of a long */ public void setPeriodAfterStart(ReadablePeriod period) { if (period == null) { setEndMillis(getStartMillis()); } else { setEndMillis(getChronology().add(period, getStartMillis(), 1)); } }
/** * Sets the period of this time interval, preserving the end instant * and using the ISOChronology in the default zone for calculations. * * @param period new period for interval, null means zero length * @throws IllegalArgumentException if the end is before the start * @throws ArithmeticException if the start instant exceeds the capacity of a long */ public void setPeriodBeforeEnd(ReadablePeriod period) { if (period == null) { setStartMillis(getEndMillis()); } else { setStartMillis(getChronology().add(period, getEndMillis(), -1)); } }
/** * Creates a new interval with the specified duration before the end instant. * * @param duration the duration to subtract from the end to get the new start instant, null means zero * @return an interval with the end from this interval and a calculated start * @throws IllegalArgumentException if the duration is negative */ public Interval withDurationBeforeEnd(ReadableDuration duration) { long durationMillis = DateTimeUtils.getDurationMillis(duration); if (durationMillis == toDurationMillis()) { return this; } Chronology chrono = getChronology(); long endMillis = getEndMillis(); long startMillis = chrono.add(endMillis, durationMillis, -1); return new Interval(startMillis, endMillis, chrono); }
/** * Sets the period of this time interval, preserving the end instant * and using the ISOChronology in the default zone for calculations. * * @param period new period for interval, null means zero length * @throws IllegalArgumentException if the end is before the start * @throws ArithmeticException if the start instant exceeds the capacity of a long */ public void setPeriodBeforeEnd(ReadablePeriod period) { if (period == null) { setStartMillis(getEndMillis()); } else { setStartMillis(getChronology().add(period, getEndMillis(), -1)); } }
/** * Sets the period of this time interval, preserving the start instant * and using the ISOChronology in the default zone for calculations. * * @param period new period for interval, null means zero length * @throws IllegalArgumentException if the end is before the start * @throws ArithmeticException if the end instant exceeds the capacity of a long */ public void setPeriodAfterStart(ReadablePeriod period) { if (period == null) { setEndMillis(getStartMillis()); } else { setEndMillis(getChronology().add(period, getStartMillis(), 1)); } }
/** * Creates a new interval with the specified duration after the start instant. * * @param duration the duration to add to the start to get the new end instant, null means zero * @return an interval with the start from this interval and a calculated end * @throws IllegalArgumentException if the duration is negative */ public Interval withDurationAfterStart(ReadableDuration duration) { long durationMillis = DateTimeUtils.getDurationMillis(duration); if (durationMillis == toDurationMillis()) { return this; } Chronology chrono = getChronology(); long startMillis = getStartMillis(); long endMillis = chrono.add(startMillis, durationMillis, 1); return new Interval(startMillis, endMillis, chrono); }