def replaceVariable()

in s2core/src/main/scala/org/apache/s2graph/core/rest/RequestParser.scala [74:99]


  def replaceVariable(now: Long, body: String): String = {
    findVar.replaceAllIn(body, m => {
      val matched = m group 1
      randIntRegex.findFirstMatchIn(matched) match {
        case None =>
          num.replaceSomeIn(matched, m => {
            val (_pivot, n, unit) = (m.group(1), m.group(2), m.group(3))
            val ts = _pivot match {
              case null => now
              case "now" | "NOW" => now
              case "next_minute" | "NEXT_MINUTE" => now / minute * minute + minute
              case "next_week" | "NEXT_WEEK" => now / week * week + week
              case "next_day" | "NEXT_DAY" => now / day * day + day
              case "next_hour" | "NEXT_HOUR" => now / hour * hour + hour
            }

            if (_pivot == null && n == null && unit == null) None
            else if (n == null || unit == null) Option(ts.toString)
            else Option(calculate(ts, n.replaceAll(" ", "").toInt, unit).toString)
          })
        case Some(m) =>
          val range = m group 1
          randInt(range).toString
      }
    })
  }