Well, here is what I have.

$self->{life_left} = $self->{expire_date} - DateTime->now();

where $self->{expire_date} is a DateTime object and $self->{life_left} is a DateTime::Duration object.

Then in the template, I do the following:

<td>[% object.life_left.years %]</td>

Hope this makes sense.

Additionally, I will need to do some rounding on the Duration object (if more then siz months => add year, etc).

Thank you for any ideas you might have.


Arshavir





[EMAIL PROTECTED] wrote:

"DateTime::Format::Duration" may be what you need for
this specific problem. Can you show us a few lines of
your template?

- Flavio S. Glock



I am running into a snag with using


DateTime::Duration and TT. I think

it's an important issue and am surprised that there


is no info on this

on Google.

Somehow when you try to invoke any of


DateTime::Duration's accessor

methods from within a TT template it dies with an


error that comparison

operators are not overloaded in DateTime::Duration


and that I should use

DateTime::Duration->compare() to do comparisons.
I have tracked this down and it appears that


somewhere deep in the

template processing, TT is doing an 'eq' on a


DateTime::Duration object

and that's throwing an exception.

I am wondering whether it would be very hard to


overload the comparison

operators.
If both objects are of DateTime::Duration, then can


you just call

compare from within _compare_overload(). And if


they are not of the same

type, then they are obviously not equal.
Or maybe the 'eq' operator could be a special case


of comparison,

implemented as a separate _eq_overload() subroutine.

Maybe, I am asking for too much, but it seems like


what I am trying to

do is fairly mundane.

Thanks for any insights you may have.


Arshavir










Reply via email to