[Dbix-class] inflate_column with DateTime::Format::MySQL and
invalid dates
Ash Berlin
ash_cpan at firemirror.com
Sat Oct 27 13:04:33 GMT 2007
Randy Moore wrote:
> 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); },
> });
>
See DBIx::Class::InflateColumn::DateTime
I'm guessing you got the from somewhere in the docs? Please let me know
where so that I can update it to show differently.
> 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
>
I'm not sure if InflateColumn::DateTime will handle this better or not,
but its the first thing to try.
Ash
More information about the DBIx-Class
mailing list