use of java.time.Instant 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.Instant in project jdk8u_jdk by JetBrains.
the class TCKZonedDateTime method factory_ofInstant_Instant_inGap.
@Test
public void factory_ofInstant_Instant_inGap() {
Instant instant = TEST_PARIS_GAP_2008_03_30_02_30.toInstant(OFFSET_0100);
ZonedDateTime test = ZonedDateTime.ofInstant(instant, ZONE_PARIS);
// one hour later in summer offset
check(test, 2008, 3, 30, 3, 30, 0, 0, OFFSET_0200, ZONE_PARIS);
}
use of java.time.Instant in project jdk8u_jdk by JetBrains.
the class TCKZonedDateTime method factory_ofInstant_tooBig.
@Test(expectedExceptions = DateTimeException.class)
public void factory_ofInstant_tooBig() {
long days_0000_to_1970 = (146097 * 5) - (30 * 365 + 7);
long year = Year.MAX_VALUE + 1L;
long days = (year * 365L + (year / 4 - year / 100 + year / 400)) - days_0000_to_1970;
Instant instant = Instant.ofEpochSecond(days * 24L * 60L * 60L);
ZonedDateTime.ofInstant(instant, ZoneOffset.UTC);
}
use of java.time.Instant in project jdk8u_jdk by JetBrains.
the class TCKDateTimeParseResolver method test_parse_fromField_InstantSeconds_NanoOfSecond.
@Test
public void test_parse_fromField_InstantSeconds_NanoOfSecond() {
DateTimeFormatter fmt = new DateTimeFormatterBuilder().appendValue(INSTANT_SECONDS).appendLiteral('.').appendValue(NANO_OF_SECOND).toFormatter();
TemporalAccessor acc = fmt.parse("86402.123456789");
Instant expected = Instant.ofEpochSecond(86402, 123456789);
assertEquals(acc.isSupported(INSTANT_SECONDS), true);
assertEquals(acc.isSupported(NANO_OF_SECOND), true);
assertEquals(acc.isSupported(MICRO_OF_SECOND), true);
assertEquals(acc.isSupported(MILLI_OF_SECOND), true);
assertEquals(acc.getLong(INSTANT_SECONDS), 86402L);
assertEquals(acc.getLong(NANO_OF_SECOND), 123456789L);
assertEquals(acc.getLong(MICRO_OF_SECOND), 123456L);
assertEquals(acc.getLong(MILLI_OF_SECOND), 123L);
assertEquals(Instant.from(acc), expected);
}
use of java.time.Instant 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