* @param instantProvider the instant to get the previous transition after, not null
* @return the previous transition after the specified instant, null if this is before the first transition
*/
@Override
public ZoneOffsetTransition previousTransition(InstantProvider instantProvider) {
Instant instant = Instant.instant(instantProvider);
long epochSecs = instant.getEpochSeconds();
if (instant.getNanoOfSecond() > 0 && epochSecs < Long.MAX_VALUE) {
epochSecs += 1; // allow rest of method to only use seconds
}
// check if using last rules
long lastHistoric = savingsInstantTransitions[savingsInstantTransitions.length - 1];
if (lastRules.length > 0 && epochSecs > lastHistoric) {
ZoneOffset lastHistoricOffset = wallOffsets[wallOffsets.length - 1];
OffsetDateTime dt = OffsetDateTime.fromInstant(instant, lastHistoricOffset);
OffsetDateTime lastHistoricDT = OffsetDateTime.fromInstant(Instant.instant(lastHistoric), lastHistoricOffset);
for (Year year = dt.toYear(); year.getValue() > lastHistoricDT.getYear(); year = year.previous()) {
ZoneOffsetTransition[] transArray = findTransitionArray(year);
for (int i = transArray.length - 1; i >= 0; i--) {
if (instant.isAfter(transArray[i].getInstant())) {
return transArray[i];
}
}
}
}
// using historic rules
int index = Arrays.binarySearch(savingsInstantTransitions, epochSecs);
if (index < 0) {
index = -index - 1;
}
if (index <= 0) {
return null;
}
Instant transitionInstant = Instant.instant(savingsInstantTransitions[index - 1]);
OffsetDateTime trans = OffsetDateTime.fromInstant(transitionInstant, wallOffsets[index - 1]);
return createTransition(trans, wallOffsets[index]);
}