def getTimeRange()

in s2counter_core/src/main/scala/org/apache/s2graph/counter/core/TimedQualifier.scala [198:233]


  def getTimeRange(intervals: Seq[IntervalUnit],
                   limit: Int,
                   optFrom: Option[Long],
                   optTo: Option[Long]): Seq[(TimedQualifier, TimedQualifier)] = {
    val newLimit = limit - 1
    val maxInterval = intervals.maxBy {
      case MINUTELY => 0
      case HOURLY => 1
      case DAILY => 2
      case MONTHLY => 3
      case TOTAL => 4
    }
    val minInterval = intervals.minBy {
      case MINUTELY => 0
      case HOURLY => 1
      case DAILY => 2
      case MONTHLY => 3
      case TOTAL => 4
    }
    val (from, to) = (optFrom, optTo) match {
      case (Some(f), Some(t)) =>
        (f, t)
      case (Some(f), None) =>
        (f, nextTime(minInterval, f, newLimit))
      case (None, Some(t)) =>
        (nextTime(maxInterval, t, -newLimit), t)
      case (None, None) =>
        val current = System.currentTimeMillis()
        (nextTime(maxInterval, current, -newLimit), nextTime(minInterval, current, 0))
    }
    for {
      interval <- intervals
    } yield {
      (TimedQualifier(interval, from), TimedQualifier(interval, to))
    }
  }