Search in sources :

Example 11 with LocalDateTime

use of java.time.LocalDateTime in project morphia by mongodb.

the class Java8EntityTest method queries.

@Test
public void queries() {
    Instant instant = Instant.ofEpochMilli(System.currentTimeMillis());
    LocalDate localDate = LocalDate.of(1995, 10, 15);
    LocalDateTime localDateTime = LocalDateTime.of(2016, 4, 10, 14, 15, 16, 123 * 1000000);
    LocalTime localTime = LocalTime.of(10, 29, 15, 848000000);
    Java8Entity entity = createEntity(getDs(), instant, localDate, localDateTime, localTime);
    compare(getDs(), entity, "instant", instant);
    compare(getDs(), entity, "localDate", localDate);
    compare(getDs(), entity, "localDateTime", localDateTime);
    compare(getDs(), entity, "localTime", localTime);
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) Instant(java.time.Instant) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Example 12 with LocalDateTime

use of java.time.LocalDateTime in project presto by prestodb.

the class TestJdbcQueryBuilder method setup.

@BeforeMethod
public void setup() throws SQLException {
    database = new TestingDatabase();
    jdbcClient = database.getJdbcClient();
    columns = ImmutableList.of(new JdbcColumnHandle("test_id", "col_0", BIGINT), new JdbcColumnHandle("test_id", "col_1", DOUBLE), new JdbcColumnHandle("test_id", "col_2", BOOLEAN), new JdbcColumnHandle("test_id", "col_3", VARCHAR), new JdbcColumnHandle("test_id", "col_4", DATE), new JdbcColumnHandle("test_id", "col_5", TIME), new JdbcColumnHandle("test_id", "col_6", TIMESTAMP), new JdbcColumnHandle("test_id", "col_7", TINYINT), new JdbcColumnHandle("test_id", "col_8", SMALLINT), new JdbcColumnHandle("test_id", "col_9", INTEGER), new JdbcColumnHandle("test_id", "col_10", REAL));
    Connection connection = database.getConnection();
    try (PreparedStatement preparedStatement = connection.prepareStatement("create table \"test_table\" (" + "" + "\"col_0\" BIGINT, " + "\"col_1\" DOUBLE, " + "\"col_2\" BOOLEAN, " + "\"col_3\" VARCHAR(128), " + "\"col_4\" DATE, " + "\"col_5\" TIME, " + "\"col_6\" TIMESTAMP, " + "\"col_7\" TINYINT, " + "\"col_8\" SMALLINT, " + "\"col_9\" INTEGER, " + "\"col_10\" REAL " + ")")) {
        preparedStatement.execute();
        StringBuilder stringBuilder = new StringBuilder("insert into \"test_table\" values ");
        int len = 1000;
        LocalDateTime dateTime = LocalDateTime.of(2016, 3, 23, 12, 23, 37);
        for (int i = 0; i < len; i++) {
            stringBuilder.append(format(Locale.ENGLISH, "(%d, %f, %b, 'test_str_%d', '%s', '%s', '%s', %d, %d, %d, %f)", i, 200000.0 + i / 2.0, i % 2 == 0, i, Date.valueOf(dateTime.toLocalDate()), Time.valueOf(dateTime.toLocalTime()), Timestamp.valueOf(dateTime), i % 128, -i, i - 100, 100.0f + i));
            dateTime = dateTime.plusHours(26);
            if (i != len - 1) {
                stringBuilder.append(",");
            }
        }
        try (PreparedStatement preparedStatement2 = connection.prepareStatement(stringBuilder.toString())) {
            preparedStatement2.execute();
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 13 with LocalDateTime

use of java.time.LocalDateTime in project requery by requery.

the class TimeConversionsTest method testInsertReadDateTime.

@Test
public void testInsertReadDateTime() {
    Event event = new Event();
    UUID id = UUID.randomUUID();
    LocalDateTime localDateTimeNow = LocalDateTime.now().withNano(0);
    OffsetDateTime offsetDateTimeNow = OffsetDateTime.now(ZoneId.systemDefault()).withNano(0);
    ZonedDateTime zonedDateTimeNow = ZonedDateTime.now(ZoneId.systemDefault()).withNano(0);
    event.setId(id);
    event.setLocalDateTime(localDateTimeNow);
    event.setOffsetDateTime(offsetDateTimeNow);
    event.setZonedDateTime(zonedDateTimeNow);
    data.insert(event);
    event = data.findByKey(Event.class, id);
    Assert.assertEquals(localDateTimeNow, event.getLocalDateTime());
    Assert.assertEquals(offsetDateTimeNow, event.getOffsetDateTime());
    Assert.assertEquals(zonedDateTimeNow.toInstant(), event.getZonedDateTime().toInstant());
}
Also used : LocalDateTime(java.time.LocalDateTime) OffsetDateTime(java.time.OffsetDateTime) ZonedDateTime(java.time.ZonedDateTime) Event(io.requery.test.model2.Event) UUID(java.util.UUID) Test(org.junit.Test)

Example 14 with LocalDateTime

use of java.time.LocalDateTime in project spring-loaded by spring-projects.

the class Issue104 method run.

public static String run() {
    LocalDateTime time = LocalDateTime.now();
    ZonedDateTime zdt = time.atZone(ZoneId.systemDefault());
    return zdt.toString();
}
Also used : LocalDateTime(java.time.LocalDateTime) ZonedDateTime(java.time.ZonedDateTime)

Example 15 with LocalDateTime

use of java.time.LocalDateTime in project jdk8u_jdk by JetBrains.

the class TCKLocalDateTime method test_plusDays_overYears.

@Test
public void test_plusDays_overYears() {
    LocalDateTime t = LocalDateTime.of(2006, 7, 14, 12, 30, 40, 987654321).plusDays(366);
    assertEquals(t, TEST_2007_07_15_12_30_40_987654321);
}
Also used : LocalDateTime(java.time.LocalDateTime) Test(org.testng.annotations.Test)

Aggregations

LocalDateTime (java.time.LocalDateTime)399 Test (org.testng.annotations.Test)280 ZonedDateTime (java.time.ZonedDateTime)45 Test (org.junit.Test)40 LocalDate (java.time.LocalDate)33 ZoneOffsetTransition (java.time.zone.ZoneOffsetTransition)26 LocalTime (java.time.LocalTime)20 Instant (java.time.Instant)19 DateTimeFormatter (java.time.format.DateTimeFormatter)16 ZoneId (java.time.ZoneId)15 AbstractTCKTest (tck.java.time.AbstractTCKTest)14 OffsetDateTime (java.time.OffsetDateTime)10 ZoneRules (java.time.zone.ZoneRules)10 ZoneOffset (java.time.ZoneOffset)9 Date (java.util.Date)8 List (java.util.List)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 Timestamp (java.sql.Timestamp)6 ChronoLocalDateTime (java.time.chrono.ChronoLocalDateTime)6