Thanks for your reply. I solved the issue a different way. I made a method in the Person class.
I was going to post this as a comment but it is too many characters.
However to directly answer your question:
Each item in the list has a start time and a minimum time. So for example:
Item 0 in the list: Start time: 09:00 and minimum time 30 mins
Item 1 in the list: Start time: 10:00 and minimum time 30 mins
Item 2 in the list: Start time: 11:00 and minimum time 30 mins
I have a search time that I want to compare to the items in the list. The logic should be as follows:
The search time should be above the start time of the list item
If there is a consecutive item in the list then the search time should be below the start time of the consecutive item
If there is no consecutive item then the search time should be below start time + min time
Some examples:
Example 1:
Search time: 10:45
Result should be list item 1 because:
10:45 is above the start time of item 1 (10:45 > 10:00)
Item 2 exists and the search time is below the start time of item 2 (10:45<11:00)
Example 2:
Search time: 11:15
Result should be item 2 because:
11:15 is above the start time of item 2 (11:15 > 11:00)
There is no item 3 so the search time should be compared to the start time (11:00) + min time (30 minutes). 11:15 is less then 11:30 so this is the required list item.
Example 3:
Search time: 11:45
There should be no result (or alternatively a null result) because:
11:45 is above the start time of item 2 (11:45 > 11:00)
There is no item 3 so the search time should be compared to the start time (11:00) + min time (30 minutes). 11:45 is after 11:30 so no items in the list match the search time
The number of items in the list could vary.
As I said I have solved the problem using a different solution so my question is not important. I would be interested to know the answer because it might be useful in the future however I am happy to mark the question closed if that is the appropriate thing to do?
Thanks