[phobos] datetime review
Jonathan M Davis
jmdavisProg at gmx.com
Thu Oct 14 16:14:51 PDT 2010
On Thursday, October 14, 2010 16:06:28 Andrei Alexandrescu wrote:
> On 10/14/10 17:01 CDT, Jonathan M Davis wrote:
> > What's really annoying is when you want to create a range which iterates
> > over time points which are apart by some combination of years, months,
> > and smaller units.
>
> The more I think of it the more I want this feature out. It would be
> borderline nice if it were a natural consequence of the design, but
> sweating over it doesn't sit well at all.
>
> > Before, you could just give the function something like Dur.years(5) +
> > Dur.months(1) + Dur.days(2) and it would produce a function which gave
> > you a time point 5 years, 1 month, and 2 days after the previous one.
> > But without MonthDuration or JointDuration, that becomes much more
> > awkward. I'm still ironing out the best way to deal with the function
> > signature for that.
>
> I could say
>
> d.addYear(5);
> d.addMonths(1);
> d.addDays(2);
>
> This is acceptable considering that it's not that often you really need
> to be 5 years, 1 month, and 2 days from now. Besides it's weird. What if
> I take 27 January 2010 and then skip that duration? Will I be on Feb 28
> 2015 or Mar 1 2015? I don't know, and the simple fact that I need to ask
> myself (and that the library needs to respond) such an awkard question
> is embarrassing.
>
> If it were me I'd even postulate that addMonths takes you to the 1st of
> the landing month. Or eliminate addMonths and addYears altogether,
> because adding 1 year to 29 February 2008 does not land on a good date.
> Allow the user to construct a new Date from the current year, month, and
> day.
The problem is ranges, not just typical adding. If you're doing typical adding,
then it's easy. And I suppose that the range side wouldn't be all that hard
either if you just forced the programmer to create their own delegate for it
rather than trying to give them a nice function to generate such a delegate. As
you point out, not many folks are likely to want to iterate over such weird
durations of time anyway.
As for the odd dates, AllowDayOverflow deals with that, though it is true that
with adding MonthDurations, it ignored that, so you were kind of hung out to dry
there.
- Jonathan M Davis
More information about the phobos
mailing list