private void setLow(PointInTime low) { if (Precision.MILLISECOND.equals(low.getPrecision())) { this.low = low.clone(); } else { this.low = low.promote().getLow(); } }
public Period toPeriod() { Period rslt = new Period( lowClosed ? low : low.addMilliseconds(1), highClosed ? high : high.subtractMilliseconds(1)); return rslt; }
private void setHigh(PointInTime high) { if (Precision.MILLISECOND.equals(high.getPrecision())) { this.high = high.clone(); } else { this.high = high.promote().getHigh(); if (isHighClosed()) { this.high = this.high.subtract(Period.millis(1)); } } }
/** * Returns an IntervalOfTime that has both endpoints closed. If the low endpoint is open it will * move it forward by one millisecond. If the high endpoint is closed, it will move it backward by * one millisecond. * * @return an IntervalOfTime with closed endpoints baed on the endpoints of this interval. */ public IntervalOfTime toClosed() { PointInTime t1 = getLow(); if (!isLowClosed()) { t1 = t1.addMilliseconds(1); } PointInTime t2 = getHigh(); if (!isHighClosed()) { t2 = t2.subtractMilliseconds(1); } return new IntervalOfTime(t1, t2, true, true); }
public IntervalOfTime( PointInTime low, PointInTime high, boolean lowClosed, boolean highClosed, boolean equalEndpointsAllowed) { if (high.equals(low) && !equalEndpointsAllowed) { throw new IllegalArgumentException( "The end point should be unequal to the low point in time when equalEndpointsAllowed is false"); } this.lowClosed = lowClosed; this.highClosed = highClosed; if (low.after(high)) { setLow(high); setHigh(low); } else { setLow(low); setHigh(high); } }
public Period toPeriod(PeriodType periodType) { return new Period( lowClosed ? low : low.addMilliseconds(1), highClosed ? high : high.subtractMilliseconds(1), periodType); }
public PointInTime getCenter() { PointInTime center = getLow().clone(); return center.add(new Duration(getWidth().getMillis() / 2L)); }
public static IntervalOfTime untilToday(ReadablePeriod p) { PointInTime today = PointInTime.today(); return new IntervalOfTime(today.subtract(p), today, true, true); }
public static IntervalOfTime untilNow(ReadablePeriod p) { PointInTime now = PointInTime.now(); return new IntervalOfTime(now.subtract(p), now, true, true); }
public static IntervalOfTime since(PointInTime t) { return new IntervalOfTime(t, PointInTime.now(), true, true); }
public static IntervalOfTime forTheNext(ReadablePeriod p) { PointInTime now = PointInTime.now(); return new IntervalOfTime(now, now.add(p), true, true); }
public static IntervalOfTime yearToDate() { PointInTime now = PointInTime.now(); return new IntervalOfTime(new PointInTime(now.getYear()), now); }
public static IntervalOfTime thisYear() { PointInTime today = PointInTime.today(); return new PointInTime(today.getYear()).promote(); }
public static IntervalOfTime today() { return PointInTime.today().promote(); }
public int hashCode() { return (highClosed ? 1 : 0) + (lowClosed ? 1 : 0) + (low != null ? low.hashCode() : 0) + (high != null ? high.hashCode() : 0); }
public boolean contains(PointInTime t) { return contains(t.promote()); }