I have been looking around but I have not found anything useful. Are there any 3rd party libraries that work with hamcrest that have extensive date matching?
Specifically I am looking for matchers along the lines of:
assertThat(myDate, is(withinMinutes(sourceDate, 10)));
assertThat(myDate, is(afterDate(sourceDate)));
assertThat(myDate, is(betweenDates(startDate, endDate)));
I wanted to see if there was anything out there before I rolled my own.
I've written a set of date matchers which look like what you're after. The source is here https://github.com/eXparity/hamcrest-date. An example of how to use the within matcher
assertThat(dateUnderTest, DateMatchers.within(2, TimeUnit.SECONDS, new Date()));
You can add it with maven adding this to your pom.xml
<dependency>
<groupId>org.exparity</groupId>
<artifactId>hamcrest-date</artifactId>
<version>2.0.1</version>
</dependency>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With