scalaplayframeworkconfigurationhocon

Scala + Play, how to get a duration from the HOCON configuration?


Imagine I have a Duration value defined in my application.conf file. The documentation says it can parse Durations, but I can't see how.

timeout = 60 milliseconds

Can I parse it directly as a duration value? Ideally I would like to do something like this

val timeout = current.configuration.getMilliseconds("timeout")
(myActor ? GiveMeSomething)(timeout).mapTo[...]

but timeout is an Option[Long]. Thanks for any tips.


Solution

  • I don't believe you can parse it directly as a duration value.

    I usually have a helper class/method that does it for me, similar to this: http://pierreandrews.net/posts/config-scala.html