Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes TimeColumnLocalTimeMapper #84

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,16 @@
*/
package org.jadira.usertype.dateandtime.threeten.columnmapper;

import org.jadira.usertype.spi.shared.AbstractTimeColumnMapper;

import java.sql.Time;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeFormatterBuilder;

import org.jadira.usertype.spi.shared.AbstractTimeColumnMapper;

public class TimeColumnLocalTimeMapper extends AbstractTimeColumnMapper<LocalTime> {
public class TimeColumnLocalTimeMapper extends AbstractTimeColumnMapper<LocalTime>
{

private static final long serialVersionUID = 6734385103313158326L;

public static final DateTimeFormatter LOCAL_TIME_FORMATTER = new DateTimeFormatterBuilder().appendPattern("HH:mm:ss").toFormatter();


public TimeColumnLocalTimeMapper() {
}
Expand All @@ -49,13 +46,8 @@ public String toNonNullString(LocalTime value) {
}

@Override
public Time toNonNullValue(LocalTime value) {

LocalDateTime localDateTime = LocalDateTime.of(
1970, 1, 1, value.getHour(), value.getMinute(), value.getSecond(), value.getNano()
);

final Time time = new Time(localDateTime.getNano());
return time;
public Time toNonNullValue(LocalTime value)
{
return Time.valueOf(value);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package org.jadira.usertype.dateandtime.threeten.columnmapper;

import org.junit.Before;
import org.junit.Test;

import java.sql.Time;
import java.time.LocalTime;

import static org.junit.Assert.*;

public class TimeColumnLocalTimeMapperTest
{
private TimeColumnLocalTimeMapper timeColumnLocalTimeMapper;

@Before
public void setup()
{
timeColumnLocalTimeMapper = new TimeColumnLocalTimeMapper();
}
@Test
public void toNonNullValueShouldReturnTheCorrectTime()
{
LocalTime localTime = LocalTime.of(13, 37);
Time expected = Time.valueOf("13:37:00");
Time time = timeColumnLocalTimeMapper.toNonNullValue(localTime);
assertEquals(expected, time);
}
}