use of java.time.ZoneOffset 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.ZoneOffset 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.ZoneOffset in project jdk8u_jdk by JetBrains.
the class TCKZoneOffset method test_factory_int_hours.
//-----------------------------------------------------------------------
@Test
public void test_factory_int_hours() {
for (int i = -18; i <= 18; i++) {
ZoneOffset test = ZoneOffset.ofHours(i);
doTestOffset(test, i, 0, 0);
}
}
use of java.time.ZoneOffset in project jdk8u_jdk by JetBrains.
the class TCKZoneOffset method test_factory_int_hours_minutes_seconds.
//-----------------------------------------------------------------------
@Test
public void test_factory_int_hours_minutes_seconds() {
for (int i = -17; i <= 17; i++) {
for (int j = -59; j <= 59; j++) {
for (int k = -59; k <= 59; k++) {
if ((i < 0 && j <= 0 && k <= 0) || (i > 0 && j >= 0 && k >= 0) || (i == 0 && ((j < 0 && k <= 0) || (j > 0 && k >= 0) || j == 0))) {
ZoneOffset test = ZoneOffset.ofHoursMinutesSeconds(i, j, k);
doTestOffset(test, i, j, k);
}
}
}
}
ZoneOffset test1 = ZoneOffset.ofHoursMinutesSeconds(-18, 0, 0);
doTestOffset(test1, -18, 0, 0);
ZoneOffset test2 = ZoneOffset.ofHoursMinutesSeconds(18, 0, 0);
doTestOffset(test2, 18, 0, 0);
}
use of java.time.ZoneOffset in project jdk8u_jdk by JetBrains.
the class TCKZoneOffset method test_equals.
//-----------------------------------------------------------------------
// equals() / hashCode()
//-----------------------------------------------------------------------
@Test
public void test_equals() {
ZoneOffset offset1 = ZoneOffset.ofHoursMinutesSeconds(1, 2, 3);
ZoneOffset offset2 = ZoneOffset.ofHoursMinutesSeconds(2, 3, 4);
ZoneOffset offset2b = ZoneOffset.ofHoursMinutesSeconds(2, 3, 4);
assertEquals(offset1.equals(offset2), false);
assertEquals(offset2.equals(offset1), false);
assertEquals(offset1.equals(offset1), true);
assertEquals(offset2.equals(offset2), true);
assertEquals(offset2.equals(offset2b), true);
assertEquals(offset1.hashCode() == offset1.hashCode(), true);
assertEquals(offset2.hashCode() == offset2.hashCode(), true);
assertEquals(offset2.hashCode() == offset2b.hashCode(), true);
}
Aggregations