Skip Menu |

This queue is for tickets about the Date-Simple CPAN distribution.

Report information
The Basics
Id: 15587
Status: rejected
Priority: 0/
Queue: Date-Simple

People
Owner: Nobody in particular
Requestors: 2005.8723001 [...] nctu.edu.tw
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 3.01
Fixed in: (no value)



Subject: calling strftime changes the behavior of localtime
machine 1: Date::Simple 3.01 with Perl 5.8.7 on Debian 3.1 sarge machine 2: Date::Simple 3.02 with Perl 5.8.6 on RedHat Fedora Core 4 The behavior of localtime() changes after calling strftime(). In the attached test program, the first and second print are supposed to print out the same result. But I got the following result on both machines: (my timezone is GMT+8) [foo@localhost ~]# perl /tmp/localtime_test.pl Mon Nov 7 00:00:00 2005 Sun Nov 6 16:00:00 2005
#!/usr/bin/perl -w use strict; use Date::Simple; my $time = 1131292800; print scalar localtime $time, "\n"; my $foo = Date::Simple::today->strftime('%Y'); print scalar localtime $time, "\n";
The POSIX::strftime and localtime has some strange behavior on my machines, which is the real reason of this problem. Looks like this ticket can be closed. I will try to find out what happened with my POSIX::strftime. #!/usr/bin/perl -w use strict; use POSIX qw(strftime); my $time = 1131624000; $ENV{TZ} = 'UTC+0'; strftime('%Y/%m/%d %H:%M:%S', 0, 0, 0, 10, 10, 105); print scalar(localtime $time), "\n"; # Thu Nov 10 12:00:00 2005 $ENV{TZ} = 'UTC+1'; print scalar(localtime $time), "\n"; # should be "Thu Nov 10 11:00:00 2005" # but shows "Thu Nov 10 12:00:00 2005" on both machines strftime('%Y/%m/%d %H:%M:%S', 0, 0, 0, 10, 10, 105); print scalar(localtime $time), "\n"; # Wed Nov 10 11:00:00 2005 [guest - Mon Nov 7 01:29:04 2005]: Show quoted text
> machine 1: Date::Simple 3.01 with Perl 5.8.7 on Debian 3.1 sarge > machine 2: Date::Simple 3.02 with Perl 5.8.6 on RedHat Fedora Core 4 > > The behavior of localtime() changes after calling strftime(). > > In the attached test program, the first and second print are supposed > to print out the same result. But I got the following result on both > machines: (my timezone is GMT+8) > > [foo@localhost ~]# perl /tmp/localtime_test.pl > Mon Nov 7 00:00:00 2005 > Sun Nov 6 16:00:00 2005
According to [perl #26136], this is a problem with glibc's localtime and localtime_r. I'll modify format() in Simple.pm on my machines to deal with this problem. http://www.nntp.perl.org/group/perl.perl5.porters/106255 http://rt.perl.org/rt3/index.html?q=26136 sub format { - my ($self,$format)=@_; + my ($self,$format,$result)=@_; $format= $fmts{refaddr($self)||''} || $fmts{ref($self)} || $Standard_Format if @_==1; return "$self" unless defined ($format); require POSIX; - local $ENV{TZ} = 'UTC+0'; - return POSIX::strftime ($format, _gmtime ($self)); + { + local $ENV{TZ} = 'UTC+0'; + $result = POSIX::strftime ($format, _gmtime ($self)); + } + POSIX::tzset(); + return $result; }
From: ask [...] develooper.com
test case that (at least in the evening PST) shows the problem: #!/usr/bin/perl -w use strict; use Test::More tests=>4; $ENV{'TZ'} = 'US/Pacific'; use Date::Simple; ok(my $d0 = Date::Simple->new(), 'new'); ok(my $d1 = Date::Simple->new($d0->format), 'new($d0->format)'); ok(my $d2 = Date::Simple->today, 'today'); is($d1, $d2, 'new == today');