Skip to content

Instantly share code, notes, and snippets.

@crocker
Created September 15, 2016 21:51
Show Gist options
  • Save crocker/806fc453e0e1f8684bb00a2d9f6c503d to your computer and use it in GitHub Desktop.
Save crocker/806fc453e0e1f8684bb00a2d9f6c503d to your computer and use it in GitHub Desktop.
def getDateRange(year: Int, week: Int): (LocalDate, LocalDate) = {
val date = new LocalDate().withYear(year).withWeekOfWeekyear(week)
val startDate = date.withDayOfWeek(1)
val endDate = date.withDayOfWeek(7)
(startDate, endDate)
}
val dateFormat = "yyyy-MM-dd E"
val year = 2016
for(week <- 1 to 52) {
val range = getDateRange(year, week)
val previousRange = getDateRange(year-1, week)
println(s"Week ${week}: ${range._1.toString(dateFormat)} - ${range._2.toString(dateFormat)} | ${previousRange._1.toString(dateFormat)} - ${previousRange._2.toString(dateFormat)}")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment