On Tue, 10 Feb 2004, Matt Sisk wrote:
> 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.
It'd certainly be trivial for you to write a helper function for this:
sub duration_as_seconds {
my $dur = shift;
return $dur->delta_days * 64000 + $dur->delta_minutes * 60 + $dur->delta_seconds;
}
But of course this assumes that the duration has no months. The problem
with providing it in DateTime::Duration is that these assumptions really
can only be made by end users like yourself.
> Perhaps it is just a documentation issue -- it took me a while to find
> and divine the subtract_datetime_absolute method. (difference_in_seconds
> ???)
Yeah, subtract_datetime_absolute came before I started adding delta_*
methods.
Maybe that name should be deprecated in favor of delta_seconds or
something like that.
-dave
/*=======================
House Absolute Consulting
www.houseabsolute.com
=======================*/