Search in sources :

Example 11 with Clock

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

the class TCKZonedDateTime method now_Clock_allSecsInDay_beforeEpoch.

@Test
public void now_Clock_allSecsInDay_beforeEpoch() {
    LocalTime expected = LocalTime.MIDNIGHT.plusNanos(123456789L);
    for (int i = -1; i >= -(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(), 1969);
        assertEquals(test.getMonth(), Month.DECEMBER);
        assertEquals(test.getDayOfMonth(), 31);
        expected = expected.minusSeconds(1);
        assertEquals(test.toLocalTime(), expected);
        assertEquals(test.getOffset(), ZoneOffset.UTC);
        assertEquals(test.getZone(), ZoneOffset.UTC);
    }
}
Also used : LocalTime(java.time.LocalTime) ZonedDateTime(java.time.ZonedDateTime) Instant(java.time.Instant) Clock(java.time.Clock) Test(org.testng.annotations.Test)

Example 12 with Clock

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

the class TCKLocalDate method now_Clock_tooLow.

@Test(expectedExceptions = DateTimeException.class)
public void now_Clock_tooLow() {
    Clock clock = Clock.fixed(MIN_INSTANT.minusNanos(1), ZoneOffset.UTC);
    LocalDate.now(clock);
}
Also used : Clock(java.time.Clock) Test(org.testng.annotations.Test)

Example 13 with Clock

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

the class TCKLocalDateTime method now_Clock_minYear.

@Test
public void now_Clock_minYear() {
    Clock clock = Clock.fixed(MIN_INSTANT, ZoneOffset.UTC);
    LocalDateTime test = LocalDateTime.now(clock);
    assertEquals(test, MIN_DATE_TIME);
}
Also used : LocalDateTime(java.time.LocalDateTime) Clock(java.time.Clock) Test(org.testng.annotations.Test)

Example 14 with Clock

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

the class TCKLocalTime method now_Clock_min.

@Test
public void now_Clock_min() {
    Clock clock = Clock.fixed(Instant.MIN, ZoneOffset.UTC);
    LocalTime test = LocalTime.now(clock);
    assertEquals(test.getHour(), 0);
    assertEquals(test.getMinute(), 0);
    assertEquals(test.getSecond(), 0);
    assertEquals(test.getNano(), 0);
}
Also used : LocalTime(java.time.LocalTime) Clock(java.time.Clock) Test(org.testng.annotations.Test)

Example 15 with Clock

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

the class TCKLocalTime method now_Clock_beforeEpoch.

@Test
public void now_Clock_beforeEpoch() {
    for (int i = -1; i >= -(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 + 24 * 60 * 60) / (60 * 60)) % 24);
        assertEquals(test.getMinute(), ((i + 24 * 60 * 60) / 60) % 60);
        assertEquals(test.getSecond(), (i + 24 * 60 * 60) % 60);
        assertEquals(test.getNano(), 8);
    }
}
Also used : LocalTime(java.time.LocalTime) Instant(java.time.Instant) Clock(java.time.Clock) Test(org.testng.annotations.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