/** * Gets the previous transition before the specified instant. * <p> * This returns details of the previous transition after the specified instant. * For example, if the instant represents a point where "summer" daylight saving time * applies, then the method will return the transition from the previous "winter" time. * * @param Instant|null $instant the instant to get the previous transition after, not null, but null * may be ignored if the rules have a single offset for all instants * @return ZoneOffsetTransition the previous transition after the specified instant, null if this is before the first transition */ public function previousTransition($instant) { if (empty($this->savingsInstantTransitions)) { return null; } $epochSec = $instant->getEpochSecond(); if ($instant->getNano() > 0 && $epochSec < Long::MAX_VALUE) { $epochSec += 1; // allow rest of method to only use seconds } // check if using last rules $lastHistoric = $this->savingsInstantTransitions[count($this->savingsInstantTransitions) - 1]; if (!empty($this->lastRules) && $epochSec > $lastHistoric) { // search year the instant is in $lastHistoricOffset = $this->wallOffsets[count($this->wallOffsets) - 1]; $year = $this->findYear($epochSec, $lastHistoricOffset); $transArray = $this->findTransitionArray($year); for ($i = count($transArray) - 1; $i >= 0; $i--) { if ($epochSec > $transArray[$i]->toEpochSecond()) { return $transArray[$i]; } } // use last from preceding year $lastHistoricYear = $this->findYear($lastHistoric, $lastHistoricOffset); if (--$year > $lastHistoricYear) { $transArray = $this->findTransitionArray($year); return $transArray[count($transArray) - 1]; } // drop through } // using historic rules $index = Math::binarySearch($this->savingsInstantTransitions, $epochSec); if ($index < 0) { $index = -$index - 1; } if ($index <= 0) { return null; } return ZoneOffsetTransition::ofEpoch($this->savingsInstantTransitions[$index - 1], $this->wallOffsets[$index - 1], $this->wallOffsets[$index]); }