Search in sources :

Example 86 with Clock

use of java.time.Clock in project j2objc by google.

the class TCKZonedDateTime method now_Clock_allSecsInDay_zone.

@Test
public void now_Clock_allSecsInDay_zone() {
    ZoneId zone = ZoneId.of("Europe/London");
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i).plusNanos(123456789L);
        ZonedDateTime expected = ZonedDateTime.ofInstant(instant, zone);
        Clock clock = Clock.fixed(expected.toInstant(), zone);
        ZonedDateTime test = ZonedDateTime.now(clock);
        assertEquals(test, expected);
    }
}
Also used : ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) Clock(java.time.Clock) Test(org.junit.Test)

Example 87 with Clock

use of java.time.Clock in project j2objc by google.

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.junit.Test)

Example 88 with Clock

use of java.time.Clock in project j2objc by google.

the class TCKOffsetTime method now_Clock_offsets.

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

Example 89 with Clock

use of java.time.Clock in project j2objc by google.

the class TCKLocalTime method now_Clock_allSecsInDay.

@Test
public void now_Clock_allSecsInDay() {
    for (int i = 0; i < (2 * 24 * 60 * 60); i++) {
        Instant instant = Instant.ofEpochSecond(i, 8);
        Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
        LocalTime test = LocalTime.now(clock);
        assertEquals(test.getHour(), (i / (60 * 60)) % 24);
        assertEquals(test.getMinute(), (i / 60) % 60);
        assertEquals(test.getSecond(), i % 60);
        assertEquals(test.getNano(), 8);
    }
}
Also used : LocalTime(java.time.LocalTime) Instant(java.time.Instant) Clock(java.time.Clock) Test(org.junit.Test)

Example 90 with Clock

use of java.time.Clock in project j2objc by google.

the class TCKOffsetDateTime method now_Clock_offsets.

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

Aggregations

Clock (java.time.Clock)209 Test (org.junit.Test)62 Instant (java.time.Instant)51 Test (org.testng.annotations.Test)43 LocalTime (java.time.LocalTime)15 ZonedDateTime (java.time.ZonedDateTime)12 LocalDateTime (java.time.LocalDateTime)11 ZoneId (java.time.ZoneId)11 LocalDate (java.time.LocalDate)10 OffsetDateTime (java.time.OffsetDateTime)8 Test (org.junit.jupiter.api.Test)7 HandlerTest (com.yahoo.vespa.config.server.http.HandlerTest)6 SessionHandlerTest (com.yahoo.vespa.config.server.http.SessionHandlerTest)6 IOException (java.io.IOException)6 SessionTest (com.yahoo.vespa.config.server.session.SessionTest)5 OffsetTime (java.time.OffsetTime)5 ZoneOffset (java.time.ZoneOffset)5 Chronology (java.time.chrono.Chronology)5 IsoChronology (java.time.chrono.IsoChronology)5 Date (java.util.Date)4