Search in sources :

Example 16 with ZonedDateTime

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

the class TCKZonedDateTime method test_get.

@Test(dataProvider = "sampleTimes")
public void test_get(int y, int o, int d, int h, int m, int s, int n, ZoneId zone) {
    LocalDate localDate = LocalDate.of(y, o, d);
    LocalTime localTime = LocalTime.of(h, m, s, n);
    LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
    ZoneOffset offset = zone.getRules().getOffset(localDateTime);
    ZonedDateTime a = ZonedDateTime.of(localDateTime, zone);
    assertEquals(a.getYear(), localDate.getYear());
    assertEquals(a.getMonth(), localDate.getMonth());
    assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
    assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
    assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());
    assertEquals(a.getHour(), localTime.getHour());
    assertEquals(a.getMinute(), localTime.getMinute());
    assertEquals(a.getSecond(), localTime.getSecond());
    assertEquals(a.getNano(), localTime.getNano());
    assertEquals(a.toLocalDate(), localDate);
    assertEquals(a.toLocalTime(), localTime);
    assertEquals(a.toLocalDateTime(), localDateTime);
    if (zone instanceof ZoneOffset) {
        assertEquals(a.toString(), localDateTime.toString() + offset.toString());
    } else {
        assertEquals(a.toString(), localDateTime.toString() + offset.toString() + "[" + zone.toString() + "]");
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) LocalTime(java.time.LocalTime) ZonedDateTime(java.time.ZonedDateTime) LocalDate(java.time.LocalDate) ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 17 with ZonedDateTime

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

the class TCKZonedDateTime method test_withYear_noChange.

@Test
public void test_withYear_noChange() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
    ZonedDateTime test = base.withYear(2008);
    assertEquals(test, base);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Test(org.testng.annotations.Test)

Example 18 with ZonedDateTime

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

the class TCKZonedDateTime method test_with_adjuster_LocalDateTime_adjustedOffset.

@Test
public void test_with_adjuster_LocalDateTime_adjustedOffset() {
    ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_PARIS);
    ZonedDateTime test = base.with(LocalDateTime.of(2012, 1, 15, 14, 30));
    check(test, 2012, 1, 15, 14, 30, 0, 0, OFFSET_0100, ZONE_PARIS);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Test(org.testng.annotations.Test)

Example 19 with ZonedDateTime

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

the class TCKZonedDateTime method now_Clock_offsets.

@Test
public void now_Clock_offsets() {
    ZonedDateTime base = ZonedDateTime.of(LocalDateTime.of(1970, 1, 1, 12, 0), ZoneOffset.UTC);
    for (int i = -9; i < 15; i++) {
        ZoneOffset offset = ZoneOffset.ofHours(i);
        Clock clock = Clock.fixed(base.toInstant(), offset);
        ZonedDateTime test = ZonedDateTime.now(clock);
        assertEquals(test.getHour(), (12 + i) % 24);
        assertEquals(test.getMinute(), 0);
        assertEquals(test.getSecond(), 0);
        assertEquals(test.getNano(), 0);
        assertEquals(test.getOffset(), offset);
        assertEquals(test.getZone(), offset);
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Clock(java.time.Clock) ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 20 with ZonedDateTime

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

the class TCKZonedDateTime method test_withLaterOffsetAtOverlap_notAtOverlap.

//-----------------------------------------------------------------------
// withLaterOffsetAtOverlap()
//-----------------------------------------------------------------------
@Test
public void test_withLaterOffsetAtOverlap_notAtOverlap() {
    ZonedDateTime base = ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0200, ZONE_PARIS);
    ZonedDateTime test = base.withLaterOffsetAtOverlap();
    // not changed
    assertEquals(test, base);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Test(org.testng.annotations.Test)

Aggregations

ZonedDateTime (java.time.ZonedDateTime)1461 Test (org.junit.Test)622 Test (org.testng.annotations.Test)182 LocalDateTime (java.time.LocalDateTime)145 ZoneId (java.time.ZoneId)129 Instant (java.time.Instant)114 ArrayList (java.util.ArrayList)104 Test (org.junit.jupiter.api.Test)96 LocalDate (java.time.LocalDate)90 List (java.util.List)80 DateTimeFormatter (java.time.format.DateTimeFormatter)78 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)76 Date (java.util.Date)66 IOException (java.io.IOException)58 UUID (java.util.UUID)58 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)54 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)53 HashMap (java.util.HashMap)47 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)44 OffsetDateTime (java.time.OffsetDateTime)44