atoomic / perl-TimeDate

time & date parsing and formatting perl library
http://search.cpan.org/dist/TimeDate/
1 stars 3 forks source link

tz_name() reports incorrect offset when the name is not defined. [rt.cpan.org #59298] #4

Open atoomic opened 4 years ago

atoomic commented 4 years ago

Migrated from rt.cpan.org#59298 (status was 'new')

Requestors:

From steven.martin@cfl.rr.com on 2010-07-13 07:25:50 :

I am in India where the local time is GMT +530.  I expected the script below
to print "IST."  Instead it printed "+33000."

#!/usr/bin/perl

use Date::Format;

print time2str("%Z%n", time);

On investigation, I found that the %Z format in Date::Format uses tz_name()
from Time::Zone.  In tz_name(), if the name of the offset is not defined, I
believe tz_name() should return the offset in the standard numeric format
with the sign, hours, and minutes.  However, it appears that the offset is
kept in seconds while the function is calculating as if it is in minutes.

I corrected the problem by adding the following line before the sprintf() in
tz_name() in Zone.pm line 288:

$off /= 60;

There is also a latent bug for negative offsets if they include a fractional
part of an hour.  I changed the sprintf() from: 

sprintf("%+05d\n", int($off / 60) * 100 + $off % 60);

to: 

sprintf("%+03d%02d\n", int($off / 60), abs($off) % 60);

(I also uncommented the offset for IST in the definition of @Zone but that's
a different issue.)  

I don't think it matters, but I'm running Perl 5.10 under Cygwin and using
Date::Format version 2.24.

Please correct the package and/or its documentation.

Regards,

Steven