I'm trying to calculate the time from various dates since a specific period start date. Calculating the dates since was fine and easy, but I also want the function to return -1 if the dates between them is negative. I'm not sure a clean way to do this? I've got:
def getTimeBetween(date1: String, date2: String, format: String, dtype: String): Int = { dtype match { case "fixed" => { if (date1 == null) throw new Exception("Specify date1") else Days.daysBetween(date2, date1).getDays() } case _ => throw new Exception("Enter a valid type") } } I'm pretty new to Scala so I don't know all the syntax well yet. I'm more used to Java/C++, so I thought next if/else statements would work but I've realized it's not the way to go.
Thanks.
typeis a keyword in scala so you cannot use it as a variable. Secondly, can you use a library likejoda.timeor are you restricted to primitive types?DateTimetypes?