Win a copy of Functional Reactive Programming this week in the Other Languages forum!

# overlapping dates

John Jordan John Jordan
Greenhorn
Posts: 4
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

Nayanjyoti Talukdar
Ranch Hand
Posts: 71
Do u mean that u have to find out a method to check out the two date information?If not, what do u mean by overlapping of date?
----------
Nayan.

John Lee
Ranch Hand
Posts: 2545
overlapping date? what is the definition for it?
In your example, two input are all dates, representing two moments. There is no overlap for two moments. Only two states are: same, or not same.

Blake Minghelli
Ranch Hand
Posts: 331
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.

Layne Lund
Ranch Hand
Posts: 3061
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.

John Lee
Ranch Hand
Posts: 2545
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
Posts: 2545
While I am not sure about the overlapping dates thing, but I do find out you have a overlapping names.