public LocalTime FindDateTime(TimeSpan time) { if (To == null) { throw new InvalidOperationException("FindDateTime can only be used if there is a value for To"); } var date = From.BeginningOfDay(); while (date <= To) { var candidate = date.Add(time); if (IsActiveAt(candidate)) { return(candidate); } date = date.Add(1.Days()); } throw new InvalidOperationException("Unable to find the matching time"); }