Is there a DSL utils date / time in Scala?

I need to manipulate and calculate a lot of things related to the date, such as “today?”, “Until yesterday?”, “Now plus 3 days”, etc. Is there a library or dsl in scala that can help with this? I was hoping for something with implicit conversions.

I will use it with elevators, so the Lift assistants also work. I saw that TimeHelpers in the elevator has some methods, this is a good start, but I'm looking for something else.

+5
source share
3 answers

You can use the following scala shell for joda-time.

Scala-time

+7
source

If you need to manipulate java.util.Date, there are also Moments

+2

Lamma, .

scala> import io.lamma._   // import at begining
import io.lamma._

scala> Date(2014, 7, 10) - Date(2014, 7, 3)   // calculate date difference
res5: Int = 7

scala> (2014, 7, 10) - (2014, 7, 3)  // implicit conversion from (Int, Int, Int)
res6: Int = 7

scala> (2014, 7, 10) + 3    // plus 3 days
res7: io.lamma.Date = Date(2014,7,13)

scala> (2014, 7, 10) + 5.weeks   // plus 5 weeks
res8: io.lamma.Date = Date(2014,8,14)

scala> (2014, 7, 10) + (5 weeks)   // this will work too
res9: io.lamma.Date = Date(2014,8,14)

scala> (2014, 7, 10) + (10 years)   // another expression
res10: io.lamma.Date = Date(2024,7,10)
+2

All Articles