Changeset 2033

Show
Ignore:
Timestamp:
05/23/08 12:26:58
Author:
typester
Message:

Added time_zone handling

XXX: I didn't know how to treat time_zone with InflateColumn?::DateTime? and Schema::Loader, so I did it manually.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/fastladder-crawler/plagger/lib/Plagger/Plugin/Store/Fastladder.pm

    r2022 r2033  
    1515 
    1616    $self->{schema} = Plagger::Plugin::Store::Fastladder::Schema::Loader->new( 
    17         @{ $self->conf->{connect_info} }, 
     17        $self->conf->{connect_info}, 
     18        { time_zone => $self->conf->{timezone} || $c->conf->{timezone} || 'local' }, 
    1819    ); 
    1920 
  • branches/fastladder-crawler/plagger/lib/Plagger/Plugin/Store/Fastladder/Schema/Loader.pm

    r2011 r2033  
    1111 
    1212    __PACKAGE__->loader_options( 
    13         components => [qw/InflateColumn::DateTime/], 
    14         exclude    => qr/^schema_info$/, 
     13        exclude => qr/^schema_info$/, 
    1514    ); 
    1615} 
    1716 
    1817sub new { 
    19     my ($class, @connect_info) = @_; 
     18    my ($class, $connect_info, $options) = @_; 
    2019 
    21     my $schema = Plagger::Plugin::Store::Fastladder::Schema->connect(@connect_info); 
     20    my $schema = Plagger::Plugin::Store::Fastladder::Schema->connect(@$connect_info); 
    2221    croak "cannot load schema info" unless $schema->sources; 
    2322 
     
    5655    $favicons->belongs_to( feed => $feeds, 'feed_id' ); 
    5756 
     57    # XXX: setup datetime inflate manually 
     58    # InflateColumn::DateTime doesn't treat time_zone when it used with Schema::Loader? 
     59    my $time_zone    = $options->{time_zone}; 
     60    my $parser_class = $schema->storage->datetime_parser; 
     61 
     62    for my $source ($schema->sources) { 
     63        my $rs = $schema->resultset($source); 
     64 
     65        for my $column ($source->columns) { 
     66            my $info = $source->column_info($column); 
     67            next unless defined $info->{data_type}; 
     68 
     69            my $type = lc $info->{data_type}; 
     70            $type = 'datetime' if $type =~ /^timestamp/; 
     71            next unless $type eq 'datetime' || $type eq 'date'; 
     72 
     73            my ($parse, $format) = ("parse_$type", "format_$type"); 
     74            $rs->inflate_column( 
     75                $column => { 
     76                    inflate => sub { 
     77                        my $dt = $parser_class->$parse(shift); 
     78                        $dt->set_time_zone($time_zone) if $time_zone; 
     79                        $dt; 
     80                    }, 
     81                    deflate => sub { 
     82                        my $dt = shift; 
     83                        $dt->set_time_zone($time_zone) if $time_zone; 
     84                        $parser_class->$format($dt); 
     85                    }, 
     86                }, 
     87            ); 
     88        } 
     89    } 
    5890 
    5991    $schema;