You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Fredrik Westermarck <fr...@mdh.se> on 2004/01/14 19:46:40 UTC
[lang] DateRange
Hi!
Since I need a DateRange class myself, I thought I'd start working on it.
Is there any specification or old discussions about what the class
should do? All I could find in the maillist archives about the class was
<http://marc.theaimsgroup.com/?l=jakarta-commons-dev&m=104014855502915&w=2>,
which wasn't that helpful...
However I've come up with the following methods that could be useful for
DateRange:
- getDifference(), the difference between start and stop in milliseconds
- beforeStart(Date), if the parameter is before the start of the range
- afterEnd(Date), if the parameter is after the end of the range
- contains(Date), if the parameter is within the range
- contains(DateRange), if the supplied range is within the range
What do you folks think about the naming and scope of the methods?
Anyone that may have suggestions about additional methods that could be
useful?
Regards,
Fredrik Westermarck
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [lang] DateRange
Posted by "Todd V. Jonker" <to...@consciouscode.com>.
Fredrik,
I recently wrote a DateRange class for a client, and unfortunately can't
contribute it. I'll sketch out the design that was most useful.
The class stores two Calendars, start and limit. Most methods come in
pairs using Calendar and Date, the latter converting to/from Calendar
using the default locale. The primal access methods are:
Date getStartDate()
Date getLimitDate()
void setRange(Calendar start, Calendar limit)
Note the important invariants:
range.getStartDate().getTime() < range.getLimitDate().getTime()
range.contains(range.getStartDate())
! range.contains(range.getLimitDate())
The latter aids in implementing ranges that are in units of
days/months/years: we represent a month as something like "2004/01/01
00:00.000" through "2004/02/01 00:00.000" -- the sub-day fields are
zeroed out to make day manipulations easy.
Other helpful methods are statics that construct common ranges like
'year-to-date':
static DateRange makeMonthPriorTo(Calendar cal)
static DateRange makeQuarterPriorTo(Calendar cal)
static DateRange makeYearToMonthPriorTo(Calendar cal)
static Calendar startOfMonth(Calendar calendar)
static Calendar startOfQuarter(Calendar calendar)
I don't really know if the concept of "quarter" is universal across
locales, but we needed it so there it is.
Cheers,
.T.
Todd V. Jonker
Conscious Code Ltd
Helping you make software better
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org
Re: [lang] DateRange
Posted by Steve Cohen <sc...@javactivity.org>.
how about
DateRange intersection(DateRange)? (A generalization of contains()).
void add(int unit, int quantity) - params as with Calendar.add(). Apply the
same offset to both start and end to move the range forward or backward.
Constructors:
DateRange(Date start,Date end)
DateRange(Date start, long duration) (milliseconds)
DateRange(Date start, int unit, int quantity) (params as in Calendar.add())
On Wednesday 14 January 2004 12:46, Fredrik Westermarck wrote:
> Hi!
>
> Since I need a DateRange class myself, I thought I'd start working on it.
>
> Is there any specification or old discussions about what the class
> should do? All I could find in the maillist archives about the class was
> <http://marc.theaimsgroup.com/?l=jakarta-commons-dev&m=104014855502915&w=2>
>, which wasn't that helpful...
>
> However I've come up with the following methods that could be useful for
> DateRange:
>
> - getDifference(), the difference between start and stop in milliseconds
> - beforeStart(Date), if the parameter is before the start of the range
> - afterEnd(Date), if the parameter is after the end of the range
> - contains(Date), if the parameter is within the range
> - contains(DateRange), if the supplied range is within the range
>
> What do you folks think about the naming and scope of the methods?
>
> Anyone that may have suggestions about additional methods that could be
> useful?
>
> Regards,
> Fredrik Westermarck
>
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org