|
-
Nov 2nd, 2005, 10:47 PM
#1
Thread Starter
PowerPoster
Algorithm problem!
Hi!
I guess im REALLLLY tired at the minute and will think this through tomorrow but its something that isnt going to make me go to bed easily!
OK:
I have a start time and end time
a user also enters a start time and end time
I want to see that if the user's entered start time and time conflicts with the set start time and end time.
how do I find this out?
I will have 2 DateTime objects for each date time set. One object will be the start time and the other the end time.
so i wanna check if the user entered their start/end time does NOT conflict with another start/end time.
how?
-
Nov 2nd, 2005, 10:59 PM
#2
Re: Algorithm problem!
Define "conflict". Here's an example but it might not do what you want:
VB Code:
If (startTime2 >= startTime1 AndAlso startTime2 < endTime1) OrElse _
(endTime2 > startTime1 AndAlso endTime2 <= endTime1) OrElse _
(startTime2 <= startTime1 AndAlso endTime2 >= endTime1) Then
MessageBox.Show("Intervals overlap.")
End If
-
Nov 2nd, 2005, 11:28 PM
#3
Re: Algorithm problem!
Or even
Code:
if ((endTime1 > startTime1) && (endTime2 > startTime2) &&
((startTime2 >= endTime1) || (endTime2 <= startTime1)))
{
// intervals do not overlap
}
else
{
// overlap
}
Last edited by penagate; Nov 2nd, 2005 at 11:40 PM.
-
Nov 3rd, 2005, 12:07 AM
#4
Re: Algorithm problem!
Oops. C#, yeah... Nice penagate.
-
Nov 3rd, 2005, 04:12 AM
#5
Thread Starter
PowerPoster
Re: Algorithm problem!
hehe thanks, i think that's pretty much what I had in mind
what i mean by conflict is basically the times collashing together
-
Nov 3rd, 2005, 09:35 PM
#6
Thread Starter
PowerPoster
Re: Algorithm problem!
lol im sorry guys
just forgotten this completely.
right, im trying to save these times etc... in an XML file. BUT i want them ordered, in otherwords, I want each record to be stored sequentially on the date time
does that make sense?
so when a user enters a date/time, that is saved to the xml file
but when it is saving, it checks the xml nodes to see where it can fit in this new node to make sure that the times/dates do not collash
understand? :-s
how can I make this work?
open xml file
for each node
make date time object
if xmlNode DateTime object < the user set date/time
.. ??
end for each
-
Nov 6th, 2005, 09:17 PM
#7
Thread Starter
PowerPoster
Re: Algorithm problem!
im afraid that solution did not work!
-
Nov 6th, 2005, 09:26 PM
#8
Re: Algorithm problem!
In that case you are going to have to explain, clearly, what exactly you want, and why the solutions given don't work for you. What do you mean by "collashing" ?
-
Nov 6th, 2005, 09:45 PM
#9
Thread Starter
PowerPoster
Re: Algorithm problem!
as said before - to make sure that they do not overlap
so for example:
starttime1: 3.00 endtime1: 4.00
starttime2: 4.01 endtime2: 5.12
starttime3: 3.23 endtime3: 3:59
in that example, starttime3 will collash - because starttime1 and endtime1 fit in that range.
Basically no time should interfere with any other time, making sure that each time is more or less than the previous time but certainly making sure that they do not collide with each other.
take for example your daily routine
you may have several meetings but you have to make sure that you do not have 2 meetings at 1 time but to make sure one proceeds the next....
-
Nov 6th, 2005, 10:03 PM
#10
Re: Algorithm problem!
Put all your start times into one array and end times into another array.
Then you can check against all of them when adding a new one.
Code:
if (newEnd > newStart)
{
for (int i = 0; i < startTimes.GetUpperBound(0); i++)
{
if (((newStart >= startTimes[i]) && (newStart <= endTimes[i])) ||
((newEnd >= startTimes[i]) && (newEnd <= endTimes[i])))
{
MessageBox.Show("Intervals overlap.");
}
else
{
// Add the node
}
}
}
else
{
MessageBox.Show("Idiot, you can't finish before you start.");
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|