in modules/core/src/main/scala/org/scalasteward/core/util/dateTime.scala [48:74]
def splitDuration(d: FiniteDuration): List[FiniteDuration] = {
@tailrec
def loop(d1: FiniteDuration, acc: List[FiniteDuration]): List[FiniteDuration] =
nextUnitAndCap(d1.unit) match {
case Some((nextUnit, cap)) if d1.length >= cap =>
val next = FiniteDuration(d1.length / cap, nextUnit)
val capped = FiniteDuration(d1.length % cap, d1.unit)
if (capped.length === 0L)
loop(next, acc)
else
loop(next, capped :: acc)
case _ => d1 :: acc
}
def nextUnitAndCap(unit: TimeUnit): Option[(TimeUnit, Long)] =
unit match {
case DAYS => None
case HOURS => Some((DAYS, 24L))
case MINUTES => Some((HOURS, 60L))
case SECONDS => Some((MINUTES, 60L))
case MILLISECONDS => Some((SECONDS, 1000L))
case MICROSECONDS => Some((MILLISECONDS, 1000L))
case NANOSECONDS => Some((MICROSECONDS, 1000L))
}
loop(d, List.empty)
}