DateRange buildShiftedRange(DateRange rawRange,long cadence,long now){
  if (rawRange.getStart() > now) {
    throw new IllegalArgumentException("start is greater than now");
  }
  final DateRange rounded=rawRange.rounded(cadence);
  final long nowDelta=now - rounded.getEnd();
  if (nowDelta > SHIFT_TOLERANCE) {
    return rounded;
  }
  final long diff=Math.abs(Math.min(nowDelta,0)) + SHIFT_TOLERANCE;
  return rounded.shift(-toleranceShiftPeriod(diff,cadence));
}

DateRange buildShiftedRange ( DateRange rawRange , long cadence , long now ) { if ( rawRange . getStart ( ) > now ) { throw new IllegalArgumentException ( "start is greater than now" ) ; } final DateRange rounded = rawRange . rounded ( cadence ) ; final long nowDelta = now - rounded . getEnd ( ) ; if ( nowDelta > SHIFT_TOLERANCE ) { return rounded ; } final long diff = Math . abs ( Math . min ( nowDelta , 0 ) ) + SHIFT_TOLERANCE ; return rounded . shift ( - toleranceShiftPeriod ( diff , cadence ) ) ; }
given a range and a cadence , return a range that might be shifted in case the end period is too close or after ' now ' . this is useful to avoid querying non - complete buckets .
