use of java.time.Clock in project jdk8u_jdk by JetBrains.
the class TCKLocalDateTime 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);
LocalDateTime test = LocalDateTime.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);
}
}
use of java.time.Clock in project jdk8u_jdk by JetBrains.
the class TCKLocalDate method now_Clock_minYear.
@Test
public void now_Clock_minYear() {
Clock clock = Clock.fixed(MIN_INSTANT, ZoneOffset.UTC);
LocalDate test = LocalDate.now(clock);
assertEquals(test, MIN_DATE);
}
use of java.time.Clock in project jdk8u_jdk by JetBrains.
the class TCKLocalDate method now_Clock_allSecsInDay_beforeEpoch.
@Test
public void now_Clock_allSecsInDay_beforeEpoch() {
for (int i = -1; i >= -(2 * 24 * 60 * 60); i--) {
Instant instant = Instant.ofEpochSecond(i);
Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
LocalDate test = LocalDate.now(clock);
assertEquals(test.getYear(), 1969);
assertEquals(test.getMonth(), Month.DECEMBER);
assertEquals(test.getDayOfMonth(), (i >= -24 * 60 * 60 ? 31 : 30));
}
}
use of java.time.Clock 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);
}
}
use of java.time.Clock in project jdk8u_jdk by JetBrains.
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);
}
}
Aggregations