use of java.time.ZoneId 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 java.time.ZoneId in project assertj-core by joel-costigliola.
the class ZonedDateTimeAssert_isBefore_Test method isBefore_should_compare_datetimes_in_actual_timezone.
@Test
public void isBefore_should_compare_datetimes_in_actual_timezone() {
ZonedDateTime utcDateTime = ZonedDateTime.of(2013, 6, 10, 0, 0, 0, 0, UTC);
ZoneId cestTimeZone = ZoneId.of("Europe/Berlin");
ZonedDateTime cestDateTime2 = ZonedDateTime.of(2013, 6, 10, 3, 0, 0, 0, cestTimeZone);
// utcDateTime < cestDateTime2
assertThat(utcDateTime).as("in UTC time zone").isBefore(cestDateTime2);
// utcDateTime = cestDateTime1
try {
ZonedDateTime cestDateTime1 = ZonedDateTime.of(2013, 6, 10, 2, 0, 0, 0, cestTimeZone);
assertThat(utcDateTime).as("in UTC time zone").isBefore(cestDateTime1);
} catch (AssertionError e) {
return;
}
fail("Should have thrown AssertionError");
}
use of java.time.ZoneId in project assertj-core by joel-costigliola.
the class ZonedDateTimeAssert_isEqualToIgnoringHours_Test method should_pass_if_actual_is_equal_to_other_ignoring_hours_in_different_timezone.
@Test
public void should_pass_if_actual_is_equal_to_other_ignoring_hours_in_different_timezone() {
ZonedDateTime utcDateTime = ZonedDateTime.of(2013, 6, 10, 0, 0, 0, 0, UTC);
ZoneId cestTimeZone = ZoneId.of("Europe/Berlin");
// new DateTime(2013, 6, 10, 5, 0, cestTimeZone) = DateTime(2013, 6, 10, 3, 0, DateTimeZone.UTC)
assertThat(utcDateTime).isEqualToIgnoringHours(ZonedDateTime.of(2013, 6, 10, 5, 0, 0, 0, cestTimeZone));
// new DateTime(2013, 6, 11, 1, 0, cestTimeZone) = DateTime(2013, 6, 10, 23, 0, DateTimeZone.UTC)
assertThat(utcDateTime).isEqualToIgnoringHours(ZonedDateTime.of(2013, 6, 11, 1, 0, 0, 0, cestTimeZone));
try {
// DateTime(2013, 6, 10, 0, 0, cestTimeZone) = DateTime(2013, 6, 9, 22, 0, DateTimeZone.UTC)
assertThat(utcDateTime).isEqualToIgnoringHours(ZonedDateTime.of(2013, 6, 10, 0, 0, 0, 0, cestTimeZone));
} catch (AssertionError e) {
assertThat(e).hasMessage(format("%nExpecting:%n <2013-06-10T00:00Z>%nto have same year, month and day as:%n <2013-06-09T22:00Z>%nbut had not."));
return;
}
failBecauseExpectedAssertionErrorWasNotThrown();
}
use of java.time.ZoneId in project assertj-core by joel-costigliola.
the class ZonedDateTimeAssert_isEqualTo_Test method isEqualTo_should_compare_datetimes_in_actual_timezone.
@Test
public void isEqualTo_should_compare_datetimes_in_actual_timezone() {
ZonedDateTime utcDateTime = ZonedDateTime.of(2013, 6, 10, 0, 0, 0, 0, UTC);
ZoneId cestTimeZone = ZoneId.of("Europe/Berlin");
ZonedDateTime cestDateTime = ZonedDateTime.of(2013, 6, 10, 2, 0, 0, 0, cestTimeZone);
// datetime are equals in same timezone
assertThat(utcDateTime).as("in UTC time zone").isEqualTo(cestDateTime);
assertThat(cestDateTime).as("in CEST time zone").isEqualTo(utcDateTime);
}
use of java.time.ZoneId in project assertj-core by joel-costigliola.
the class ZonedDateTimeAssert_isIn_Test method isIn_should_compare_datetimes_in_actual_timezone.
@Test
public void isIn_should_compare_datetimes_in_actual_timezone() {
ZonedDateTime utcDateTime = ZonedDateTime.of(2013, 6, 10, 0, 0, 0, 0, ZoneOffset.UTC);
ZoneId cestTimeZone = ZoneId.of("Europe/Berlin");
ZonedDateTime cestDateTime = ZonedDateTime.of(2013, 6, 10, 2, 0, 0, 0, cestTimeZone);
// cestDateTime and utcDateTime are equals in same timezone
assertThat(utcDateTime).isIn(cestDateTime, ZonedDateTime.now());
}
Aggregations