use of java.time.Instant 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.Instant in project jdk8u_jdk by JetBrains.
the class TCKZoneOffset method test_getRules.
//-----------------------------------------------------------------------
// getRules()
//-----------------------------------------------------------------------
@Test
public void test_getRules() {
ZoneOffset offset = ZoneOffset.ofHoursMinutesSeconds(1, 2, 3);
assertEquals(offset.getRules().isFixedOffset(), true);
assertEquals(offset.getRules().getOffset((Instant) null), offset);
assertEquals(offset.getRules().getDaylightSavings((Instant) null), Duration.ZERO);
assertEquals(offset.getRules().getStandardOffset((Instant) null), offset);
assertEquals(offset.getRules().nextTransition((Instant) null), null);
assertEquals(offset.getRules().previousTransition((Instant) null), null);
assertEquals(offset.getRules().isValidOffset((LocalDateTime) null, offset), true);
assertEquals(offset.getRules().isValidOffset((LocalDateTime) null, ZoneOffset.UTC), false);
assertEquals(offset.getRules().isValidOffset((LocalDateTime) null, null), false);
assertEquals(offset.getRules().getOffset((LocalDateTime) null), offset);
assertEquals(offset.getRules().getValidOffsets((LocalDateTime) null), Arrays.asList(offset));
assertEquals(offset.getRules().getTransition((LocalDateTime) null), null);
assertEquals(offset.getRules().getTransitions().size(), 0);
assertEquals(offset.getRules().getTransitionRules().size(), 0);
}
use of java.time.Instant in project jdk8u_jdk by JetBrains.
the class TCKZonedDateTime method factory_ofInstant_allDaysInCycle.
@Test
public void factory_ofInstant_allDaysInCycle() {
// sanity check using different algorithm
ZonedDateTime expected = LocalDateTime.of(1970, 1, 1, 0, 0, 0, 0).atZone(ZoneOffset.UTC);
for (long i = 0; i < 146097; i++) {
Instant instant = Instant.ofEpochSecond(i * 24L * 60L * 60L);
ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
assertEquals(test, expected);
expected = expected.plusDays(1);
}
}
use of java.time.Instant in project jdk8u_jdk by JetBrains.
the class TCKZonedDateTime method factory_ofInstant_Instant_ZR.
//-----------------------------------------------------------------------
// ofInstant(Instant, ZoneId)
//-----------------------------------------------------------------------
@Test
public void factory_ofInstant_Instant_ZR() {
Instant instant = LocalDateTime.of(2008, 6, 30, 11, 30, 10, 35).toInstant(OFFSET_0200);
ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);
check(test, 2008, 6, 30, 11, 30, 10, 35, OFFSET_0200, ZONE_PARIS);
}
use of java.time.Instant in project jdk8u_jdk by JetBrains.
the class TCKZoneRules method test_Paris_getStandardOffset.
public void test_Paris_getStandardOffset() {
ZoneRules test = europeParis();
ZonedDateTime zdt = createZDT(1840, 1, 1, ZoneOffset.UTC);
while (zdt.getYear() < 2010) {
Instant instant = zdt.toInstant();
if (zdt.toLocalDate().isBefore(LocalDate.of(1911, 3, 11))) {
assertEquals(test.getStandardOffset(instant), ZoneOffset.ofHoursMinutesSeconds(0, 9, 21));
} else if (zdt.toLocalDate().isBefore(LocalDate.of(1940, 6, 14))) {
assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
} else if (zdt.toLocalDate().isBefore(LocalDate.of(1944, 8, 25))) {
assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
} else if (zdt.toLocalDate().isBefore(LocalDate.of(1945, 9, 16))) {
assertEquals(test.getStandardOffset(instant), OFFSET_ZERO);
} else {
assertEquals(test.getStandardOffset(instant), OFFSET_PONE);
}
zdt = zdt.plusMonths(6);
}
}
Aggregations