Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to substract a day/hour/minute from joda-time DateTime in Scala?

I am trying to use joda-time with its Scala wrapper.

Saying val dt is a DateTime and contains a date (zero time), how do I get the date of the day befor it? dt - 1.days doesn't work and gives

"type mismatch" ("found: org.scala_tools.time.Imports.DateTime, required: ?{val -:?}").

Scala-time examples like 2.hours + 45.minutes + 10.seconds don't work either saying that hours is not a member of an Int.

Joda-time examples like DateTime.dayOfWeek().addToCopy(3) don't work either as dayOfWeek, for example, is not a member of org.scala_tools.time.Imports.DateTime.

Formatted DateTimeinput and output seem to work as meant.

UPDATE: Seems to be a bug of NetBeans IDE.It shows the error, while compiler compiles ok and the program works as expected with dt - 1.days syntax.

like image 313
Ivan Avatar asked Sep 03 '10 22:09

Ivan


2 Answers

Seems to be a bug of NetBeans IDE. It shows the error, while compiler compiles ok and the program works as expected with "dt - 1.days" syntax.

like image 116
Ivan Avatar answered Oct 07 '22 01:10

Ivan


It seems that the code cannot find the implicit conversions. Are you sure you import org.scala_tools.time.Imports._ in the scope that you are using it?

like image 34
Peter Tillemans Avatar answered Oct 07 '22 00:10

Peter Tillemans