def duration()

in app/aws/Federation.scala [55:89]


  def duration(
      permission: Permission,
      requestedDuration: Option[Duration] = None,
      optClock: Option[Clock] = None
  ): Duration = {
    if (permission.shortTerm) {
      // short term permission, give them requested or default (limited by max)
      val calculated = requestedDuration.fold(defaultShortTime) { requested =>
        Date.minDuration(requested, maxShortTime)
      }
      Date.maxDuration(calculated, minShortTime)
    } else {
      // use requested or default (limited by max)
      // if nothing is requested, try to give them until 19:00 local time (requires timezone)
      val calculated = requestedDuration match {
        case None =>
          optClock.fold(defaultLongTime) { clock =>
            val now = ZonedDateTime.now(clock)
            val localEndOfWork = {
              val withTime =
                now.withHour(19).withMinute(0).withSecond(0).withNano(0)
              if (withTime.isBefore(now)) withTime.plusDays(1)
              else withTime
            }
            val durationToEndOfWork = Duration.between(now, localEndOfWork)
            if (durationToEndOfWork.compareTo(maxLongTime) < 0)
              durationToEndOfWork
            else defaultLongTime
          }
        case Some(requested) =>
          Date.minDuration(requested, maxLongTime)
      }
      Date.maxDuration(calculated, minLongTime)
    }
  }