use of java.time.ZonedDateTime in project jdk8u_jdk by JetBrains.
the class TCKZonedDateTime method test_get.
@Test(dataProvider = "sampleTimes")
public void test_get(int y, int o, int d, int h, int m, int s, int n, ZoneId zone) {
LocalDate localDate = LocalDate.of(y, o, d);
LocalTime localTime = LocalTime.of(h, m, s, n);
LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
ZoneOffset offset = zone.getRules().getOffset(localDateTime);
ZonedDateTime a = ZonedDateTime.of(localDateTime, zone);
assertEquals(a.getYear(), localDate.getYear());
assertEquals(a.getMonth(), localDate.getMonth());
assertEquals(a.getDayOfMonth(), localDate.getDayOfMonth());
assertEquals(a.getDayOfYear(), localDate.getDayOfYear());
assertEquals(a.getDayOfWeek(), localDate.getDayOfWeek());
assertEquals(a.getHour(), localTime.getHour());
assertEquals(a.getMinute(), localTime.getMinute());
assertEquals(a.getSecond(), localTime.getSecond());
assertEquals(a.getNano(), localTime.getNano());
assertEquals(a.toLocalDate(), localDate);
assertEquals(a.toLocalTime(), localTime);
assertEquals(a.toLocalDateTime(), localDateTime);
if (zone instanceof ZoneOffset) {
assertEquals(a.toString(), localDateTime.toString() + offset.toString());
} else {
assertEquals(a.toString(), localDateTime.toString() + offset.toString() + "[" + zone.toString() + "]");
}
}
use of java.time.ZonedDateTime in project jdk8u_jdk by JetBrains.
the class TCKZonedDateTime method test_withYear_noChange.
@Test
public void test_withYear_noChange() {
ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_0100);
ZonedDateTime test = base.withYear(2008);
assertEquals(test, base);
}
use of java.time.ZonedDateTime in project jdk8u_jdk by JetBrains.
the class TCKZonedDateTime method test_with_adjuster_LocalDateTime_adjustedOffset.
@Test
public void test_with_adjuster_LocalDateTime_adjustedOffset() {
ZonedDateTime base = ZonedDateTime.of(TEST_LOCAL_2008_06_30_11_30_59_500, ZONE_PARIS);
ZonedDateTime test = base.with(LocalDateTime.of(2012, 1, 15, 14, 30));
check(test, 2012, 1, 15, 14, 30, 0, 0, OFFSET_0100, ZONE_PARIS);
}
use of java.time.ZonedDateTime 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.ZonedDateTime in project jdk8u_jdk by JetBrains.
the class TCKZonedDateTime method test_withLaterOffsetAtOverlap_notAtOverlap.
//-----------------------------------------------------------------------
// withLaterOffsetAtOverlap()
//-----------------------------------------------------------------------
@Test
public void test_withLaterOffsetAtOverlap_notAtOverlap() {
ZonedDateTime base = ZonedDateTime.ofStrict(TEST_LOCAL_2008_06_30_11_30_59_500, OFFSET_0200, ZONE_PARIS);
ZonedDateTime test = base.withLaterOffsetAtOverlap();
// not changed
assertEquals(test, base);
}
Aggregations