wood burning stoves 2.0*
The moose likes Java in General and the fly likes overlapping dates Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Java in General
Bookmark "overlapping dates" Watch "overlapping dates" New topic
Author

overlapping dates

John Jordan John Jordan
Greenhorn

Joined: Jan 19, 2003
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

Joined: Feb 12, 2002
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

Joined: Aug 05, 2001
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

Joined: Sep 13, 2002
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.


Blake Minghelli<br />SCWCD<br /> <br />"I'd put a quote here but I'm a non-conformist"
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
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.


Java API Documentation
The Java Tutorial
John Lee
Ranch Hand

Joined: Aug 05, 2001
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

Joined: Aug 05, 2001
Posts: 2545
While I am not sure about the overlapping dates thing, but I do find out you have a overlapping names.
 
GeeCON Prague 2014
 
subject: overlapping dates