[Catalyst] Changing format of date field

Bill Moseley moseley at hank.org
Mon Jan 6 21:41:33 GMT 2014

On Mon, Jan 6, 2014 at 7:18 AM, Adam Witney <awitney at sgul.ac.uk> wrote:

> Hi,
> I have a date field in a DBIx::Class Result class using
> InflateColumn::DateTime. When I pass this through a Catalyst/TT
> application, the date is presented in YYYY-MM-DD format.
> I can modify this to DD/MM/YYYY in my TT template with object.dmy('/'),
> but I would prefer to change the default DateTime stringification, however
> I am not quite sure where or how to do this?
> Any ideas greatly appreciated.

Seem like formatting in the template is the right place -- may want to have
different formats in different places in your app.   Then you might also
think about how best to localize.

One idea is to localize a set of names for a set of formats:

[% dt_fmt =3D c.localize( '_DT_DATE_ONLY' );   foo.some_dt_object.strftime(
 dt_fmt ) | html %]

I have also used a function that does the above, but also clones and sets
the time zone and locale based on the user's preferences:

[% user_time( foo.event_start, '_DT_TIMESTAMP_WITH_ZONE' ) | html %]

-- =

Bill Moseley
moseley at hank.org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20140106/6adc4=

More information about the Catalyst mailing list