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);
}
}
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);
}
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);
}
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);
}
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);
}
}
Aggregations