Search in sources :

Example 91 with Instant

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

the class TCKZonedDateTime method now_Clock_allSecsInDay_utc.

@Test
public void now_Clock_allSecsInDay_utc() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        ZonedDateTime test = ZonedDateTime.now(clock);
        assertEquals(test.getYear(), 1970);
        assertEquals(test.getMonth(), Month.JANUARY);
        assertEquals(test.getDayOfMonth(), (i < 24 * 60 * 60 ? 1 : 2));
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 123456789);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
        assertEquals(test.getZone(), ZoneOffset.UTC);
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) Clock(java.time.Clock) Test(org.testng.annotations.Test)

Example 92 with Instant

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

the class TCKZoneOffset method test_getRules.

//-----------------------------------------------------------------------
// getRules()
//-----------------------------------------------------------------------
@Test
public void test_getRules() {
    ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(1, 2, 3);
    assertEquals(offset.getRules().isFixedOffset(), true);
    assertEquals(offset.getRules().getOffset((Instant) null), offset);
    assertEquals(offset.getRules().getDaylightSavings((Instant) null), Duration.ZERO);
    assertEquals(offset.getRules().getStandardOffset((Instant) null), offset);
    assertEquals(offset.getRules().nextTransition((Instant) null), null);
    assertEquals(offset.getRules().previousTransition((Instant) null), null);
    assertEquals(offset.getRules().isValidOffset((LocalDateTime) null, offset), true);
    assertEquals(offset.getRules().isValidOffset((LocalDateTime) null, ZoneOffset.UTC), false);
    assertEquals(offset.getRules().isValidOffset((LocalDateTime) null, null), false);
    assertEquals(offset.getRules().getOffset((LocalDateTime) null), offset);
    assertEquals(offset.getRules().getValidOffsets((LocalDateTime) null), Arrays.asList(offset));
    assertEquals(offset.getRules().getTransition((LocalDateTime) null), null);
    assertEquals(offset.getRules().getTransitions().size(), 0);
    assertEquals(offset.getRules().getTransitionRules().size(), 0);
}
Also used : LocalDateTime(java.time.LocalDateTime) Instant(java.time.Instant) ZoneOffset(java.time.ZoneOffset) Test(org.testng.annotations.Test)

Example 93 with Instant

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

the class TCKZonedDateTime method factory_ofInstant_allDaysInCycle.

@Test
public void factory_ofInstant_allDaysInCycle() {
    // sanity check using different algorithm
    ZonedDateTime expected = LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0).atZone(ZoneOffset.UTC);
    for (long i = 0; i < 146097; i++) {
        Instant instant = Instant.ofEpochSecond(i * 24L * 60L * 60L);
        ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
        assertEquals(test, expected);
        expected = expected.plusDays(1);
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) Test(org.testng.annotations.Test)

Example 94 with Instant

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

the class TCKZonedDateTime method factory_ofInstant_Instant_ZR.

//-----------------------------------------------------------------------
// ofInstant(Instant, ZoneId)
//-----------------------------------------------------------------------
@Test
public void factory_ofInstant_Instant_ZR() {
    Instant instant = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 35).toInstant(OFFSET_0200);
    ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);
    check(test, 2008, 6, 30, 11, 30, 10, 35, OFFSET_0200, ZONE_PARIS);
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) Test(org.testng.annotations.Test)

Example 95 with Instant

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

the class TCKZoneRules method test_Paris_getStandardOffset.

public void test_Paris_getStandardOffset() {
    ZoneRules test = europeParis();
    ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
    while (zdt.getYear() < 2010) {
        Instant instant = zdt.toInstant();
        if (zdt.toLocalDate().isBefore(LocalDate.of(1911, 3, 11))) {
            assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, 9, 21));
        } else if (zdt.toLocalDate().isBefore(LocalDate.of(1940, 6, 14))) {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
        } else if (zdt.toLocalDate().isBefore(LocalDate.of(1944, 8, 25))) {
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
        } else if (zdt.toLocalDate().isBefore(LocalDate.of(1945, 9, 16))) {
            assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
        } else {
            assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
        }
        zdt = zdt.plusMonths(6);
    }
}
Also used : ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) ZoneRules(java.time.zone.ZoneRules)

Aggregations

Instant (java.time.Instant)463 Test (org.testng.annotations.Test)143 Test (org.junit.Test)85 ZonedDateTime (java.time.ZonedDateTime)39 Duration (java.time.Duration)30 Clock (java.time.Clock)26 Lifetime (org.apache.cxf.sts.request.Lifetime)26 OffsetDateTime (java.time.OffsetDateTime)23 LocalDateTime (java.time.LocalDateTime)20 ArrayList (java.util.ArrayList)18 Element (org.w3c.dom.Element)18 LocalDate (java.time.LocalDate)17 IOException (java.io.IOException)14 Date (java.util.Date)14 LocalTime (java.time.LocalTime)12 DateTimeFormatter (java.time.format.DateTimeFormatter)12 STSException (org.apache.cxf.ws.security.sts.provider.STSException)12 SecurityToken (org.apache.cxf.ws.security.tokenstore.SecurityToken)12 Timestamp (java.sql.Timestamp)11 DefaultConditionsProvider (org.apache.cxf.sts.token.provider.DefaultConditionsProvider)10