in reply to Re: Good & Easy Date Module?
in thread Good & Easy Date Module?

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

Replies are listed 'Best First'.
Re: Beware Date::Calc::Add_Delta_DHMS
by merlyn (Sage) on Feb 21, 2001 at 23:25 UTC
    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?

        Well, there's a 25-hour day in there... maybe that broke it.

        And Date::Calc is doing what you told it. If you cross the funny-days, you get surprising results only if you're not aware of it.

        -- Randal L. Schwartz, Perl hacker