[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

gmtime(0)has a problem ? (Was: Re: [MacPerl] "Epoch-making difference"--time())



At 16:51 96.04.04, Matthias Ulrich Neeracher wrote:
> Hmm, I thought the age of the universe was commonly considered to be around
> 10E10 years, give or take one order of magnitude. Since a year has about
> Pi*10E7 seconds, 10E18 seconds should be enough, and a quadword easily holds
> 10E19 seconds.

  Incredible.  The age of universe just fitting in quadword (Of course we ca
n even modify the second, or the smallest slice of time, to Planck Time (ord
er of e-44) but that still fits in octaword (128 bits), still smaller than I
Pv6 address space!).  Well, according to Adams, the whole universe fits in a
mare byte, since it is 42 :).

> The current answer to this is $MacPerl::Version, which contains a meaningful
> value under all versions of MacPerl. Recently, it was decided to introduce in
> all Perl5 ports an $^O built-in, which returns the OS. i haven't decided o
>n the
> exact value yet, but "MacOS" is the most likely candidate.
>
> Another question is whether you *have* to special case for MacPerl at
> all. Would it maybe be possible to make your library auto-calibrating by
> calling something like gmtime(0) at the beginning?

  The last idea looks the best and I rewrote newtimelocal.pl using this appr
oach.  Worked absolutely fine of two unixen (MachTen and SunOS 4.1.4).  Look
s totally funny on MacPerl.  I checked it out and found that gmtime(0) on Ma
cPerl returns a funny value.  Take a look at this.  I ran a small code as fo
llows;

        sub PrintArray{
          local($result) = '(';
         for($i = 0; $i < $#_; $i++){
                        $result .= $_[$i] . ", ";
        }
        $result .= $_[$#_] . ')';
         return $result;
        }

        print "gmtime(0) =    ",  &PrintArray(gmtime(0)), "\n";
        print "localtime(0) = ",  &PrintArray(localtime(0)), "\n";
        $now = time();
        print "gmtime($now) =    ",  &PrintArray(gmtime($now)), "\n";
        print "localtime($now) = ",  &PrintArray(localtime($now)), "\n";

And the result was this!

        gmtime(0) =    (16, 28, 21, 5, 1, 140, 0, 35, 0)
        localtime(0) = (0, 0, 0, 1, 0, 4, 5, 0, 0)
        gmtime(2911541528) =    (8, 32, 0, 5, 3, 96, 5, 95, 0)
        localtime(2911541528) = (8, 32, 9, 5, 3, 96, 5, 95, 0)

While {gm|local}time($now) looks OK, gmtime(0) is obvously funny and localti
me(0) shows what gmtime(0) was supposed to be.  It was supposed to be

        gmtime(0) =    (0, 0, 0, 1, 0, 4, 5, 0, 0)
        localtime(0) = (0, 0, 9, 1, 0, 4, 5, 0, 0)

At where I live now (Japan, GMT+9, no DST).  Unixen said

        gmtime(0) =    (0, 0, 0, 1, 0, 4, 5, 0)
        localtime(0) = (0, 0, 9, 1, 0, 4, 5, 0)

        gmtime(0) =    (0, 0, 0, 1, 0, 70, 4, 0, 0)
        localtime(0) = (0, 0, 9, 1, 0, 70, 4, 0, 0)
        gmtime(828664260) =    (0, 31, 0, 5, 3, 96, 5, 95, 0)
        localtime(828664260) = (0, 31, 9, 5, 3, 96, 5, 95, 0)

Which is exactly what I expected.  Now I am lost.  Is that due to Vogol's In
tergalactic highway construction or what?

Dan the Man "Lost in time... literally"