Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Maximum localtime value in Perl

by kiramind (Initiate)
on May 08, 2018 at 01:20 UTC ( [id://1214183]=perlquestion: print w/replies, xml ) Need Help??

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

Hello, It appears that past a certain value, `localtime` stops returning dates. thanks to a binary search performed by one of my colleagues, it appear the magic number is `67767976233316804` (which is between 2**55 and 2**56).
> perl -E 'say "#1> ".localtime(67767976233316804); say "#2> ".localti +me(67767976233316805); ' #1> Sun Dec 29 21:00:00 2147483647 #2>
I am a little curious as why is this value the biggest one accepted. Do some monks have this knowledge ?

Replies are listed 'Best First'.
Re: Maximum localtime value in Perl
by NetWallah (Canon) on May 08, 2018 at 03:49 UTC
    The maximum ((update) signed) 32-bit int is 2,147,483,647 == (2^31)-1 .

    If you notice - this is the value of the "year" produced in #1.

    This value corresponds to 0x7FFFFFFF.

    IMHO, localtime should create an "integer Overflow" type exception beyond this value, or start using 64-bit ints.

                    Memory fault   --   brain fried

Re: Maximum localtime value in Perl
by mxb (Pilgrim) on May 08, 2018 at 08:31 UTC

    I can replicate here also.

    % perl --version This is perl 5, version 24, subversion 4 (v5.24.4) built for amd64-freebsd-thread-multi

    From perldoc perlport

    gmtime In theory, "gmtime()" is reliable from -2**63 to 2**63-1. However, because work arounds in the implementation use floating point numbers, it will become inaccurate as the time gets larger. This is a bug and will be fixed in the future. On VOS, time values are 32-bit quantities.
Re: Maximum localtime value in Perl
by thomas895 (Deacon) on May 08, 2018 at 02:22 UTC

    I can replicate this on v5.12.3 on Win32. What version are you using?

    I think it's not just Perl but the localtime function itself that causes this.

    -Thomas
    "Excuse me for butting in, but I'm interrupt-driven..."
      I am using perl v5.18.2 on Mac OSX.
Re: Maximum localtime value in Perl
by choroba (Cardinal) on May 09, 2018 at 06:47 UTC
    Based on Nostradamus' famous prediction, the world as we know it will end on that day. There's no point in returning localtime for any future moment.

    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

      At that point in the future the planck length will shrink to zero, causing the whole universe to implode into a singular non-point of nothingness in no time.

      perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

        Don't be a tease!

      Now that made me wonder if localtime() should handle complex numbers. And how.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (8)
As of 2024-04-16 07:35 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found