use of java.time.OffsetDateTime in project jdk8u_jdk by JetBrains.
the class TCKOffsetDateTime method test_with_adjustment_ZoneOffset.
@Test
public void test_with_adjustment_ZoneOffset() {
OffsetDateTime test = TEST_2008_6_30_11_30_59_000000500.with(OFFSET_PTWO);
assertEquals(test, OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(11, 30, 59, 500), OFFSET_PTWO));
}
use of java.time.OffsetDateTime in project jdk8u_jdk by JetBrains.
the class TCKOffsetDateTime method test_toEpochSecond_afterEpoch.
//-----------------------------------------------------------------------
// toEpochSecond()
//-----------------------------------------------------------------------
@Test
public void test_toEpochSecond_afterEpoch() {
for (int i = 0; i < 100000; i++) {
OffsetDateTime a = OffsetDateTime.of(1970, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC).plusSeconds(i);
assertEquals(a.toEpochSecond(), i);
}
}
use of java.time.OffsetDateTime in project jdk8u_jdk by JetBrains.
the class TCKOffsetDateTime method test_compareTo_bothNanos.
@Test
public void test_compareTo_bothNanos() {
OffsetDateTime a = OffsetDateTime.of(2008, 6, 30, 11, 20, 40, 4, OFFSET_PTWO);
// a is before b on instant scale
OffsetDateTime b = OffsetDateTime.of(2008, 6, 30, 10, 20, 40, 5, OFFSET_PONE);
assertEquals(a.compareTo(b) < 0, true);
assertEquals(b.compareTo(a) > 0, true);
assertEquals(a.compareTo(a) == 0, true);
assertEquals(b.compareTo(b) == 0, true);
assertEquals(a.toInstant().compareTo(b.toInstant()) < 0, true);
assertEquals(OffsetDateTime.timeLineOrder().compare(a, b) < 0, true);
}
use of java.time.OffsetDateTime in project jdk8u_jdk by JetBrains.
the class TCKOffsetDateTime method test_getLong_TemporalField.
@Test
public void test_getLong_TemporalField() {
OffsetDateTime test = OffsetDateTime.of(LocalDate.of(2008, 6, 30), LocalTime.of(12, 30, 40, 987654321), OFFSET_PONE);
assertEquals(test.getLong(ChronoField.YEAR), 2008);
assertEquals(test.getLong(ChronoField.MONTH_OF_YEAR), 6);
assertEquals(test.getLong(ChronoField.DAY_OF_MONTH), 30);
assertEquals(test.getLong(ChronoField.DAY_OF_WEEK), 1);
assertEquals(test.getLong(ChronoField.DAY_OF_YEAR), 182);
assertEquals(test.getLong(ChronoField.HOUR_OF_DAY), 12);
assertEquals(test.getLong(ChronoField.MINUTE_OF_HOUR), 30);
assertEquals(test.getLong(ChronoField.SECOND_OF_MINUTE), 40);
assertEquals(test.getLong(ChronoField.NANO_OF_SECOND), 987654321);
assertEquals(test.getLong(ChronoField.HOUR_OF_AMPM), 0);
assertEquals(test.getLong(ChronoField.AMPM_OF_DAY), 1);
assertEquals(test.getLong(ChronoField.INSTANT_SECONDS), test.toEpochSecond());
assertEquals(test.getLong(ChronoField.OFFSET_SECONDS), 3600);
}
use of java.time.OffsetDateTime in project jdk8u_jdk by JetBrains.
the class TCKOffsetDateTime method now_Clock_offsets.
@Test
public void now_Clock_offsets() {
OffsetDateTime base = OffsetDateTime.of(1970, 1, 1, 12, 0, 0, 0, ZoneOffset.UTC);
for (int i = -9; i < 15; i++) {
ZoneOffset offset = ZoneOffset.ofHours(i);
Clock clock = Clock.fixed(base.toInstant(), offset);
OffsetDateTime test = OffsetDateTime.now(clock);
assertEquals(test.getHour(), (12 + i) % 24);
assertEquals(test.getMinute(), 0);
assertEquals(test.getSecond(), 0);
assertEquals(test.getNano(), 0);
assertEquals(test.getOffset(), offset);
}
}
Aggregations