Is there any Date/Time DSL utils in Scala?
Asked Answered
D

3

5

I need to manipulate and calculate lots of things related to date, such as "is today?", "is before yesterday?", "now plus 3 days" etc. Is there any library or dsl in scala that can help with that? I was hoping for something with implicit conversions.

I will be using it with lift snippets, so Lift helpers works too. I saw that TimeHelpers in lift has some methods, that's a good start but I am looking for something more.

Dispirit answered 11/1, 2012 at 0:19 Comment(0)
I
7

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

Scala-time

Interviewer answered 11/1, 2012 at 1:5 Comment(0)
C
2

If you have to manipulate java.util.Date, there is also Moments

Carlinecarling answered 11/1, 2012 at 4:10 Comment(0)
T
2

I recently developed Lamma which fit your use case quite well.

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)
Terpstra answered 24/6, 2014 at 19:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.