Please vote on std.datetime

Dmitry Olshansky dmitry.olsh at gmail.com
Fri Dec 10 08:15:09 PST 2010


On 10.12.2010 3:26, Andrei Alexandrescu wrote:
> Jonathan M. Davis has diligently worked on his std.datetime proposal, 
> and it has been through a few review cycles in this newsgroup.
>
> It's time to vote. Please vote for or against inclusion of datetime 
> into Phobos, along with your reasons.
>
>
> Thank you,
>
> Andrei

First, let me state my concerns.
I'm very disappointed with how the range interface introduced in 
std.datetime, let me pick an example from ddoc:
auto interval = Interval!Date(Date(2010, 9, 2), Date(2010, 9, 27));
auto func = IRange.everyDayOfWeek!(Date, >>>Direction.bwd 
<<<)(DayOfWeek.fri);
auto range = interval.>>>bwdRange<<<(func);

*(emphasis mine)
Note the verbosity caused by conflating two concepts  - the flexible way 
of getting a range of time points by consequently applying the delegate 
to a given start time point, and traversing an interval of time in a 
certain direction.

Time ago I pointlessly argued with Jonathon to just drop the flexible 
way of iterating intervals, replacing it by simplistic "stride by a 
adding given duration to the begining of interval until you hit end". In 
the end I observed it was very limited view as it can't effectively 
solve the "give me the next five Easters" problem, and  hastily retreated :)

So I to come up with an alternative, see the attached sketch of it. The 
main idea - provide and infinite range based on aforementioned flexible 
principle, simple example is (for ints):
auto r = powersOf((int x){ return x*2; }, 1); // 2,4,8,...
given the fact that delegate already contains information about 
direction of traversing (if any), the user the free to use it as is:
take(r,10); // 2,4... 1024

in case with dates that is:
auto inf = powersOf(IRange.everyDayOfWeek!(Date)(DayOfWeek.monday), 
Date(2010,Month.dec,11));
take(inf,5);//next 5 mondays, forward is default in everyDayOfWeek

Then comes the second concept of confining ranges in intervals, here it 
goes:
auto interval = 
Interval!Date(Date(2010,Month.dec,1),Date(2010,Month.dec,20));
auto conf = confine(inf,interval);//Mondays in the interval iterated 
from the beginning

And the simplistic approach of fixed duration striding:
fwdRange(interval, dur!"days"(2)); //yup, traverse by two days
same goes for bwdRange

To summarize it:
1) remove fwdRange, bwdRange from each of Interval types (all it does is 
to require to retype them all over again) and make them  free functions 
with above simple functionality
2)  drop IRange, and let those delegates not handled by simple case to 
just float around (they are very unlikely to conflict with anything IMHO)
3) speaking  of which - separate the notion of applying delegate (that 
could even be generalized in std.algorithm someday) to obtain range, and 
confinement of produced range to interval.

A fitting finale would be to say... that _yes_, I would like to see this 
library in Phobos!
Though with just proposed change if gets any traction...
Overall it's a fantastic work, thanks Jonathon.

-- 

Dmitry Olshansky

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: extdrange.d
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20101210/b6a82dfc/attachment.ksh>


More information about the Digitalmars-d mailing list