Skip Menu |

This queue is for tickets about the Time-Piece CPAN distribution.

Report information
The Basics
Id: 9655
Status: resolved
Priority: 0/
Queue: Time-Piece

People
Owner: Nobody in particular
Requestors:
Cc:
AdminCc:

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



Subject: Time::Piece 1.08: strptime and timezone bug?
I faced the following problem with Time::Piece 1.08 module (tp.pl is attached to this bug report): $ env |grep TZ TZ=JST-9 $ perl tp.pl y Class::Date time1: Wed, 12 Jan 2005 22:14:45 JST / 32400 time2: Wed, 12 Jan 2005 22:14:45 JST / 32400 delta: 0 hours (0 seconds) By Time::Piece time1: Wed, 12 Jan 2005 22:14:45 JST / 32400 time2: Wed, 12 Jan 2005 22:14:45 JST / 32400 delta: -9 hours (-32400 seconds)
#!/usr/bin/env perl use Class::Date; use Time::Piece; print "By Class::Date\n"; my $cd_time1 = Class::Date::now; my $cd_time2 = Class::Date::date($cd_time1->strftime('%Y%m%d%H%M%S')); my $cd_delta = $cd_time1 - $cd_time2; print "time1: ", $cd_time1->strftime, " / ", $cd_time1->tzoffset, "\n"; print "time2: ", $cd_time2->strftime, " / ", $cd_time2->tzoffset, "\n"; print "delta: ", $cd_delta->hour, ' hours (', $cd_delta->second, " seconds)\n"; print "\nBy Time::Piece\n"; my $tp_time1 = Time::Piece->new; my $tp_time2 = Time::Piece->strptime($tp_time1->strftime('%Y%m%d%H%M%S'), '%Y%m%d%H%M%S'); my $tp_delta = $tp_time1 - $tp_time2; print "time1: ", $tp_time1->strftime, " / ", $tp_time1->tzoffset, "\n"; print "time2: ", $tp_time2->strftime, " / ", $tp_time2->tzoffset, "\n"; print "delta: ", $tp_delta->hours, " hours (", $tp_delta->seconds, " seconds)\n";
On Wed Jan 12 08:18:42 2005, guest wrote: Show quoted text
> I faced the following problem with Time::Piece 1.08 module > (tp.pl is attached to this bug report): > > $ env |grep TZ > TZ=JST-9 > > $ perl tp.pl > y Class::Date > time1: Wed, 12 Jan 2005 22:14:45 JST / 32400 > time2: Wed, 12 Jan 2005 22:14:45 JST / 32400 > delta: 0 hours (0 seconds) > > By Time::Piece > time1: Wed, 12 Jan 2005 22:14:45 JST / 32400 > time2: Wed, 12 Jan 2005 22:14:45 JST / 32400 > delta: -9 hours (-32400 seconds)
OK, fixed this now. It's a bit confusing as strftime doesn't care if the timezone is local or not, so I've had to just hard code 'UTC' as the timezone for non-local times. Works though.