[Dbix-class] inflate_column with DateTime::Format::MySQL and invalid dates

Randy Moore ramoore at axion-it.com
Sat Oct 27 02:44:06 GMT 2007


Hi all,

I've just started using inflate_column to inflate a date in a MySQL 
table into a DateTime object.  It works well, as long as the the date is 
valid in the database.  But, I've got a case where my date is 
'0000-00-00 00:00:00' until the object gets verified.

__PACKAGE__->inflate_column('verification_date', {
    inflate => sub { DateTime::Format::MySQL->parse_datetime(shift); },
    deflate => sub { DateTime::Format::MySQL->format_datetime(shift); },
});

If I try to display the date column in a template (TT, example [% 
object.verification_date.dmy('/') %] ) before the date has been set to 
something valid, the DateTime::Format::MySQL code heaves its guts all 
over the place (to be technical about it).

I can work around this by using:
[% IF object.get_column('verification_date') > 0 %][% 
object.verification_date.dmy('/') %][% END %]

But that doesn't seem very elegant.

Can anyone suggest a cleaner solution?

Thanks much

-- 
Randy Moore
Axion Information Technologies, Inc.





More information about the DBIx-Class mailing list