scala/scala-java8-compat

Add a converter for Duration

johanandren opened this issue · 6 comments

For converting between java.time.Duration and scala.concurrent.Duration. Use case is to make it easier for Java devs using Akka to use the Java duration in their Java code without us having to provide parallell APIs everywhere there is a duration.

Any objections to such a PR?

(We'd need to backport to 0.7 to use it in Akka for binary comp. reasons)

Sounds like a good idea to me.

@SethTisue any chance of getting this in?

synox commented

The PR #86 seems overly complicated.
Why not just? :

    public static FiniteDuration toScala(java.time.Duration javaDuration) {
        return Duration.fromNanos(javaDuration.toNanos());
    }

Was a while ago, as far as I recall it j.t.Duration expresses time as long seconds with an int nanos part, while FiniteDuration express time as a long value and a unit. Which means that the max value for a java duration does not fit in as a long nanoseconds, but does fit as a long with the unit seconds.

Likely not a problem if your code is mostly scheduling for example Akka events, but may be a problem in other contexts.

synox commented

Good Point. j.t.Duration could cover 292.5 billion years, while j.t.Duration.toNanos() overflows at 292.5 years.

#86 is merged