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());
}
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;
}
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);
}
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));
}
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);
}
Aggregations