Dave Rolsky wrote:
If you want to know how many seconds a duration really represents, you
have to add it to a datetime to find out, so you could do:

 my $now = DateTime->now( time_zone => 'UTC' );
 my $later = $now->clone->add_duration($duration);

my $seconds_dur = $later->subtract_datetime_absolute($now);

This returns a duration which only contains seconds and nanoseconds.

I understand why you have to deal with the ambiguity, but I still really wish there were an easer way to get a rough shot at this value when absolute precision is not required.


In particular I run into this problem when I'm trying to generate values, in seconds, to pass to the sleep() function. When I don't really care about the precision of leap seconds, etc, it would be nice for a duration object to have an 'as the clock flies' value in seconds. I always face this situation with deltas less than a 'day' or '24 hours' without really caring about leap seconds.

<shrug>

Perhaps it is just a documentation issue -- it took me a while to find and divine the subtract_datetime_absolute method. (difference_in_seconds ???)

Matt

Reply via email to