CC: | "Martin, Galen" <gmartin [...] cas.org> |
Subject: | Date::Calc bug |
Date: | Mon, 3 Mar 2008 15:04:04 -0500 |
To: | <bug-Date-Calc [...] rt.cpan.org> |
From: | "Keith-Nakamura, Doug" <dkeith-nakamura [...] cas.org> |
Our Date::Calc version: 5.3
Our Perl version: v5.8.4
Our OS: Solaris 9 (SunOS 5.9)
We found a possible leap-year bug in Date::Calc::Timezone(). This
function is supposed to return the difference between localtime() and
gmtime(), the timezone offset for the current location. The offset is
supposed to be positive if we are located east of Greenwich, and
negative west of Greenwich (except during daylight savings time in some
locations). Our company is located in Ohio, so we are west of
Greenwich. We always have a negative offset even during DST. We
realize that system settings and parameters on our machine such as
locales, environment variables, and the system clock influence the
behavior of Date::Calc::Timezone(). However, it's also possible that
your function itself contains a bug, so we thought we'd tell you about
it. The problem we saw was that on February 29th after 19:00, the
offset was no longer negative. Unfornately, we don't know what the
actual offset was since my code assumed only negative values and had no
'else' branch (due to an assumption on my part). Since the offset
wasn't negative, we had no timezone information from the following code:
my (undef, undef, undef, $gmt_offset, undef, undef, $dst) =
Date::Calc::Timezone();
# U.S. timezone support only, for now:
my $timezone;
if ($gmt_offset == -4)
{
# Atlantic Standard Time
$timezone = 'AST';
}
elsif ($gmt_offset == -5)
{
# Eastern Standard Time
$timezone = 'EST';
}
elsif ($gmt_offset == -6)
{
# Central Standard Time
$timezone = 'CST';
}
elsif ($gmt_offset == -7)
{
# Mountain Standard Time
$timezone = 'MST';
}
elsif ($gmt_offset == -8)
{
# Pacific Standard Time
$timezone = 'PST';
}
elsif ($gmt_offset == -9)
{
# Alaskan Standard Time
$timezone = 'AKST';
}
elsif ($gmt_offset == -10)
{
# Hawaii-Aleutian Standard Time
$timezone = 'HAST';
}
if ($dst)
{
$timezone =~ s/S/D/; # Change 'Standard' to 'Daylight'
}
Usually, this code sets $timezone to 'EST', but that wasn't the case
after 19:00 on leap day. Unfornately with no 'else' branch to default
to, $timezone stayed undefined and caused a problem later in our script.
It makes sense that the problem began after 19:00 because we are 5 hours
behind GMT. Therefore for whatever reason, as soon as midnight GMT on
March 1 was reached, the offset was not between -4 and -10 where we
expected it to be. Do you know what could have happened? If this isn't
a bug in your module, we apologize for wasting your time.
Thank you
Doug Keith-Nakamura
Systems Engineer
Chemical Abstracts Service
Columbus, OH 43015
USA