std.date proposal
Fredrik Olsson
peylow at treyst.se
Wed Apr 5 23:28:27 PDT 2006
Walter Bright skrev:
> Fredrik Olsson wrote:
>>>> A double can represent infinity, -infinity, and not a number can be
>>>> not a date.
>>>
>>> std.date's d_time offers d_time_nan, which fills the role of nan for
>>> times. I don't see a purpose for infinity or -infinity when dealing
>>> with calendar dates or file times. There is a purpose for such when
>>> doing physics math, but that is way beyond the scope of std.date.
>>>
>> I find a good infinity to be nice to have, when calling say something
>> like: isInRange(aDate, now(), infinity); A date way into the future
>> would be just as good for most purposes, but clean and readable code
>> is nice.
>
> Why not write it as:
>
> if (now() <= aDate) ...
>
> ?
Perhaps a better example:
Item[] itemsInRange(Item[] items, d_date start, d_date end) {
Item[] ret;
foreach (Item item; items) {
if (isInRange(item.date, start, end)
ret ~= item;
}
return ret;
}
Introducing itemsBefore() and itemsAfter() could be done, but less code
for the same functionality would be to simply send "infinity" to
itemsInTange's start or end. And now it would be nice with a set
standard for "what is infinity".
Best would be if the properties min and max could be made for typedefs,
and maybe introduce your own, such as nad for "not a date".
// Fredrik
More information about the Digitalmars-d-announce
mailing list