internal ZoneInterval GetZoneInterval(Instant instant) { if (seam.Contains(instant)) { return(seam); } return(adjustmentZone.GetZoneInterval(instant)); }
/// <summary> /// Returns the zone interval for the given instant in time. See <see cref="ZonedDateTime"/> for more details. /// </summary> public ZoneInterval GetZoneInterval(Instant instant) { if (headInterval != null && headInterval.Contains(instant)) { return(headInterval); } if (tailInterval != null && tailInterval.Contains(instant)) { return(tailInterval); } // Avoid having to worry about Instant.MaxValue for the rest of the class. if (instant == Instant.MaxValue) { return(adjustmentIntervals[adjustmentIntervals.Count - 1].GetZoneInterval(instant)); } int lower = 0; // Inclusive int upper = adjustmentIntervals.Count; // Exclusive while (lower < upper) { int current = (lower + upper) / 2; var candidate = adjustmentIntervals[current]; if (candidate.Start > instant) { upper = current; } else if (candidate.End <= instant) { lower = current + 1; } else { return(candidate.GetZoneInterval(instant)); } } throw new InvalidOperationException ("Instant " + instant + " did not exist in the range of adjustment intervals"); }