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

I'm currently writing a module that uses Time::Local. In particular the timelocal() function. Now I also want to use dates before the epoch, the example I'm using is 13th September 1965 (a significant date in my calendar :)). On Linux this gives me the correct value with no problem. However, running on Windows via the test suite I get a whole host of error messages, although standalone it just reports the value correctly.

So I decided to have a look at what is going on inside timelocal(). Unfortunately the culprit seems to be localtime(). With negative values it prints nothing. Thankfully Time::Local can cope with this and still returns a valid negative number.

My problem now is how do I stop these warnings of "Use of uninitialized value in integer addition..." etc while running my tests? Bear in mind this a Perl function running from a Perl Core module.

Do I simply not allow tests of dates before the epoch if running on Windows (I'd rather not have to do that *), or is there some way I can tell localtime the world is not going to end or perhaps a switch for the test harness that can suppress them? Or is there another way?

* Though I note that Time::Local ignores dates before the epoch in tests ... hmmm, I wonder why.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Barbie
Birmingham Perl Mongers
Web Site: http://birmingham.pm.org/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  • Comment on Windows, Time::Local and dates before the epoch

Replies are listed 'Best First'.
Re: Windows, Time::Local and dates before the epoch
by fglock (Vicar) on Jun 11, 2003 at 14:52 UTC

    You might try updating your Time::Local (there is a new version in CPAN).

    A better alternative would be to use DateTime instead. If you can't install DateTime, you can use Date::ICal. Both modules work with dates before 1970.

      Might be better to explain a little more about the module I'm writing.

      Calendar::List provides a list, hash or HTML code snippet of a set of dates. Underneath the hood is another module Calendar::Functions which uses one of DateTime, Date::ICal or Time::Local to do the date manipulation, depending which is installed.

      So, as I don't know what is going to be on the user's machine, and the latest version of Time::Local on CPAN has exactly the same problem, I'm looking for something a bit easier to implement.

      Note the problem is ONLY in the test suite. Outside of the test suite it's fine. The warning messages don't appear.

      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      Barbie
      Birmingham Perl Mongers
      Web Site: http://birmingham.pm.org/
      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Re: Windows, Time::Local and dates before the epoch
by Skeeve (Parson) on Jun 12, 2003 at 05:24 UTC
    When I read your reply to fglock I thought: How about implementing your own functions? You won't have to depend on anything preinstalled on the client then. At least calculating a number from any date is not so difficult. The way back is a bit more complicated but not unsolvable. I did that more than once for my faithful FX-602P (a programmable pocket calculator) and for (Turbo-)Pascal ages ago. Maybe I have the source somewhere or can recreate it from mind if you're interested.

      You mean write yet another Date/Time module that does more or less the same as the others. I'd be hung, drawn and quartered :)

      I didn't want to write another module, simply because DateTime and Date::ICal are both well supported modules. If someone using my module wants reliable handling of dates then they are advised to install a reliable date handling module. Time::Local is the fallback simply because its in the Core.

      Since yesterday I'm thinking along the same lines as Time::Local tests. If the user is happy with the boundaries set by Time::Local and localtime, then I don't really need tests that look beyond that. If they want to go beyond those boundaries then they should really install a more reliable date handling module.

      I just found it infuriating having done all these tests and got it working on Linux, when I test it on Windows all these messages suddenly appeared. Such is life.

      --
      Barbie | Birmingham Perl Mongers | http://birmingham.pm.org/

        You mean write yet another Date/Time module that does more or less the same as the others. I'd be hung, drawn and quartered :)

        I know. They did it to me after posting my reply. Downvoted almost instantly ;-)

        Nevertheless. If it's just a small routine, I prefer to use my own algorithm in favour of using just another library that need to be installed and that I need to learn to handle ;-)

        If someone using my module wants reliable handling of dates then they are advised to install a reliable date handling module

        That's fair and if you can live with it... okay for me :-)

        Maybe I will get hanged. I will try and write YADCM (Yet Another Date Calculation Module).