I'm trying to create a way to add days to a LocalDate object in Scala through implicit classes, but I continually get an error either saying "LocalDate is a final class and cannot be extended" or below:
scala:73: could not find implicit value for parameter year: Int
Here's the code I tried using:
implicit class UVMLocalDate(val me: Int) extends AnyVal{
implicit def days(implicit year: Int, month: Int, day: Int) {
LocalDate.of(year,month,me + days)
}
}
I'm restricted to having the class behave like so:
(LocalDate.of(2015, 4, 14)) == (LocalDate.of(2015, 4, 12) + 2.days)
Example use:
val dateEx = LocalDate.of(2015, 3, 23) + 2.days
assert(dateEx == LocalDate.of(2015, 3, 25))
Thanks
LocalDate
s together. It also doesn't provide a Scala+
method. – Teo Klestrup Röijezondays
method would be immensely helpful. – Angelo Genovese