use of org.simpleflatmapper.map.property.time.JavaZoneIdProperty in project SimpleFlatMapper by arnaudroger.
the class PreparedStatementFieldMapperFactoryTest method testJavaYearMonth.
@Test
public void testJavaYearMonth() throws Exception {
java.time.YearMonth value = java.time.YearMonth.now();
java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.YearMonth>(value), java.time.YearMonth.class, new JavaZoneIdProperty(zoneId));
newFieldMapperAndMapToPS(NullGetter.<Object, java.time.YearMonth>getter(), java.time.YearMonth.class);
verify(ps).setDate(1, new java.sql.Date(value.atDay(1).atStartOfDay(zoneId).toInstant().toEpochMilli()));
verify(ps).setNull(2, Types.DATE);
}
use of org.simpleflatmapper.map.property.time.JavaZoneIdProperty in project SimpleFlatMapper by arnaudroger.
the class PreparedStatementFieldMapperFactoryTest method testJavaLocalDateTime.
// IFJAVA8_START
@Test
public void testJavaLocalDateTime() throws Exception {
java.time.LocalDateTime value = java.time.LocalDateTime.now();
java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.LocalDateTime>(value), java.time.LocalDateTime.class, new JavaZoneIdProperty(zoneId));
newFieldMapperAndMapToPS(NullGetter.<Object, java.time.LocalDateTime>getter(), java.time.LocalDateTime.class);
verify(ps).setTimestamp(1, new Timestamp(value.atZone(zoneId).toInstant().toEpochMilli()));
verify(ps).setNull(2, Types.TIMESTAMP);
}
use of org.simpleflatmapper.map.property.time.JavaZoneIdProperty in project SimpleFlatMapper by arnaudroger.
the class SettableDataSetterFactoryTest method testJava8TimeLDT.
// IFJAVA8_START
@Test
public void testJava8TimeLDT() throws Exception {
Setter<SettableByIndexData, LocalDateTime> setter = factory.getSetter(newPM(LocalDateTime.class, DataType.timestamp()));
LocalDateTime ldt = LocalDateTime.now();
setter.set(statement, ldt);
setter.set(statement, null);
verify(statement).setDate(0, Date.from(ldt.atZone(ZoneId.systemDefault()).toInstant()));
verify(statement).setToNull(0);
final ZoneId zoneId = ZoneId.ofOffset("UTC", ZoneOffset.ofHours(2));
Setter<SettableByIndexData, LocalDateTime> setterTz = factory.getSetter(newPM(LocalDateTime.class, DataType.timestamp(), new JavaZoneIdProperty(zoneId)));
setterTz.set(statement, ldt);
verify(statement).setDate(1, Date.from(ldt.atZone(zoneId).toInstant()));
}
use of org.simpleflatmapper.map.property.time.JavaZoneIdProperty in project SimpleFlatMapper by arnaudroger.
the class PreparedStatementFieldMapperFactoryTest method testJavaLocalDate.
@Test
public void testJavaLocalDate() throws Exception {
java.time.LocalDate value = java.time.LocalDate.now();
java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.LocalDate>(value), java.time.LocalDate.class, new JavaZoneIdProperty(zoneId));
newFieldMapperAndMapToPS(NullGetter.<Object, java.time.LocalDate>getter(), java.time.LocalDate.class);
verify(ps).setDate(1, new java.sql.Date(value.atStartOfDay(zoneId).toInstant().toEpochMilli()));
verify(ps).setNull(2, Types.DATE);
}
use of org.simpleflatmapper.map.property.time.JavaZoneIdProperty in project SimpleFlatMapper by arnaudroger.
the class PreparedStatementFieldMapperFactoryTest method testJavaLocalTime.
@Test
public void testJavaLocalTime() throws Exception {
java.time.LocalTime value = java.time.LocalTime.now();
java.time.ZoneId zoneId = ZoneId.of("America/Los_Angeles");
newFieldMapperAndMapToPS(new ConstantGetter<Object, java.time.LocalTime>(value), java.time.LocalTime.class, new JavaZoneIdProperty(zoneId));
newFieldMapperAndMapToPS(NullGetter.<Object, java.time.LocalTime>getter(), java.time.LocalTime.class);
verify(ps).setTime(1, new Time(value.atDate(LocalDate.now()).atZone(zoneId).toInstant().toEpochMilli()));
verify(ps).setNull(2, Types.TIME);
}
Aggregations