Subject: | DateTime.pm - 2 possible bugs |
Date: | Mon, 6 Oct 2008 11:00:55 -0700 (PDT) |
To: | bug-datetime [...] rt.cpan.org |
From: | Andrew Billeb <abilleb [...] yahoo.com> |
Hello Dave,
I've run into some unexpected behavior with DateTime that I'd like to report. First, (and this is not the main issue), if I use DateTime->new() and specify "108" for "year", it is interpreted as "2008". I could see this as being intended behavior since, for example, the module Date::Parse will report "108" for the year when parsing "10/06/08"....but then what would I do if I really wanted a DateTime object with a year of "108"?
The more important part, however, comes when I try to use DateTime->new() with a year of "108" and a time_zone of "America/New_York".....the value returned by $dt-epoch is off by close to an hour (as can be seen from the output of "scalar localtime $dt->epoch")...see below for details. This behavior does not occur when using the year "2008".
Please see below for output from the various combinations of either "108" or "2008" for year, and either "-0400" or "America/New_York" or "America/Chicago" for time_zone. In all cases, the parameters for (second, minute, hour, day, month) are (0, 0, 0, 1, 10):
With $year = 108 and $time_zone = -0400
$dt->epoch = 1222833600
scalar localtime $dt->epoch = Wed Oct 1 00:00:00 2008
With $year = 108 and $time_zone = America/New_York
$dt->epoch = 1222836962 <- UNEXPECTED
scalar localtime $dt->epoch = Wed Oct 1 00:56:02 2008 <- UNEXPECTED
With $year = 108 and $time_zone = America/Chicago
$dt->epoch = 1222840236 <- UNEXPECTED
scalar localtime $dt->epoch = Wed Oct 1 01:50:36 2008 <- UNEXPECTED
With $year = 2008 and $time_zone = -0400
$dt->epoch = 1222833600
scalar localtime $dt->epoch = Wed Oct 1 00:00:00 2008
With $year = 2008 and $time_zone = America/New_York
$dt->epoch = 1222833600
scalar localtime $dt->epoch = Wed Oct 1 00:00:00 2008
With $year = 2008 and $time_zone = America/Chicago
$dt->epoch = 1222837200
scalar localtime $dt->epoch = Wed Oct 1 01:00:00 2008
So, for example with year "108" and time zone of "America/New_York", the time reported is off by 56'02" from what it should be. Here is the code:
-------------------------
#!/usr/bin/perl
use strict;
use warnings;
use DateTime ();
sub makeDT {
my ($sec,$min,$hour,$day,$month,$year, $time_zone) = @_;
my $dt = DateTime->new(
year => $year,
month => $month,
day => $day,
hour => $hour,
minute => $min,
second => $sec,
time_zone => $time_zone,
);
return $dt;
}
sub printDT {
my $year = shift;
my $time_zone = shift;
my $dt = makeDT(0, 0, 0, 1, 10, $year, $time_zone);
print "With \$year = $year and \$time_zone = $time_zone\n";
print "\$dt->epoch = ", $dt->epoch, "\n";
print "scalar localtime \$dt->epoch = ", scalar localtime $dt->epoch, "\n\n";
}
printDT(108, '-0400');
printDT(108, 'America/New_York');
printDT(108, 'America/Chicago');
printDT(2008, '-0400');
printDT(2008, 'America/New_York');
printDT(2008, 'America/Chicago');
-----------------------------------
I'm running Perl v5.8.8 on Linux 2.6.9-42.ELsmp with DateTime.pm version 0.4305.
So, the potential bugs I see here are:
1) DateTime interprets years like "108" as "2008".
2) DateTime produces unexpected results when creating new objects with years like "108" and non-numeric time zones.
Please let me know if you would like me to clarify anything.
Andrew