Sorry in advance for the long question. Feedback is especially appreciated here.,.
In my work, we do a lot of things with date ranges (date periods, if you want). We need to take all kinds of measurements, compare the overlap between two dates, etc. I developed an interface, a base class, and several derived classes that serve my needs well:
- IDatePeriod
- DatePeriod
- Calendarmonth
- Calendarweek
- Fiscalyear
Divided at its core, the superclass of the DatePeriod class looks like this (omits all the fun features that are the basis for why we need this set of classes ...):
(Java pseudo code):
class datePeriod implements IDatePeriod
protected Calendar periodStartDate
protected Calendar periodEndDate
public DatePeriod(Calendar startDate, Calendar endDate) throws DatePeriodPrecedenceException
{
periodStartDate = startDate
. . .
. . .
periodEndDate = endDate
{
public void setStartDate(Calendar startDate)
{
periodStartDate = startDate
. . .
. . .
{
public void setEndDate(Calendar endDate) throws datePeriodPrecedenceException
{
periodEndDate = EndDate
. . .
. . .
{
}
. , . , , CalendarMonth "" DatePeriod. . , CalendarMonth ( startDate endDate), , Calendar.
CalendarMonth, CalendarMonth, , , .
public class CalendarMonth extends DatePeriod
public CalendarMonth(Calendar dateInMonth)
{
}
public CalendarMonth(Calendar startDate, Calendar endDate)
{
this(startDate)
}
public void setStartDate(Calendar startDate)
{
periodStartDate = startDate
. . .
. . .
{
public void setEndDate(Calendar endDate) throws datePeriodPrecedenceException
{
{
}
. , , . CAN CalendarMonth , DatePeriod, . , , CalendarMonth.
CalendarMonth ( CalendarWeek ..) , IDatePeriod , , CalendarMonth, DatePeriod., ( , -, , - , CalendarMonth).
, LSP / ?