inflate_column + time_zone

んー

for my $date_column (qw/created_date modified_date/) {
    __PACKAGE__->inflate_column(
        $date_column => {
            inflate => sub { DateTime::Format::MySQL->parse_datetime(shift)->set_time_zone('UTC') },
            deflate => sub { DateTime::Format::MySQL->format_datetime(shift->set_time_zone('UTC')) },
        }
    );

    {
        no strict 'refs';
        *{"$date_column\_for"} = sub {
            my ($self, $user) = @_;

            ($user && $user->info && $user->info->time_zone)
                ? $self->$date_column->set_time_zone( $user->info->time_zone )
                : $self->$date_column;
        }
    }
}
by typester / at 2007-05-01T08:12:00 / perl · dbic / Comment