in reply to Re: Subtracting Dates
in thread Subtracting Dates

Why is Date::Calc overkill? It's an appropriate solution to the problem, it doesn't pollute your namespace, and it has a very nice well-documented interface. Sure, it may take an extra 5 hundredths of a second to load the module, but it's worthwhile to have more readable code IMHO.

Replies are listed 'Best First'.
Re: Re: Re: Subtracting Dates
by dsheroh (Monsignor) on Jun 07, 2002 at 17:55 UTC
    Because it's not part of the standard perl distribution and I'd like to be able to distribute my code to people who don't know how/don't want to be bothered to install stuff off CPAN?

    Because

    my $seconds_per_day = 60 * 60 * 24; my $then = time - (14 * seconds_per_day);
    is, to me, at least as readable as ehdonhon's example of using Add_Delta_YMD and doesn't pollute the namespace either?

    Granted, the $seconds_per_day version takes a little extra work (remembering which indexes from (localtime($then)) you want and adding offsets to the extracted month and year if you intend to display them directly), but it's worthwhile to have more easily portable code, IMHO.

    For a larger project that's likely to need other modules, sure, Date::Calc is great. But if it's the only non-core module that would be used, I don't think it's worth the hassle of making people install it when you can do the same thing using only the core language with so little extra effort.