Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^5: Time::Piece strangeness take two

by spiritway (Vicar)
on Dec 14, 2005 at 05:04 UTC ( [id://516521]=note: print w/replies, xml ) Need Help??


in reply to Re^4: Time::Piece strangeness take two
in thread Time::Piece strangeness take two

I don't see how you arrive at this conclusion. When I modify the input dates to read 200 and 205 respectively, the program crashes. When I modify the dates to be 2000 and 2005 respectively, the program completes properly.

This program shows how the year is handled:

use strict; use warnings; use Time::Piece; my $t2 = localtime; print "Time is $t2\n"; print "Year is ", $t2->year, "\n";

The output of that is

Time is Tue Dec 13 22:57:39 2005 Year is 2005
That is as expected.

The documentation for Time::Piece shows these two methods:

$t->year # based at 0 (year 0 AD is, of course 1 BC) $t->_year # year minus 1900

I think it's clear that $t->year is simply the "zero" based year as we know them, and the $t->_year method is the year as we get it from the localtime function.

Replies are listed 'Best First'.
Re^6: Time::Piece strangeness take two
by mojotoad (Monsignor) on Dec 14, 2005 at 07:02 UTC
    Hi there,

    In the original example, the behaviour would arise from the strptime() call -- on most systems this ends up being a call to the strptime function in your local C library.

    As it so happens, you were using %Y in your call which means the year, including the century (i.e. 4 digit year for us mortals).

    On the other hand, had you used %y, it is defined thusly:

    %y is the year within century. When a century is not otherwise specif +ied, values in the range 69-99 refer to years in the twentieth centur +y (1969 to 1999 inclusive); values in the range 00-68 refer to years +in the twenty-first century (2000 to 2068 inclusive). Leading zeros a +re permitted but not required.

    That's the source of the difference of opinion.

    Cheers,
    Matt

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (2)
As of 2024-04-26 07:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found