ksublondie has asked for the wisdom of the Perl Monks concerning the following question:

I've used Date::Manip on several scripts before without any problems, but have discovered some random errors in my current project.

I've created a web app (linux/apache2 server) using Date::Manip. When I first installed the module on this server, I set the TZ variable inside the module (like I've always done before) but would receive random Date::Manip errors related to the TZ variable. So I manually set it inside my app...strange, but worked fine. Now I'm randomly getting errors on my date inputs. According to the documentation, input can be any of the following:

MM/DD MM/DD/YY MM/DD/YYYY mmmDD DDmmm mmmYYYY/DD mmmYYYY mmmDD/YY DDmmmYY DD/YYmmm YYYYmmmDD YYYYmmm mmmDDYYYY DDmmmYYYY DDYYYYmmm YYYY/DDmmm

However...periodically, I receive errors if I use any format other than MM/DD/YYYY. This error is if I use MM/DD:

ERROR: Invalid year () at /usr/local/share/perl/5.8.8/Date/Manip.pm l +ine 5538 Date::Manip::_Date_FixYear('undef') called at /usr/local/share +/perl/5.8.8/Date/Manip.pm line 5506 Date::Manip::_Date_DateCheck('SCALAR(0x9735474)', 'SCALAR(0x97 +32134)', 'SCALAR(0x97323f8)', 'SCALAR(0x97325b4)', 'SCALAR(0x973545c) +', 'SCALAR(0x973536c)', 'SCALAR(0x973220c)', 'SCALAR(0x9735570)') cal +led at /usr/local/share/perl/5.8.8/Date/Manip.pm line 1451 Date::Manip::ParseDateString('9/2') called at /usr/local/share +/perl/5.8.8/Date/Manip.pm line 1809

or (using mm/dd/yy)

ERROR: Invalid year (8) at /usr/local/share/perl/5.8.8/Date/Manip.pm +line 5538 Date::Manip::_Date_FixYear(8) called at /usr/local/share/perl/ +5.8.8/Date/Manip.pm line 3413 Date::Manip::Date_LeapYear(8) called at /usr/local/share/perl/ +5.8.8/Date/Manip.pm line 5508 Date::Manip::_Date_DateCheck('SCALAR(0xac88b28)', 'SCALAR(0xac +88b58)', 'SCALAR(0xac88aec)', 'SCALAR(0xabe90b0)', 'SCALAR(0xabe8fc0) +', 'SCALAR(0xabeb1e4)', 'SCALAR(0xabebb2c)', 'SCALAR(0xa43da34)') cal +led at /usr/local/share/perl/5.8.8/Date/Manip.pm line 1451 Date::Manip::ParseDateString('9/1/08') called at /usr/local/sh +are/perl/5.8.8/Date/Manip.pm line 1809

Here's the clincher: if I reload apache2, it fixes the problem, but only temporarily (maybe an hour or 2) so I doubt it's an error w/the code (I can include it if someone REALLY wants to see it...). Are there any Date::Manip or apache experts out there that have any ideas?

Replies are listed 'Best First'.
Re: obscure/random input Date::Manip errors
by Tanktalus (Canon) on Sep 26, 2008 at 23:46 UTC

    Intermittent problems are always the worst. Before we go too far, I'm suspecting that you're using mod_perl here - is that right? Do you set $Date::Manip::Cnf{"UpdateCurrTZ"} to true? That's the only scenario under which my perusal of the code says that this failure could occur. So perhaps the short-term fix is to stop using mod_perl ;-)

    The next step may be to put a stack trace in Date::Manip::Date_Init to see who is calling it and when (and why). At some point, some bad value must be getting into $Curr{"y"}, and then things get screwed up from there. A stack trace there may help pinpoint things, though it'll likely completely overwhelm your apache error log (assuming you're throwing your stack trace to stderr, which makes more sense than stdout!), so you may want to create a new log file. The key here is to catch the transition from good to bad, and what happens at that point. I'm not sure what to expect, but that's the next step I'd be looking at.

Re: obscure/random input Date::Manip errors
by oko1 (Deacon) on Sep 27, 2008 at 14:23 UTC

    In my experience, Date::Manip is useful - lots of functionality, a lot of smart options that can make life a lot easier - but it's BIG and SLOW. These are not qualities you want your prog to have, especially when you're connecting it to something that can get rather picky about timing (e.g., a webserver - particularly a heavily loaded one.)

    If you can get along with using a lighter-weight module - say, DateTime, as AnonymousMonk suggested - then I'd try that out. In fact, even if you can't get the full functionality you need, I'd still try it as a diagnostic.


    --
    "Language shapes the way we think, and determines what we can think about."
    -- B. L. Whorf
      Am I using mod_perl? ummm...I think so??? I didn't setup the server. How can I tell for sure? (I'm still a perl newbie, please be gentle)

      I'd thought about switching to another module, but to use another module, I'd have to re-create several Date::Manip methods, completely defeating the purpose of using another module :D

      I haven't changed any other variables in Date::Manip other than the TZ, so everything else is set to default. I'll try the stack trace...I've never done one before, but no time like the present to start.

        Sadly, I admitted defeat and simply converted to DateTime. :(
Re: obscure/random input Date::Manip errors
by Anonymous Monk on Sep 27, 2008 at 04:10 UTC
    I would switch to DateTime ASAP :)