0

I wrote a method to iterate over a range of dates and to return a Set[Date]. But after I convert an iterator to Set[Date] there is an Error:

Expression of type scala.collection.immutable.Set[java.util.Date] doesn't conform to expected type scala.Predef.Set[java.sql.Date]

def createDateRange(start: Date, end: Date): Set[Date] = {
  val datesIterator: Iterator[LocalDate] = Iterator
    .iterate(new LocalDate(start))(_ plusDays 1) takeWhile (_ isBefore new LocalDate(end))
  datesIterator.toSet.map(x => x.toDateTimeAtStartOfDay.toDate)

}

As I understand, toDateTimeAtStartOfDay.toDate returns java.util.Date but I need a java.sql.Date.

Is there a better way to get a range of dates by just using a java.sql.Date?

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
samba
  • 2,821
  • 6
  • 30
  • 85
  • 1
    Since you just need to convert from LocalDate to java.sql.Date: https://stackoverflow.com/questions/29750861/convert-between-localdate-and-sql-date – Alexey Romanov Jul 19 '19 at 11:36
  • Why not take the step and throw the outdated `java.util.Date` and `java.sql.Date` as well as the finished Joda-Time project overboard and use [java.time, the modern Java date and time API,](https://docs.oracle.com/javase/tutorial/datetime/) throughout? – Ole V.V. Jul 20 '19 at 06:24

0 Answers0