>Category: MacPerl Application
>Group: Release 5.6.1r*
>Status: Open
>Resolution: None
>Priority: 5
>Submitted By: Scott R. Godin (webdragon)
>Assigned to: Nobody/Anonymous (nobody)
>Summary: meaning of localtime/gmtime reversed?
>
>Initial Comment:
>simple script:
>
>#!/usr/bin/perl -l
>print "$_ - $ENV{$_}" foreach keys %ENV;
>use POSIX;
>
>print POSIX::strftime("%H:%M:%S, %A, %B, %m %Y",
>gmtime(0));
>
>print POSIX::strftime("%H:%M:%S, %A, %B, %m %Y",
>localtime(0));
>
>under MacPerl I get what I expected to see (if I read
>the documentation clearly enough)
>
>-=-
>
>04:00:00, Friday, January, 01 1904
>00:00:00, Friday, January, 01 1904
>
>-=-
>
>under the redhat linux box I have (7.2 running Perl
>5.6.1) I get the complete opposite:
>
>
>-=-
>
>00:00:00, Thursday, January 01 1970
>19:00:00, Wednesday, December 12 1969
>
>-=-
>
>The only way for me to get localtime on the unix box to
>work like I've come to expect it to, is by setting
>
>local $ENV{TZ} = 'UTC'; in the script.
>
>-=-
>
>My question is, who is wrong? MacPerl or this blasted
>Unix box ?

Both are right.

The Unix start of epoch is Thu 1-Jan-1970 00:00:00 (GMT), while the 
Mac OS Classic start of epoch is Fri 1-Jan-1904 00:00:00 (LOCAL 
TIME). Imho, it wasn't a very wise decision to choose local time as 
the zero-point on Mac OS. Anyway, MacPerl ensures the traditional Mac 
OS behavior. Thus, you have to normalize between Mac OS and Unix 
(unless you live in Greenwich, where both times are equal :-).

Btw, the description of the time() function in perlfunc.pod:

"Returns the number of non-leap seconds since whatever time the 
system considers to be the epoch (that's 00:00:00, January 1, 1904 
for MacOS, and 00:00:00 UTC, January 1, 1970 for most other systems). 
Suitable for feeding to gmtime and localtime."

can be misunderstood, since it doesn't mention that Mac OS uses local time.


HTH,

Thomas.


P.S.

May I recommend the following wonderful little book:

     Dava Sobel, Longitude, Walker Publishing Company, Inc., 1995.




Reply via email to