< prev index next >
src/java.base/share/classes/java/time/zone/ZoneRules.java
Print this page
rev 58174 : 8239836: ZoneRules.of() doesn't check transitionList/standardOffsetTL arguments validity
Reviewed-by: rriggs
*** 468,478 ****
* Checks of the zone rules are fixed, such that the offset never varies.
*
* @return true if the time-zone is fixed and the offset never changes
*/
public boolean isFixedOffset() {
! return savingsInstantTransitions.length == 0;
}
/**
* Gets the offset applicable at the specified instant in these rules.
* <p>
--- 468,478 ----
* Checks of the zone rules are fixed, such that the offset never varies.
*
* @return true if the time-zone is fixed and the offset never changes
*/
public boolean isFixedOffset() {
! return standardTransitions.length == 0 && savingsInstantTransitions.length == 0;
}
/**
* Gets the offset applicable at the specified instant in these rules.
* <p>
*** 483,498 ****
* @param instant the instant to find the offset for, not null, but null
* may be ignored if the rules have a single offset for all instants
* @return the offset, not null
*/
public ZoneOffset getOffset(Instant instant) {
! if (savingsInstantTransitions.length == 0) {
return standardOffsets[0];
}
long epochSec = instant.getEpochSecond();
// check if using last rules
if (lastRules.length > 0 &&
epochSec > savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
int year = findYear(epochSec, wallOffsets[wallOffsets.length - 1]);
ZoneOffsetTransition[] transArray = findTransitionArray(year);
ZoneOffsetTransition trans = null;
for (int i = 0; i < transArray.length; i++) {
--- 483,499 ----
* @param instant the instant to find the offset for, not null, but null
* may be ignored if the rules have a single offset for all instants
* @return the offset, not null
*/
public ZoneOffset getOffset(Instant instant) {
! if (isFixedOffset()) {
return standardOffsets[0];
}
long epochSec = instant.getEpochSecond();
// check if using last rules
if (lastRules.length > 0 &&
+ savingsInstantTransitions.length > 0 &&
epochSec > savingsInstantTransitions[savingsInstantTransitions.length - 1]) {
int year = findYear(epochSec, wallOffsets[wallOffsets.length - 1]);
ZoneOffsetTransition[] transArray = findTransitionArray(year);
ZoneOffsetTransition trans = null;
for (int i = 0; i < transArray.length; i++) {
*** 638,652 ****
Object info = getOffsetInfo(localDateTime);
return (info instanceof ZoneOffsetTransition ? (ZoneOffsetTransition) info : null);
}
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);
--- 639,654 ----
Object info = getOffsetInfo(localDateTime);
return (info instanceof ZoneOffsetTransition ? (ZoneOffsetTransition) info : null);
}
private Object getOffsetInfo(LocalDateTime dt) {
! if (isFixedOffset()) {
return standardOffsets[0];
}
// check if using last rules
if (lastRules.length > 0 &&
+ savingsInstantTransitions.length > 0 &&
dt.isAfter(savingsLocalTransitions[savingsLocalTransitions.length - 1])) {
ZoneOffsetTransition[] transArray = findTransitionArray(dt.getYear());
Object info = null;
for (ZoneOffsetTransition trans : transArray) {
info = findOffsetInfo(dt, trans);
*** 754,764 ****
* @param instant the instant to find the offset information for, not null, but null
* may be ignored if the rules have a single offset for all instants
* @return the standard offset, not null
*/
public ZoneOffset getStandardOffset(Instant instant) {
! if (savingsInstantTransitions.length == 0) {
return standardOffsets[0];
}
long epochSec = instant.getEpochSecond();
int index = Arrays.binarySearch(standardTransitions, epochSec);
if (index < 0) {
--- 756,766 ----
* @param instant the instant to find the offset information for, not null, but null
* may be ignored if the rules have a single offset for all instants
* @return the standard offset, not null
*/
public ZoneOffset getStandardOffset(Instant instant) {
! if (isFixedOffset()) {
return standardOffsets[0];
}
long epochSec = instant.getEpochSecond();
int index = Arrays.binarySearch(standardTransitions, epochSec);
if (index < 0) {
*** 784,794 ****
* @param instant the instant to find the daylight savings for, not null, but null
* may be ignored if the rules have a single offset for all instants
* @return the difference between the standard and actual offset, not null
*/
public Duration getDaylightSavings(Instant instant) {
! if (savingsInstantTransitions.length == 0) {
return Duration.ZERO;
}
ZoneOffset standardOffset = getStandardOffset(instant);
ZoneOffset actualOffset = getOffset(instant);
return Duration.ofSeconds(actualOffset.getTotalSeconds() - standardOffset.getTotalSeconds());
--- 786,796 ----
* @param instant the instant to find the daylight savings for, not null, but null
* may be ignored if the rules have a single offset for all instants
* @return the difference between the standard and actual offset, not null
*/
public Duration getDaylightSavings(Instant instant) {
! if (isFixedOffset()) {
return Duration.ZERO;
}
ZoneOffset standardOffset = getStandardOffset(instant);
ZoneOffset actualOffset = getOffset(instant);
return Duration.ofSeconds(actualOffset.getTotalSeconds() - standardOffset.getTotalSeconds());
< prev index next >