Hi,
If I have a date range (StartDate-EndDate), how can I tell if this date overlaps a list of other date ranges ie (StartDate1-EndDate1; StartDate3-EndDate3; StartDate3-EndDate3;…).
This is for a scheduling type app.
Any ideas?
THX, Tony
Hi,
If I have a date range (StartDate-EndDate), how can I tell if this date overlaps a list of other date ranges ie (StartDate1-EndDate1; StartDate3-EndDate3; StartDate3-EndDate3;…).
This is for a scheduling type app.
Any ideas?
THX, Tony
Subject: How to check for date range overlapping another list of date ranges
create 3 ranges on a piece of paper and see how you as a person will solve it
Then code it.
Subject: RE: How to check for date range overlapping another list of date ranges
Well, OK but this will be open ended so I need to take into account n ranges.
Subject: RE: How to check for date range overlapping another list of date ranges
You’ll need to expand on that generallization. Do you mean …
1 - Given n date-ranges, do they ALL overlap ? (i.e. There is at least one date common to ALL of them)
or
2 - Given n date-ranges, do ANY overlap ? (i.e. There is at least one date common to 2 of them)
Subject: RE: How to check for date range overlapping another list of date ranges
Hi Graham, I mean option 2.
That is given Range A, does it overlap any of the dates in Range (B, C, D, …n) . (B, C, D…n) are all discrete and should have no overlaps.
Subject: RE: How to check for date range overlapping another list of date ranges
Then the logic is …
For each range X in (B…n) to be checked.
If End(A) < Start(X) or End(X) < Start(A)
then
A and B are distinct. - Check next range
else
There is an overlap
Subject: RE: How to check for date range overlapping another list of date ranges
One way to code this is …
Dim sess As New NotesSession, ws As New NotesUIWorkspace, uidoc As NotesUIDocument
Dim startDate1 As NotesDateTime, endDate1 As NotesDateTime
Dim startDate2 As NotesDateTime, endDate2 As NotesDateTime
Dim item As NotesItem, range() As String, i As Integer, k As Integer, overlap As Boolean, result As Boolean
'Initialize the variables
i = 0
result = False
Set uidoc = ws.CurrentDocument
Set item = uidoc.Document.GetFirstItem("DatesToUse")
'Check the dates
Forall dt In item.Values
Redim Preserve range(i)
range(i)= Cstr(dt)
If i>0 Then
Set startDate1 = sess.CreateDateTime(Strleft(range(i),"-"))
Set endDate1 = sess.CreateDateTime(Strright(range(i),"-"))
For k = 0 To i-1
overlap = True
Set startDate2 = sess.CreateDateTime(Strleft(range(k),"-"))
Set endDate2 = sess.CreateDateTime(Strright(range(k),"-"))
If startDate1.TimeDifferenceDouble(endDate2)>0 Or startDate2.TimeDifference(endDate1)>0 Then overlap = False
If overlap = True Then result = True
Next
End If
i=i+1
End Forall
'Return the result
Call uidoc.FieldSetText("Overlap",Cstr(result))
Here the code is in a button that reads from a multivalue text field called DatesToUse that contains entries in the form of mm/dd/yy-mm/dd/yy and places the result in a text field called Overlap.