overlapping dates

Hi: I have been presented with problem of developing a method for determing overlapping dates. If I am given the following two string; how would I extract and test the date information to deternmine if I had overlaping dates? Can someone help me get started with developing a method? Ex: a1 = new A("15/04/02 11:15 pm", "15/04/02:11:30"); a2 = new A("15/04/02 11:20 pm", "15/04/02:11:35"); Regards, John

Originally posted by John Jordan John Jordan: Hi: I have been presented with problem of developing a method for determing overlapping dates. If I am given the following two string; how would I extract and test the date information to deternmine if I had overlaping dates? Can someone help me get started with developing a method? Ex: a1 = new A("15/04/02 11:15 pm", "15/04/02:11:30"); a2 = new A("15/04/02 11:20 pm", "15/04/02:11:35"); Regards, John

Each of the two "A" objects contain a date range (e.g. 15/04/02 11:15 - 15/04/02 11:30 (a 15 minute range)). I think John is asking how to determine if the two ranges represented by "a1" and "a2" overlap. Assuming I'm understanding that correctly, I suppose you could check to see if the first date in "a2" is >= first date in "a1" AND <= second date in "a1". If not, then you would also need to do the same check using the second date in "a2". To do the date comparsions, you'll need to use the DateFormat class to parse the strings into Date objects. Then I'd suggest you use the getTime() method of Date to express the dates as int's so you can do the comparisons. Someone might have a better suggestion but hopefully this helps.

First it seems you need to convert a String to something you can handle as a date. Check out the DateFormat.parse() method. It seems to have exactly what you want. Next, you need to detect if date ranges overlap. As stated earlier, you need to come up with a clear definition as to what you mean by "overlapping dates." I suggest you write something down. If your definition is clear enough, you should be able write the code to detect when they overlap and even return the range for the overlap.

Now I am kind of getting it. Function A() is not what you are after. You use A() twice, each time to get a a range, then you want to know if overlap exists? I think it is easy: all you need to do is to find out: 1) which range start ealier; 2) whether the range that start ealier finish after the second range starts;

John Lee
Ranch Hand

Joined: Aug 05, 2001
Posts: 2545

posted Feb 23, 2003 14:14:00

0

While I am not sure about the overlapping dates thing, but I do find out you have a overlapping names.