Written by Roy van Rijn (royvanrijn.com) on
Dec 15, 2015 15:00:41
: 0 comments
Google Guava: Range with LocalDate
This afternoon I was working on implementing a user story with (JodaTime) LocalDate ranges. The problem? I needed to represent a lot of periods, in days. The thing I needed to check: Is a certain LocalDate contained in this period.
It works, sure, but the conversion to ReadableInstant with toDateTimeAtStartOfDay kind of bugged me. But luckely Google Guava has something to make the code much cleaner: Ranges
Using Range made the code much smaller and easier to read:
I really love using Google Guava, it provides solutions for a lot of common programming challenges. Not only that, their API is very very clean and skillfully designed. The use of open/closed in Range.java is very handy and makes it easy to think about corner cases.