Search in sources :

Example 11 with OffsetDateTime

use of java.time.OffsetDateTime 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 12 with OffsetDateTime

use of java.time.OffsetDateTime in project Gaffer by gchq.

the class CommonTimeUtil method timeToBucket.

/**
     * Place a time value (a Java {@link Long} representing the number of
     * milliseconds since the start of the Unix epoch) in a {@link TimeBucket}.
     *
     * @param time   the time, in milliseconds since the start of the Unix epoch
     * @param bucket the time bucket to place the time value into
     * @return the value of the time bucket
     */
public static long timeToBucket(final long time, final TimeBucket bucket) {
    final OffsetDateTime dateTime = Instant.ofEpochMilli(time).atOffset(ZoneOffset.UTC);
    final long timeBucket;
    switch(bucket) {
        case SECOND:
            timeBucket = dateTime.truncatedTo(SECONDS).toInstant().toEpochMilli();
            break;
        case MINUTE:
            timeBucket = dateTime.truncatedTo(MINUTES).toInstant().toEpochMilli();
            break;
        case HOUR:
            timeBucket = dateTime.truncatedTo(HOURS).toInstant().toEpochMilli();
            break;
        case DAY:
            timeBucket = dateTime.truncatedTo(DAYS).toInstant().toEpochMilli();
            break;
        case WEEK:
            timeBucket = dateTime.with(firstDayOfWeek()).truncatedTo(DAYS).toInstant().toEpochMilli();
            break;
        case MONTH:
            timeBucket = dateTime.with(firstDayOfMonth()).truncatedTo(DAYS).toInstant().toEpochMilli();
            break;
        default:
            timeBucket = time;
    }
    return timeBucket;
}
Also used : OffsetDateTime(java.time.OffsetDateTime)

Example 13 with OffsetDateTime

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

the class TCKOffsetTime method test_until_convertedType.

@Test
public void test_until_convertedType() {
    OffsetTime offsetTime = OffsetTime.of(1, 1, 1, 0, OFFSET_PONE);
    OffsetDateTime offsetDateTime = offsetTime.plusSeconds(3).atDate(LocalDate.of(1980, 2, 10));
    assertEquals(offsetTime.until(offsetDateTime, SECONDS), 3);
}
Also used : OffsetDateTime(java.time.OffsetDateTime) OffsetTime(java.time.OffsetTime) Test(org.testng.annotations.Test)

Example 14 with OffsetDateTime

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

the class TCKOffsetDateTime method test_withYear_normal.

//-----------------------------------------------------------------------
// withYear()
//-----------------------------------------------------------------------
@Test
public void test_withYear_normal() {
    OffsetDateTime base = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE);
    OffsetDateTime test = base.withYear(2007);
    assertEquals(test, OffsetDateTime.of(LocalDate.of(2007, 6, 30), LocalTime.of(11, 30, 59), OFFSET_PONE));
}
Also used : OffsetDateTime(java.time.OffsetDateTime) Test(org.testng.annotations.Test)

Example 15 with OffsetDateTime

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

the class TCKOffsetDateTime method factory_of_LocalDateLocalTimeZoneOffset.

//-----------------------------------------------------------------------
@Test
public void factory_of_LocalDateLocalTimeZoneOffset() {
    LocalDate date = LocalDate.of(2008, 6, 30);
    LocalTime time = LocalTime.of(11, 30, 10, 500);
    OffsetDateTime test = OffsetDateTime.of(date, time, OFFSET_PONE);
    check(test, 2008, 6, 30, 11, 30, 10, 500, OFFSET_PONE);
}
Also used : LocalTime(java.time.LocalTime) OffsetDateTime(java.time.OffsetDateTime) LocalDate(java.time.LocalDate) Test(org.testng.annotations.Test)

Aggregations

OffsetDateTime (java.time.OffsetDateTime)191 Test (org.testng.annotations.Test)139 Instant (java.time.Instant)22 Test (org.junit.Test)20 ZonedDateTime (java.time.ZonedDateTime)17 LocalDateTime (java.time.LocalDateTime)12 LocalDate (java.time.LocalDate)11 LocalTime (java.time.LocalTime)10 Timestamp (java.sql.Timestamp)6 OffsetTime (java.time.OffsetTime)6 ChronoZonedDateTime (java.time.chrono.ChronoZonedDateTime)6 Map (java.util.Map)6 Date (java.sql.Date)4 Clock (java.time.Clock)4 ZoneOffset (java.time.ZoneOffset)4 DateTimeFormatter (java.time.format.DateTimeFormatter)4 Collections.emptyMap (java.util.Collections.emptyMap)4 UUID (java.util.UUID)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)4 MapUtil.stringMap (org.neo4j.helpers.collection.MapUtil.stringMap)4