use of com.cadenzauk.core.RandomValues.randomLocalDateTime in project siesta by cadenzauk.
the class DatabaseIntegrationTest method localDateTimePartFuncs.
@Test
void localDateTimePartFuncs() {
LocalDateTime dateTime = RandomValues.randomLocalDateTime();
Database database = testDatabase(dataSource, dialect);
Tuple6<Integer, Integer, Integer, Integer, Integer, Integer> result = database.select(year(LiteralExpression.of(dateTime))).comma(month(ValueExpression.of(dateTime))).comma(day(LiteralExpression.of(dateTime))).comma(hour(ValueExpression.of(dateTime))).comma(minute(LiteralExpression.of(dateTime))).comma(second(ValueExpression.of(dateTime))).single();
assertThat(result.item1(), is(dateTime.getYear()));
assertThat(result.item2(), is(dateTime.getMonthValue()));
assertThat(result.item3(), is(dateTime.getDayOfMonth()));
assertThat(result.item4(), is(dateTime.getHour()));
assertThat(result.item5(), is(dateTime.getMinute()));
assertThat(result.item6(), is(dateTime.getSecond()));
}
use of com.cadenzauk.core.RandomValues.randomLocalDateTime in project siesta by cadenzauk.
the class DataTypeTest method toDatabaseLocalDateTime.
@ParameterizedTest
@MethodSource("timeZones")
void toDatabaseLocalDateTime(String jvmTimeZone) {
try (UncheckedAutoCloseable ignored = withTimeZone(jvmTimeZone)) {
LocalDateTime input = RandomValues.randomLocalDateTime();
Timestamp expected = Timestamp.valueOf(input);
when(db.dialect()).thenReturn(new AnsiDialect());
Object result = DataType.LOCAL_DATE_TIME.toDatabase(db, input);
assertThat(result, is(expected));
}
}
Aggregations