use of java.time.ZoneOffset in project jdk8u_jdk by JetBrains.
the class ZoneRules method getOffsetInfo.
private Object getOffsetInfo(LocalDateTime dt) {
if (savingsInstantTransitions.length == 0) {
return standardOffsets[0];
}
// check if using last rules
if (lastRules.length > 0 && dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
Object info = null;
for (ZoneOffsetTransition trans : transArray) {
info = findOffsetInfo(dt, trans);
if (info instanceof ZoneOffsetTransition || info.equals(trans.getOffsetBefore())) {
return info;
}
}
return info;
}
// using historic rules
int index = Arrays.binarySearch(savingsLocalTransitions, dt);
if (index == -1) {
// before first transition
return wallOffsets[0];
}
if (index < 0) {
// switch negative insert position to start of matched range
index = -index - 2;
} else if (index < savingsLocalTransitions.length - 1 && savingsLocalTransitions[index].equals(savingsLocalTransitions[index + 1])) {
// handle overlap immediately following gap
index++;
}
if ((index & 1) == 0) {
// gap or overlap
LocalDateTime dtBefore = savingsLocalTransitions[index];
LocalDateTime dtAfter = savingsLocalTransitions[index + 1];
ZoneOffset offsetBefore = wallOffsets[index / 2];
ZoneOffset offsetAfter = wallOffsets[index / 2 + 1];
if (offsetAfter.getTotalSeconds() > offsetBefore.getTotalSeconds()) {
// gap
return new ZoneOffsetTransition(dtBefore, offsetBefore, offsetAfter);
} else {
// overlap
return new ZoneOffsetTransition(dtAfter, offsetBefore, offsetAfter);
}
} else {
// normal (neither gap or overlap)
return wallOffsets[index / 2 + 1];
}
}
use of java.time.ZoneOffset in project jdk8u_jdk by JetBrains.
the class TCKLocalDateTime method test_toEpochSecond_afterEpoch.
//-----------------------------------------------------------------------
// toEpochSecond()
//-----------------------------------------------------------------------
@Test
public void test_toEpochSecond_afterEpoch() {
for (int i = -5; i < 5; i++) {
ZoneOffset offset = ZoneOffset.ofHours(i);
for (int j = 0; j < 100000; j++) {
LocalDateTime a = LocalDateTime.of(1970, 1, 1, 0, 0).plusSeconds(j);
assertEquals(a.toEpochSecond(offset), j - i * 3600);
}
}
}
use of java.time.ZoneOffset in project jdk8u_jdk by JetBrains.
the class TCKZoneOffset method test_factory_string_hours_minutes_seconds_colon.
@Test
public void test_factory_string_hours_minutes_seconds_colon() {
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))) {
String str = (i < 0 || j < 0 || k < 0 ? "-" : "+") + Integer.toString(Math.abs(i) + 100).substring(1) + ":" + Integer.toString(Math.abs(j) + 100).substring(1) + ":" + Integer.toString(Math.abs(k) + 100).substring(1);
ZoneOffset test = ZoneOffset.of(str);
doTestOffset(test, i, j, k);
}
}
}
}
ZoneOffset test1 = ZoneOffset.of("-18:00:00");
doTestOffset(test1, -18, 0, 0);
ZoneOffset test2 = ZoneOffset.of("+18:00:00");
doTestOffset(test2, 18, 0, 0);
}
use of java.time.ZoneOffset in project jdk8u_jdk by JetBrains.
the class TCKZoneOffset method test_adjustInto_dateOnly.
@Test(expectedExceptions = DateTimeException.class)
public void test_adjustInto_dateOnly() {
ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
base.adjustInto((LocalDate.of(1909, 2, 2)));
}
use of java.time.ZoneOffset in project jdk8u_jdk by JetBrains.
the class TCKZoneOffset method test_adjustInto_OffsetDateTime.
@Test
public void test_adjustInto_OffsetDateTime() {
ZoneOffset base = ZoneOffset.ofHoursMinutesSeconds(1, 1, 1);
for (int i = -18; i <= 18; i++) {
OffsetDateTime offsetDateTime_target = OffsetDateTime.of(LocalDate.of(1909, 2, 2), LocalTime.of(10, 10, 10), ZoneOffset.ofHours(i));
OffsetDateTime offsetDateTime_result = (OffsetDateTime) base.adjustInto(offsetDateTime_target);
assertEquals(base, offsetDateTime_result.getOffset());
//Do not change offset of ZonedDateTime after adjustInto()
ZonedDateTime zonedDateTime_target = offsetDateTime_target.toZonedDateTime();
ZonedDateTime zonedDateTime_result = (ZonedDateTime) (base.adjustInto(zonedDateTime_target));
assertEquals(zonedDateTime_target.getOffset(), zonedDateTime_result.getOffset());
}
}
Aggregations