eXparity / hamcrest-date

A Java library which provides a suite hamcrest matchers for matching dates, times, and moments in time
BSD 3-Clause "New" or "Revised" License
70 stars 11 forks source link

Add support for java.sql.Timestamp #12

Closed sorinello closed 9 years ago

sorinello commented 9 years ago

Hello Stewart :) Let me explain my usage. We are using DAO to create objects by querying the DB. The Java Beans which model a record use java.sql.Timestamp to store the dates. We do not use java.util.Date nor Joda Time since the java date type corresponding to the DB date is Timestamp.

It would be a nice improvement if the matchers could also support java.sql.Timestamp. Internally, the matcher could convert/cast from Timestamp to Date and then use it.

This change should not add new Maven/external dependencies since java.sql.Timestamp is already included in the Java Runtime.

stewbis commented 9 years ago

Hi Sorin, Nice to see you're finding a few of my libs useful :). In many cases I'd expect java.sql.timestamp to work with many of the matchers already because it's a subclass of java.util.Date. Do you have a code snippet or simple test which illustrates the use case you had in mind. (I've tried locally testing a couple of things e.g. sameInstant, sameDate, etc and they call compiled and passed OK). Thanks Stewart

sorinello commented 9 years ago

Hello Stewart,

It seems to be working. I had some errors when using the before and after matcher, but I was getting another error, but not related to the matcher :) Now I am trying to figure out how the matcher works, since the java Generics accept only Date type. I can't find any mention or Java Generics usage like Matcher<? extends Date>. Also, the method public static Matcher<Date> before(final Date date) specifies a Date type. So where is the cast to Timestamp being made ? :)

You can close the issue and sorry for the noise :)

stewbis commented 9 years ago

Hi Sorin, java.sql.Timestamp extends java.util.Date so passing in Timestamp still matches the signature of the matcher which is why it's working OK. I'll close the issue. Thanks Stewart