Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Time::Piece strangeness take two

by InfiniteLoop (Hermit)
on Dec 13, 2005 at 02:06 UTC ( [id://516208]=perlquestion: print w/replies, xml ) Need Help??

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

Greetings monks,
This is a followup to my query Time::Piece strangeness. While using Time::Piece comparision, in the following code:
use Time::Piece; my $t = Time::Piece->strptime("31-01-200", "%d-%m-%Y"); $t1 = Time::Piece->strptime("31-01-2005", "%d-%m-%Y"); if($t1 > $t){ print "To be or not to be."; }

I get the following error:
Day too big - 47512 > 24855 Sec too small - 47512 < 74752 Sec too big - 47512 > 11647 Cannot handle date (0, 0, 0, 31, 0, 2100) at /usr/lib/i686-linux/Time/ +Piece.pm line 288

I have read the documentation for Time::Piece, but could not solve it. To fix this, Im trapping the comparision in an eval block.
I seek your advice on handling this condition.

Replies are listed 'Best First'.
Re: Time::Piece strangeness take two
by BrowserUk (Patriarch) on Dec 13, 2005 at 02:16 UTC

    Did you really mean to use the date 31st January 200 ?


    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

      Time::Piece is interpreting the year not as 200, but as 2100, i.e. 1900+200.
      (That is, of course, beyond the range of unix time, but that's no excuse...)

      We're building the house of the future together.

        No, BrowserUK is right; the first date is incorrect. If you notice, the second date contains the year 2005, which is how Time::Piece requires it. When I added another zero to the first date's year, I got the desired output.

      I agree with "InfiniteLoop". Whether we are passing valid date or something else, but Time::Piece must validate the date before processing it.
      -kulls
      Not really. Stumbled upon this bug, when the user modified the date and forgot to add the '5'. I guess I will stick with eavl{}ing the comparision. Thanks.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://516208]
Approved by GrandFather
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (7)
As of 2024-03-28 19:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found