[Catalyst] New Bundle::Catalyst

Bill Moseley moseley at hank.org
Wed Nov 16 06:48:10 CET 2005


On Tue, Nov 15, 2005 at 08:07:09AM -0600, Brandon Black wrote:
> The most compelling one was to use some data from $c->session in
> choosing the timezone of DateTime objects being inflated/deflated from
> time columns in the database.  I haven't found a solution I'm really
> happy with for this one yet, but currently I just have an unrelated
> utility function in lib/MyApp/Utils.pm to display DateTime objects
> using a timezone derived from $c->session, and I have to wrap usage of
> my timestamp columns in that function ( my $string_for_html_output =
> MyApp::Utils::format_for_user($c, $row->time_stamp) ).

I use an inflate that looks up the timezone in a related record.  So
maybe you could shove the timezone into the database where the inflate
method could find it.  %ENV would probably be just as good.

Anyway here's what I do:

    inflate => sub {
        my ($value, $item) = @_;

        my $dt = DateTime::Format::Pg->parse_datetime( $value );
        $dt->set_formatter( $format );

        $dt->set_time_zone( $item->location->time_zone->name );
        $dt;
    }

Another ugly hack you might be able to do is at the start of your
request you replace the inflate sub in your classes.

Untested and maybe way off, but a wild guess might be:


    Class->meta_info('has_a', $method )->args->{inflate} = sub {
        my $dt = DateTime::Format::Pg->parse_datetime( shift );
        $dt->set_time_zone( $c->session->{timezone} );
        return $dt;
    };


-- 
Bill Moseley
moseley at hank.org




More information about the Catalyst mailing list