commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "matthew.hawthorne" <ma...@apache.org>
Subject Re: [lang]/[servlet] Doing some tickling
Date Tue, 08 Mar 2005 20:45:20 GMT
Frank W. Zammetti wrote:
> My feeling is that this would lead to confusion... The code I proposed is
> specifically for checking TIME ranges, but looking at your suggestion, I
> can't tell if it would work in determing if an hour fell within a given
> range.  It might, but I can't tell from what you've posted here.  It also,
> in my particular use case, has to work when the range start time is on a
> Monday and the range end time is on a Tuesday.

I'm fairly sure that it would.

My 'contains' method looks something like this:
public boolean contains(Date d) {
   return this.startDate.before(d) && this.endDate.after(d);
}

with 'startDate' and 'endDate' being the 2 dates that are passed into 
the DateRange(Date, Date) constructor.


> I think the object to ints that you and also Henri I think talked about is
> valid, but note that you only supply a single int for range start and end,
> you don't specify hours and minutes separately.  It is this way because
> that's exactly what you get if you do Calendar.get(Calendar.HOUR_OF_DAY;. 
> Henri already talked about adding a version to accept a Date, which I
> think makes sense, as long as its an overloaded version, I certainly have
> no objection.

I can't claim that I completely follow you here -- but I think I get the 
  fundamental point.

I can appreciate your desire to only provide hours and minutes, if that 
is all that you care about.  Part of the problem is that Java only deals 
with dates in the full context: year, month, day, hour, seconds, etc. 
So, stripping some of that information away may make the calculations a 
bit trickier.

I like the idea of the 'TimeRange' object that was mentioned earlier.
I think that may make the simple hour & second calculations easier to 
deal with.

However, I think this would suffice only if the comparison takes place 
within a single day.  Once the calculation spreads across multiple days, 
I think it would be better assisted with Date objects, to give it the 
additional context.

If the difference in 2 Dates is required, then it may also be nice to 
create a simple class that can convert milliseconds (from 
Date.getTime()) into more useful units, like seconds, hours, days, etc. 
  I understand that this is simple math, but it can also be repetitive, 
so it may be worth thinking about.

Again, this depends on the requirements.  I may be going off on some 
weird tangents here.


> Now, all that being said, I for one say post your class if something like
> it doesn't already exist.  Being able to determine if a date falls within
> a given range is also a valuable function for sure. :)

OK, sounds good.  I'll try to clean it up and post it to Bugzilla when I 
get a chance.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message