diff --git a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDate.java b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDate.java index 529aaf8b3..9ea509384 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDate.java +++ b/src/main/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDate.java @@ -1,12 +1,11 @@ package com.avaje.ebeaninternal.server.type; +import com.avaje.ebeaninternal.server.core.BasicTypeConverter; +import org.joda.time.LocalDate; + import java.sql.Date; import java.sql.Types; -import org.joda.time.LocalDate; - -import com.avaje.ebeaninternal.server.core.BasicTypeConverter; - /** * ScalarType for Joda LocalDate. This maps to a JDBC Date. */ @@ -28,7 +27,7 @@ public class ScalarTypeJodaLocalDate extends ScalarTypeBaseDate { @Override public Date convertToDate(LocalDate t) { - return new java.sql.Date(t.toDateMidnight().getMillis()); + return new java.sql.Date(t.toDateTimeAtStartOfDay().getMillis()); } @Override diff --git a/src/test/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDateTest.java b/src/test/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDateTest.java new file mode 100644 index 000000000..83e8f85a9 --- /dev/null +++ b/src/test/java/com/avaje/ebeaninternal/server/type/ScalarTypeJodaLocalDateTest.java @@ -0,0 +1,56 @@ +package com.avaje.ebeaninternal.server.type; + +import org.joda.time.LocalDate; +import org.junit.Test; + +import java.sql.Date; + +import static org.assertj.core.api.Assertions.assertThat; + + +public class ScalarTypeJodaLocalDateTest { + + ScalarTypeJodaLocalDate type = new ScalarTypeJodaLocalDate(); + + @Test + public void convertToMillis_convertFromMillis() throws Exception { + + LocalDate localDate = new LocalDate(); + long millis = type.convertToMillis(localDate); + LocalDate localDate1 = type.convertFromMillis(millis); + + assertThat(localDate).isEqualTo(localDate1); + } + + @Test + public void convertToDate_convertFromDate() throws Exception { + + LocalDate localDate = new LocalDate(); + Date dateValue = type.convertToDate(localDate); + LocalDate localDate1 = type.convertFromDate(dateValue); + + assertThat(localDate).isEqualTo(localDate1); + } + + + @Test + public void toJdbcType() throws Exception { + + LocalDate localDate = new LocalDate(); + Object jdbcType = type.toJdbcType(localDate); + Date dateValue = type.convertToDate(localDate); + + assertThat(jdbcType).isEqualTo(dateValue); + } + + @Test + public void toBeanType() throws Exception { + + LocalDate localDate = new LocalDate(); + Date dateValue = type.convertToDate(localDate); + LocalDate beanType = type.toBeanType(dateValue); + + assertThat(beanType).isEqualTo(localDate); + } + +} \ No newline at end of file