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