JadiraOrg / jadira

Jadira Framework
Apache License 2.0
74 stars 44 forks source link

DateColumnLocalDateMapper toNonNullValue/fromNonNullString results vary with current time #5

Closed mattdrees closed 10 years ago

mattdrees commented 10 years ago

We ran into a problem recently caused by the combination of:

The problem arose from the fact that in toNonNullValue(Date), DateTimeZone.getOffset() is called with a null value. This causes Joda time to calculate the offset based on DateTimeUtils.currentTimeMillis(). In our case, the LocalDate being written was Oct 31 2013, before the DST transition. The code was executing post-DST transition, and the offset is now one hour less than it was on Oct 31.

As a result, adjustment was 3600000 - exactly one hour. The resulting java.sql.Date instance was therefore computed as October 30 2013 -- one day before the argument date.

I believe the best way to correct this to pass the Date argument to DateTimeZone.getOffset(). This seems to have fixed the problem for us.

PR coming shortly.

chrisphe commented 10 years ago

Matt I manually merged your fixes