[Catalyst] Setting time zone and locale on dates.

Bill Moseley moseley at hank.org
Mon May 21 21:54:54 GMT 2007


This likely falls into one of the many "how do I get $c into the
model" threads.

My session has the locale and timezone fetched from the user's
preferences at login.  It's not really locale, but a language tag
which is also used by Locale::Maketext, but should work for DateTime's
locale setting.

I use timestamp with time zone on my Postgresql timestamps and the
model inflates to DataTime objects.  Most if not all dates should be
localized for the user.

I'm tempted to use model class data to pass this to the model.  So at
the start of every request do something like:

    My::Model->current_timezone( $c->session->{timezone} );
    My::Model->current_locale( $c->session->{locale} );

And then have the model use those (if set) when inflating.

Any better ideas for dealing with this?

I ask because (besides not having that much I18N experience) I
think this is something that really belongs in the view.

    [% c.local_date( user.last_updated_time ) | html %]

But, setting the locale and time_zone in the inflator would be handy
since it's all one place instead of every time I use a date in the
view.

What do you do?


-- 
Bill Moseley
moseley at hank.org




More information about the Catalyst mailing list