On Thu, 4 Sep 2003, Dave Rolsky wrote:

> On Thu, 4 Sep 2003, David Wheeler wrote:
>
> > > It's probably that simple.  Simply setting the TZ env var probably
> > > won't
> > > do much.  An app has to call POSIX::tzset() for that take effect.
> >
> > I find that for most date and time handling I do, just setting $ENV{TZ}
> > does the trick -- except perhaps on Debian. Are you saying that if I
> > want the setting of TZ to portably affect, e.g., localtime, that I need
> > to always POSIX::tzset() after I do it? Seems a waste to load all of
> > POSIX.pm just for that...
>
> I'm pretty sure you have to do that.  For example, if you simply set
> $ENV{TZ} then localtime() doesn't change in this script:

You have to call tzset() on some platforms when you change TZ at runtime.

# this prints Tokyo time
export TZ="Asia/Tokyo"
perl -le 'print scalar localtime'

# and this doesn't on Solaris but does on Gentoo
perl -le '$ENV{TZ} = "Asia/Tokyo"; print scalar localtime'

# and this always does
perl -MPOSIX -le '$ENV{TZ} = "Asia/Tokyo"; POSIX::tzset; print scalar localtime'

So there is a difference, on some platform(s), between inheriting the value of TZ from 
the environment and setting it at runtime.  Using tzset() is the 'portable' thing to 
do.

Didn't I answer an almost identical question from David a few months ago?

-J

--

Reply via email to