Skip to content

Instantly share code, notes, and snippets.

@facundofarias
Last active October 31, 2016 14:37
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 facundofarias/8914939c72de6b7d47f2f23cbacf35d0 to your computer and use it in GitHub Desktop.
Save facundofarias/8914939c72de6b7d47f2f23cbacf35d0 to your computer and use it in GitHub Desktop.
Split JodaTime Interval into intervals
private static Collection<Interval> splitDuration(Interval interval, int chunks)
{
long startMillis = interval.getStartMillis();
long endMillis = interval.getEndMillis();
long durationMillis = endMillis - startMillis;
long chunkSize = durationMillis / chunks;
Collection<Interval> list = new ArrayList<Interval>();
for (int i = 1; i <= chunks; ++i) {
list.add(new Interval(startMillis, startMillis += chunkSize));
}
return list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment