in util-core/src/main/scala/com/twitter/util/Duration.scala [232:266]
def parse(s: String): Duration = {
val ss = s.toLowerCase
ss match {
case FullDurationRegex(_*) =>
SingleDurationRegex.findAllIn(ss).matchData.zipWithIndex map {
case (m, i) =>
val List(signStr, numStr, unitStr, special) = m.subgroups
val absDuration = special match {
case "top" => Top
case "bottom" => Bottom
case "undefined" => Undefined
case _ =>
val u = nameToUnit.get(unitStr) match {
case Some(t) => t
case None => throw new NumberFormatException("Invalid unit: " + unitStr)
}
Duration(numStr.toLong, u)
}
signStr match {
case "-" => -absDuration
// It's only OK to omit the sign for the first duration.
case "" if i > 0 =>
throw new NumberFormatException("Expected a sign between durations")
case _ => absDuration
}
// It's OK to use reduce because the regex ensures that there is
// at least one element
} reduce { _ + _ }
case _ => throw new NumberFormatException("Invalid duration: " + s)
}
}