Subscribed unsubscribe Subscribe Subscribe

Hateburo: kazeburo hatenablog

Operations Engineer / Site Reliability / 運用系小姑 / Perl Monger

POSIX::tzset and Windows

When changing timezone in perl script. POSIX::tzset is required.

local $ENV{TZ} = 'Asia/Tokyo';
POSIX::tzset();
localtime();


But Windows does not support this.

  • old Windows dies with "not implemented" error.
  • newer Windows does not die. But timezone is not changed. tzset is supported only for subprocess


If you want to use tzset in tests. it's recommended to skip on windows like these.

eval {
    POSIX::tzset;
    die q!tzset is implemented on this Cygwin. But Windows can't change tz inside script! if $^O eq 'cygwin';
    die q!tzset is implemented on this Windows. But Windows can't change tz inside script! if $^O eq 'MSWin32';
};
if ( $@ ) {
    plan skip_all => $@;
}

see http://api.metacpan.org/source/KAZEBURO/Apache-LogFormat-Compiler-0.22/t/04_tz.t