in reply to Good & Easy Date Module?

Date::Manip does everything and is pure perl so it runs everywhere. The downside is that it is slow and fairly complicated. Having said that, I've used it for a number of projects and its worth the time I spent learning it.

Date::Calc is written in C and is much faster than Date::Manip. If it does what you want it to do, I would go with it (I didn't because it is/was unavailable for MacOS).

I would avoid writing your own here. Dealing with dates is one of those issues that is extremely complicated and exception filled. You are probably better off learning a well tested, but complicated module than reinventing one yourself. I put rewritting date routines along side trying to reinvent CGI.pm or HTML::Parser. Don't do it unless you have a very good reason.

----
Coyote

Replies are listed 'Best First'.
Beware Date::Calc::Add_Delta_DHMS
by grinder (Bishop) on Feb 21, 2001 at 23:01 UTC
    Danger Will Robinson!

    I used Date::Calc a while back when grovelling through web logs. In essence, I wanted to split out information week by week. I used Time::Local to convert the the web timestamp into epoch time. I then had to walk backwards, firstly to get back to Sunday 0:00, and from there walk backwards week by week.

    The details are a little hazy, and in any event the project got wiped out by a catastrophic hard disk failure before I backed things up.

    The thing is, I was using Date::Calc::Add_Delta_DHMS, walking back week by week, and started getting weird off-by-one errors. In the end I got around the problem by just dealing with epoch time and subtracting 86400*7, and the numbers came out fine.

    I did mean to prepare a test to prove or disprove the bug, but ran out of tuits. All that to say watch out if you use the Add_Delta_* functions.

    grinder
      Lemme bet the rent on this one...

      You were using a time between 12 midnight and 1am as your base time, and you crossed the spring daylight savings time boundary when a day had only 23 hours. Then you'll be off a day. If this is the case, your epoch +/- 86400*7 solution will also fail, and you've only been lucky not to hit the same case.

      So the problem was not Date::Calc, but in a misunderstanding that there's not always 24 hours in a day.

      -- Randal L. Schwartz, Perl hacker

        /me is enlightened.

        I guess I shall have to go and code up my hypothesis. The only niggling thing is that I'm pretty sure the log files started from May last year, and I wrote the stuff in September. So I shouldn't have been bitten by that.

        Mind you, shouldn't Date::Calc deal with that kind of fiddly stuff for me? That's why I'm not rolling my own in the first place, no?