[Catalyst] datetime formatting ...

Octavian Rasnita orasnita at gmail.com
Wed Jan 6 16:08:22 GMT 2010


From: "Kiffin Gish" <kiffin.gish at planet.nl>


> I've got a datetime column defined:
>
> __PACKAGE__->add_columns(
>  ...
>  "last_modified",
>  {
>    data_type => "DATETIME",
>    default_value => undef,
>    is_nullable => 1,
>    size => undef,
>  },
> );
>
> For some reason it's being displayed like this:
>
> "2010-01-05T20:35:14"
>
> How can I get that 'T' out of there, replacing it with the usual space?
>
> -- 
> Kiffin Gish <Kiffin.Gish at planet.nl>
> Gouda, The Netherlands

That column is automaticly inflated by the component InflateColumn::DateTime 
which is loaded above by:

__PACKAGE__->load_components("InflateColumn::DateTime", "Core");

so that column is a DateTime object and you can use the DateTime methods 
like:

$row->last_modified->ymd
$row->last_modified->set_locale('fr')->strftime('%e %b %Y')
...

If you want, you can disable the inflation by adding (after "do not modify 
this or anything above'):

      __PACKAGE__->add_columns(
        last_modified => { data_type => 'datetime', inflate_datetime => 0 }
      );

Octavian




More information about the Catalyst mailing list