On Thu, 23 Feb 2006, johnc wrote:

Hi, I'm trying to do something fairly simple, which is to add a duration and a datetime object ... but after trying many experimental code permutations, and reading the pod, I'm still obviously missing something here.

I create a DateTime::Duration object like so:

my $dur = DateTime::Duration->new( hours => $hours, minutes => $minutes);

Then attempt to add it to a datetime object ...

my $offset = $now + $dur;

But ... the hours value (often just 1) is never added to the offset ... and when checking $dur->hours, it says the duration has "0" hours! What's the deal?

The hours are converted internally into minutes. Of course, that should still be reflected when you add it to another DateTime.pm object.

To get the hours out of the duration object, you can do:

 $dur->in_units('hours');


-dave

/*===================================================
VegGuide.Org                        www.BookIRead.com
Your guide to all that's veg.       My book blog
===================================================*/

Reply via email to