Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dayIterator(start: DateTime, end: DateTime, period: String) = {
- period match {
- case "day" => Iterator.iterate(start)((_ plusDays 1)) takeWhile (_ isBefore end)
- case "week" => Iterator.iterate(start)(_ plusWeeks 1) takeWhile (_ isBefore end)
- case "month" => Iterator.iterate(start)(_ plusMonths 1) takeWhile (_ isBefore end)
- }
- }
- scala> dayIterator(new DateTime("2017-09-13"), new DateTime("2017-09-27"), "week").foreach(println)
- 2017-09-13T00:00:00.000+05:30
- 2017-09-20T00:00:00.000+05:30
- 2017-09-13T00:00:00.000+05:30 (Wednesday) -- 2017-09-17T00:00:00.000+05:30 (Sunday)
- 2017-09-18T00:00:00.000+05:30 (Monday) -- 2017-09-24T00:00:00.000+05:30 (Sunday)
- 2017-09-25T00:00:00.000+05:30 (Monday) -- 2017-09-27T00:00:00.000+05:30 (Wednesday)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement