Given a range, getting all dates within that range in Scala

前端 未结 6 1855
礼貌的吻别
礼貌的吻别 2021-02-04 03:29

I need to make a function in scala that, given a range of dates, gives me a list of the range. I am relatively new in Scala and I am not able to figure out how to write the righ

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-04 03:59

    If you happen to use the Java 1.8 DateTime API (or its 1.7 backport threeten), then you could write

    def between(fromDate: LocalDate, toDate: LocalDate) = {
        fromDate.toEpochDay.until(toDate.toEpochDay).map(LocalDate.ofEpochDay)
    } 
    

提交回复
热议问题