Created
February 23, 2016 15:58
-
-
Save Fristi/d242c099ec78789bdcf6 to your computer and use it in GitHub Desktop.
Get week intervals for a specified period
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import org.joda.time.{Interval, Period, DateTime} | |
| object Main { | |
| def getWeeks(startDate: DateTime, endDate: DateTime) = { | |
| val weekPeriod = new Period().withWeeks(1) | |
| def loop(current: Interval, weeks: Seq[Interval]): Seq[Interval] = { | |
| if(current.getEnd.isBefore(endDate)) { | |
| loop(new Interval(current.getStart.plus(weekPeriod), weekPeriod), weeks :+ current) | |
| } else { | |
| weeks | |
| } | |
| } | |
| loop(new Interval(startDate, weekPeriod), Seq.empty) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment