use of java.time.Clock 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);
}
}
use of java.time.Clock in project jdk8u_jdk by JetBrains.
the class TestClock_Fixed method test_withZone_same.
//-------------------------------------------------------------------------
public void test_withZone_same() {
Clock test = Clock.fixed(INSTANT, PARIS);
Clock changed = test.withZone(PARIS);
assertSame(test, changed);
}
use of java.time.Clock in project jdk8u_jdk by JetBrains.
the class TCKInstant method now_Clock_allSecsInDay_beforeEpoch.
@Test
public void now_Clock_allSecsInDay_beforeEpoch() {
for (int i = -1; i >= -(24 * 60 * 60); i--) {
Instant expected = Instant.ofEpochSecond(i).plusNanos(123456789L);
Clock clock = Clock.fixed(expected, ZoneOffset.UTC);
Instant test = Instant.now(clock);
assertEquals(test, expected);
}
}
use of java.time.Clock in project jdk8u_jdk by JetBrains.
the class TCKYearMonth method now_Clock.
//-----------------------------------------------------------------------
// now(Clock)
//-----------------------------------------------------------------------
@Test
public void now_Clock() {
Instant instant = LocalDateTime.of(2010, 12, 31, 0, 0).toInstant(ZoneOffset.UTC);
Clock clock = Clock.fixed(instant, ZoneOffset.UTC);
YearMonth test = YearMonth.now(clock);
assertEquals(test.getYear(), 2010);
assertEquals(test.getMonth(), Month.DECEMBER);
}
use of java.time.Clock in project jdk8u_jdk by JetBrains.
the class TCKClock_Fixed method test_withZone_equal.
public void test_withZone_equal() {
Clock test = Clock.fixed(INSTANT, PARIS);
Clock changed = test.withZone(PARIS);
assertEquals(changed.getZone(), PARIS);
}
Aggregations