Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert Long to Duration (import scala.concurrent.duration) in SCALA

Tags:

scala

akka

actor

I am a begginer programmer and have a very simple problem in scala, I want to convert a long var to Duration (import scala.concurrent.duration.Duration, import scala.concurrent.duration), in order to fit this code.

listener ! PiApproximation(pi, duration = (System.currentTimeMillis - start).millis)

Eclipse throws me the error that millis its not a member of Long, I am doing a tutorial for learning how to programme in Scala with Akka (https://github.com/fhelg/AkkaPlayGround/blob/master/PingPongApp.scala). And I think the code its correct, but i cant compile it because of that.

Any ideas? Many thanks in advance.

PD: My apologies for the bad english! I am from spain and we are not that good at language learning :P!

like image 738
c0mrade92Brz Avatar asked Mar 26 '14 11:03

c0mrade92Brz


1 Answers

Scala provides implicit conversions which automatically/implicitly convert Ints and Longs:

scala> import scala.concurrent.duration._
import scala.concurrent.duration._

scala> (System.currentTimeMillis - 1234567890).millis
res0: scala.concurrent.duration.FiniteDuration = 1394598256075 milliseconds
like image 146
yǝsʞǝla Avatar answered Nov 20 '22 12:11

yǝsʞǝla