Joshua Hoblit wrote:
>
> > I'm trying to figure out how to allow
> > for incomplete year/month/day, year/week/day,
> > or year/day in DT::I.
> >
> > One way is to have a separate implementation
> > for each case:
>
> Is it possible express all of these as:
>
> If year is known:
>
> a DateTime + a DT::Duration
>
> If year is not known:
>
> a null + a DT::Duration
That's more or less how it works, actually :)
> > DateTime::Incomplete
> >
> > year / set_year
> > month / set_month
> > day / set_day
>
> DateTime->new( year => $y ) or a undef
> DateTime::Duration( months => $m, days => $d );
>
> >
> > DateTime::Incomplete::YearWeekDay
> >
> > week_year / set_week_year
> > week_number / set_week_number
> > day_of_week / set_day_of_week
>
> DateTime->new( year => $y ) or a undef
> DateTime::Duration( weeks => $w, days => $d );
No, year-week-day is a _different_ calendar.
That's why DateTime has "week_year".
> > DateTime::Incomplete::YearDay
> >
> > year / set_year
> > day_of_year / set_day_of_year
>
> DateTime->new( year => $y ) or a undef
> DateTime::Duration( days => $d );
>
> This would also make to_datetime pretty simple.
It _is_ pretty simple (pseudo code):
$result = $base->clone;
while (($key, $value) = each %has )
{
$result->set( $key => $value );
}
> > Another approach: the API would remember what
> > methods were called, and adjust to that:
> > if you called "set_week_number", then it is
> > an error if you call "set_month".
>
> How about checking to see if an opposing value is
> already set?
Yes, that's what I mean.
Do you think this is better than having _separate_
implementations for each calendar type?
Separate implementations would allow for easier
error checking (there will be a different syntax
for each class) and better program documentation.
But a more "intelligent", single implementation, is
easier to use.
PS: I forgot to mention year-quarter-day.
- Flavio S. Glock