Search in sources :

Example 61 with ZoneId

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()));
}
Also used : LocalDateTime(java.time.LocalDateTime) ZoneId(java.time.ZoneId) JavaZoneIdProperty(org.simpleflatmapper.map.property.time.JavaZoneIdProperty) Test(org.junit.Test)

Example 62 with ZoneId

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");
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 63 with ZoneId

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();
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test) BaseTest(org.assertj.core.api.BaseTest)

Example 64 with ZoneId

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);
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Example 65 with ZoneId

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());
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.Test)

Aggregations

ZoneId (java.time.ZoneId)420 Test (org.junit.Test)137 ZonedDateTime (java.time.ZonedDateTime)108 LocalDateTime (java.time.LocalDateTime)69 LocalDate (java.time.LocalDate)55 Instant (java.time.Instant)49 Test (org.testng.annotations.Test)41 ZoneOffset (java.time.ZoneOffset)37 DateTimeFormatter (java.time.format.DateTimeFormatter)32 Date (java.util.Date)29 ArrayList (java.util.ArrayList)23 LocalTime (java.time.LocalTime)21 TemporalAccessor (java.time.temporal.TemporalAccessor)15 List (java.util.List)15 HashMap (java.util.HashMap)14 Clock (java.time.Clock)13 Collectors (java.util.stream.Collectors)13 DateTimeException (java.time.DateTimeException)12 Duration (java.time.Duration)12 OffsetDateTime (java.time.OffsetDateTime)11