Skip to content

Add a converter for Duration #85

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
johanandren opened this issue Jan 20, 2017 · 6 comments
Closed

Add a converter for Duration #85

johanandren opened this issue Jan 20, 2017 · 6 comments

Comments

@johanandren
Copy link
Contributor

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)

@Ichoran
Copy link
Contributor

Ichoran commented Jan 21, 2017

Sounds like a good idea to me.

@johanandren
Copy link
Contributor Author

@SethTisue any chance of getting this in?

@synox
Copy link

synox commented Jul 13, 2017

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

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

@johanandren
Copy link
Contributor Author

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
Copy link

synox commented Jul 13, 2017

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

johanandren added a commit to johanandren/scala-java8-compat that referenced this issue Apr 30, 2018
@SethTisue
Copy link
Member

#86 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants