I've been using DateTime 0.41 quite happily for a while, but recently I upgraded to 0.45, and am encountering a bug where if you do a epoch() on a DT object that is quite sometime before epoch.

My simple test script is below:
-----------------------------
use strict;
use DateTime;

print "DateTime::VERSION $DateTime::VERSION\n";

my $d=DateTime->new( { month => 12, day => 31, year => 1958, hour => 23, minute => 59, second => 59 });
print "new 12-31-1958 23:59:59, epoch: ";
print $d->epoch();
print ", should be -347155201\n";

my $d3=DateTime->new( { month => 1, day => 1, year => 1959, hour => 0, minute => 0, second => 0});
print "new 1-1-1959 00:00:00, epoch: ";
print $d3->epoch();
print ", should be -347155200\n";

my $d2=DateTime->from_epoch( {epoch => -347155201} );
print "new from epoch -347155201, ";
print $d2->iso8601();
print ", should be 12-31-1958 23:59:59, output as epoch: ",$d2->epoch,"\n";
-----------------------------

from my own Cygwin install, I get:

DateTime::VERSION 0.45
new 12-31-1958 23:59:59, epoch: 2808604799, should be -347155201
new 1-1-1959 00:00:00, epoch: -347155200, should be -347155200
new from epoch -347155201, 1958-12-31T23:59:59, should be 12-31-1958 23:59:59, output as epoch: 2808604799
-----------------------------

from a i386 Solaris box:

DateTime::VERSION 0.45
new 12-31-1958 23:59:59, epoch: 2808604799, should be -347155201
new 1-1-1959 00:00:00, epoch: -347155200, should be -347155200
new from epoch -347155201, 1958-12-31T23:59:59, should be 12-31-1958 23:59:59, output as epoch: 2808604799
-----------------------------

from a sparc Solaris box with the old DateTime version that works...:

DateTime::VERSION 0.41
new 12-31-1958 23:59:59, epoch: -347155201, should be -347155201
new 1-1-1959 00:00:00, epoch: -347155200, should be -347155200
new from epoch -347155201, 1958-12-31T23:59:59, should be 12-31-1958 23:59:59, output as epoch: -347155201

----------------------------

Is there something I am doing wrong? is this a compiler issue? seems to just roll over at that boundary.

And making new dates from epoch work fine if you test for its output string, even with the larger negative number... but even though the object is created from that large negative epoch, doing ->epoch() again returns the incorrect number.

I tried slightly more recent versions after 0.41, and the above script works up to and including 0.4305 (I wasn't able to get any of the 0.44x series to install under my cygwin set up).

Thank you for your help.

Avianna

Reply via email to