Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@pr1001
Created November 9, 2011 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pr1001/1351495 to your computer and use it in GitHub Desktop.
Save pr1001/1351495 to your computer and use it in GitHub Desktop.
I need to tell the Dutch government how often I'm out of the country when I renew my permit. Luckily ScalaTime makes that easy to calculate.
import org.joda.time._
import org.scala_tools.time.Imports._
// do +1 day to be inclusive on start and end days
val intervals = List (
// One Day
new DateMidnight(2011, 1, 19) to (new DateMidnight(2011, 1, 19) + 1.day),
// Several Days
new DateMidnight(2011, 2, 5) to (new DateMidnight(2011, 2, 13) + 1.day)
)
val totalDays = intervals.map(Days.daysIn(_).getDays).reduceLeft(_ + _)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment