This is an automated email from the ASF dual-hosted git repository.

ikamga pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/fineract-cn-mariadb.git

commit 60d32e11e4904547482a4a7b195b31d2b7df8bf3
Author: Mark <[email protected]>
AuthorDate: Thu Sep 14 19:20:38 2017 +0200

    Use valueOf instead of epoch days
    Add tiny unit test
---
 .../core/mariadb/util/LocalDateConverter.java      |  6 ++--
 .../core/mariadb/util/LocalDateConverterTest.java  | 42 ++++++++++++++++++++++
 2 files changed, 44 insertions(+), 4 deletions(-)

diff --git a/src/main/java/io/mifos/core/mariadb/util/LocalDateConverter.java 
b/src/main/java/io/mifos/core/mariadb/util/LocalDateConverter.java
index 73b4f0b..a31c593 100644
--- a/src/main/java/io/mifos/core/mariadb/util/LocalDateConverter.java
+++ b/src/main/java/io/mifos/core/mariadb/util/LocalDateConverter.java
@@ -15,8 +15,6 @@
  */
 package io.mifos.core.mariadb.util;
 
-import io.mifos.core.lang.DateConverter;
-
 import javax.persistence.AttributeConverter;
 import javax.persistence.Converter;
 import java.sql.Date;
@@ -34,7 +32,7 @@ public class LocalDateConverter implements 
AttributeConverter<LocalDate, Date> {
     if (attribute == null) {
       return null;
     } else {
-      return new Date(DateConverter.toEpochDay(attribute));
+      return Date.valueOf(attribute);
     }
   }
 
@@ -43,7 +41,7 @@ public class LocalDateConverter implements 
AttributeConverter<LocalDate, Date> {
     if (dbData == null) {
       return null;
     } else {
-      return 
DateConverter.toLocalDate(DateConverter.fromEpochMillis(dbData.getTime()));
+      return dbData.toLocalDate();
     }
   }
 }
diff --git 
a/src/test/java/io/mifos/core/mariadb/util/LocalDateConverterTest.java 
b/src/test/java/io/mifos/core/mariadb/util/LocalDateConverterTest.java
new file mode 100644
index 0000000..6713ebd
--- /dev/null
+++ b/src/test/java/io/mifos/core/mariadb/util/LocalDateConverterTest.java
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2016 The Mifos Initiative.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package io.mifos.core.mariadb.util;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.sql.Date;
+import java.time.LocalDate;
+
+public class LocalDateConverterTest {
+
+  public LocalDateConverterTest() {
+    super();
+  }
+
+  @Test
+  public void shouldConvertLocalDate() {
+    final LocalDateConverter converter = new LocalDateConverter();
+
+    final LocalDate expected = LocalDate.of(2017, 1, 1);
+
+    final Date dbDate = converter.convertToDatabaseColumn(expected);
+
+    final LocalDate result = converter.convertToEntityAttribute(dbDate);
+
+    Assert.assertEquals(expected, result);
+  }
+}

Reply via email to