On Thu, Jul 15, 2010 at 21:17, Paul Miller <jett...@cpan.org> wrote:
> On Thu Jul 15 13:50:14 2010, auta...@urth.org wrote:
>> On Thu, 15 Jul 2010, Paul Miller via RT wrote:
>> > sub seconds     { abs( $_[0]->in_units('seconds') ) }
>> Well, that looks different to me but ...
> How is seconds() different from in_units("seconds")?  I don't see it.
Did you really miss "abs" there?! ;-)

>> Have you read the DateTime.pm docs in detail? It explains some of this.
> I have.  I just don't understand why duration objects can't tell me
> their duration in the units I want and why it returns anything at all
> if it's actually refusing to do the conversion to seconds.
Should I guess that, for instance, you want "22 minutes" to be "22*60 seconds"?
Than you're not looking at the right module, because "formatters"
(DateTime::Format::<whatever>) are usually the ones who *might* play
along with such assumptions. In this case,
"DateTime::Format::Duration" is the one you need, for instance,
appending these lines to your previous code might render what you
wanted:

require DateTime::Format::Duration;
print DateTime::Format::Duration->new( pattern => "dur is: %s seconds\n" )
    ->format_duration($dur);

DateTime::Duration is used for date/time math, so do not expect it to
apply such "normalizations".

> The documents say it won't do the conversion and makes a religious stance
> about it.  My thinking is that it should raise an exception or something
> instead.
Why should it raise an exception when, as you already noticed, it
didn't claim to do that conversion, so it worked as expected? :))
I see no "religious stance" here, it's just the right thing to do.

> It's not just for fun.  I'm trying to be helpful.
Well, I guess it's not funny to Dave either to cope with such blatant
refusals to understand how DateTime works (and nor helpful). :(

> I understand there's ambiguity here, but I think there are some predictably
> acceptable conversions that can be done (4 weeks in a month, 7 days in a week,
> etc); and they could at least be an option.
Ok, I understand you want an easy way out, but DateTime does not offer
that, instead it does provide a framework for doing *correct*
date/time computations. Use it as a foundation, integrate your
whatever assumptions into a new module (if it doesn't exist already).

Anyway, for quick and dirty date/time hacks, you might want keep on
using Date::(Calc|Manip).

Cheers
-ab

Reply via email to