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

I seem to have discovered a problem with localtime in perl 5.8.8. I'm trying to use ENV{TZ} to change the timezone and in 5.8.8, localtime seems to glom onto whatever timezone it is first called with.

My test script looks like:
$ENV{TZ} = "America/Los_Angeles";
print scalar localtime(time()), "\n";
$ENV{TZ} = 'America/New_York';
print scalar localtime(time()), "\n";

On my system (Ubuntu 8.04, perl 5.8.8-12) output looks like:
Tue Jul 22 21:38:00 2008
Tue Jul 22 21:38:00 2008

On my ISP's system(unknown Linux, perl 5.6.1) output is:
Tue Jul 22 21:39:22 2008
Wed Jul 23 00:39:22 2008

I've tried POSIX and various Time:: modules and behavior is the same. I can't believe this is a bug, but don't know where to go from here and have been beating my head on it most of the day.

Any suggestions??
Thanks
Steve S.

Replies are listed 'Best First'.
Re: 5.8.8 localtime bug??
by ikegami (Patriarch) on Jul 23, 2008 at 05:03 UTC

    Use tzset.

    use POSIX qw( tzset ); $ENV{TZ} = "America/Los_Angeles"; tzset(); print scalar localtime(time()), "\n"; $ENV{TZ} = 'America/New_York'; tzset(); print scalar localtime(time()), "\n";
    Tue Jul 22 22:02:29 2008 Wed Jul 23 01:02:29 2008
      That worked and I thought I had tried it. Long day I guess...

      Thank you very much!