Subject: | UTC subtract_datetime returns 0 days for 30th July 08 - 30th June 08 |
Date: | Tue, 08 Jul 2008 15:43:23 +1000 |
To: | bug-datetime [...] rt.cpan.org |
From: | Steven Bruce <steve.bruce [...] optusnet.com.au> |
Hi,
I seem to have found a problem in using from_epochand subtract_datetime.
I have not specified a timezone so presumably it's using UTC by default.
The following code prints: "30-07-2008 - 30-06-2008 = 0"
my $startDate = DateTime->from_epoch(epoch => "1214834400");
my $endDate = DateTime->from_epoch(epoch => "1217426400");
print $endDate->dmy;
print(" - ");
print $startDate->dmy;
print(" = ");
my $daysElapsed = $endDate->subtract_datetime($startDate);
print $daysElapsed->in_units('days') . "\n";
Yet if I just set the 'day' to anything other than "30" it works, eg.
"29-07-2008 - 30-06-2008 = 29"
my $startDate = DateTime->from_epoch(epoch => "1214834400");
my $endDate = DateTime->from_epoch(epoch => "1217426400");
print $endDate->dmy;
print(" - ");
print $startDate->dmy;
print(" = ");
$endDate->set( day => '29');
my $daysElapsed = $endDate->subtract_datetime($startDate);
print $daysElapsed->in_units('days') . "\n";
It also works if I set the timezone before doing the subtraction, which
goes against the advice on CPAN "30-07-2008 - 1-07-2008 = 30"
my $startDate = DateTime->from_epoch(epoch => "1214834400");
my $endDate = DateTime->from_epoch(epoch => "1217426400");
$startDate->set_time_zone("Australia/Sydney");
$endDate->set_time_zone("Australia/Sydney");
print $endDate->dmy;
print(" - ");
print $startDate->dmy;
print(" = ");
my $daysElapsed = $endDate->subtract_datetime($startDate);
print $daysElapsed->in_units('days') . "\n";
cheers
Steve
+61 2 8082 7946