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

前端 未结 6 1867
礼貌的吻别
礼貌的吻别 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 04:00

    Use Lamma Date

    $ scala -cp lamma_2.11-1.1.2.jar 
    Welcome to Scala version 2.11.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
    Type in expressions to have them evaluated.
    Type :help for more information.
    
    scala> import io.lamma.Date
    import io.lamma.Date
    
    scala> Date(2015, 7, 7) to Date(2015, 7, 10) foreach println 
    Date(2015,7,7)
    Date(2015,7,8)
    Date(2015,7,9)
    Date(2015,7,10)
    

    This DateRange is evaluated in a lazy way. Feel free to construct a date range of 5000 years. :)

提交回复
热议问题