Skip to content

Instantly share code, notes, and snippets.

@lloydmeta
Created June 15, 2021 03:11
Show Gist options
  • Save lloydmeta/7e89b72f13bf9c8cdda395b9104db968 to your computer and use it in GitHub Desktop.
Save lloydmeta/7e89b72f13bf9c8cdda395b9104db968 to your computer and use it in GitHub Desktop.
Scala Duration (incl FiniteDuration) pretty print in a way that can be parsed by `Duration.apply`
object PrettyDuration {
import scala.concurrent.duration._
def show(duration: Duration): String = {
if (Duration.Inf == duration) {
"Inf"
} else if (Duration.MinusInf == duration) {
"MinusInf"
} else {
duration.toCoarsest.toString
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment