Skip to content
Permalink
Browse files
Merge pull request #1 from markvanveen/develop
Use valueOf instead of epoch days
  • Loading branch information
markvanveen committed Sep 14, 2017
2 parents a42774c + 60d32e1 commit e4ce9905b2b60bdf11ec492d72b3d8705398241d
Showing 2 changed files with 44 additions and 4 deletions.
@@ -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 Date convertToDatabaseColumn(final LocalDate attribute) {
if (attribute == null) {
return null;
} else {
return new Date(DateConverter.toEpochDay(attribute));
return Date.valueOf(attribute);
}
}

@@ -43,7 +41,7 @@ public LocalDate convertToEntityAttribute(final Date dbData) {
if (dbData == null) {
return null;
} else {
return DateConverter.toLocalDate(DateConverter.fromEpochMillis(dbData.getTime()));
return dbData.toLocalDate();
}
}
}
@@ -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);
}
}

0 comments on commit e4ce990

Please sign in to comment.