Beispiel #1
0
 private void setLow(PointInTime low) {
   if (Precision.MILLISECOND.equals(low.getPrecision())) {
     this.low = low.clone();
   } else {
     this.low = low.promote().getLow();
   }
 }
Beispiel #2
0
 public Period toPeriod() {
   Period rslt =
       new Period(
           lowClosed ? low : low.addMilliseconds(1),
           highClosed ? high : high.subtractMilliseconds(1));
   return rslt;
 }
Beispiel #3
0
 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));
     }
   }
 }
Beispiel #4
0
 /**
  * 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);
 }
Beispiel #5
0
 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);
   }
 }
Beispiel #6
0
 public Period toPeriod(PeriodType periodType) {
   return new Period(
       lowClosed ? low : low.addMilliseconds(1),
       highClosed ? high : high.subtractMilliseconds(1),
       periodType);
 }
Beispiel #7
0
 public PointInTime getCenter() {
   PointInTime center = getLow().clone();
   return center.add(new Duration(getWidth().getMillis() / 2L));
 }
Beispiel #8
0
 public static IntervalOfTime untilToday(ReadablePeriod p) {
   PointInTime today = PointInTime.today();
   return new IntervalOfTime(today.subtract(p), today, true, true);
 }
Beispiel #9
0
 public static IntervalOfTime untilNow(ReadablePeriod p) {
   PointInTime now = PointInTime.now();
   return new IntervalOfTime(now.subtract(p), now, true, true);
 }
Beispiel #10
0
 public static IntervalOfTime since(PointInTime t) {
   return new IntervalOfTime(t, PointInTime.now(), true, true);
 }
Beispiel #11
0
 public static IntervalOfTime forTheNext(ReadablePeriod p) {
   PointInTime now = PointInTime.now();
   return new IntervalOfTime(now, now.add(p), true, true);
 }
Beispiel #12
0
 public static IntervalOfTime yearToDate() {
   PointInTime now = PointInTime.now();
   return new IntervalOfTime(new PointInTime(now.getYear()), now);
 }
Beispiel #13
0
 public static IntervalOfTime thisYear() {
   PointInTime today = PointInTime.today();
   return new PointInTime(today.getYear()).promote();
 }
Beispiel #14
0
 public static IntervalOfTime today() {
   return PointInTime.today().promote();
 }
Beispiel #15
0
 public int hashCode() {
   return (highClosed ? 1 : 0)
       + (lowClosed ? 1 : 0)
       + (low != null ? low.hashCode() : 0)
       + (high != null ? high.hashCode() : 0);
 }
Beispiel #16
0
 public boolean contains(PointInTime t) {
   return contains(t.promote());
 }