X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FInflateColumn%2FDateTime.pm;h=2b40608952090cbc8623a96cbfa88abeacd64e16;hb=4c4964c14a9d0b6568102ee9e2dcb14f3bb0fd17;hp=cf5e28c150914d439645fc73664c370aac54aaf1;hpb=d4daee7b54e38e4b3d3d0a77759bddc1a4ede6e5;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/InflateColumn/DateTime.pm b/lib/DBIx/Class/InflateColumn/DateTime.pm index cf5e28c..2b40608 100644 --- a/lib/DBIx/Class/InflateColumn/DateTime.pm +++ b/lib/DBIx/Class/InflateColumn/DateTime.pm @@ -18,6 +18,7 @@ columns to be of the datetime, timestamp or date datatype. __PACKAGE__->load_components(qw/InflateColumn::DateTime Core/); __PACKAGE__->add_columns( starts_when => { data_type => 'datetime' } + create_date => { data_type => 'date' } ); NOTE: You B load C B C. See @@ -69,14 +70,22 @@ one your code should continue to work without modification (though note that this feature is new as of 0.07, so it may not be perfect yet - bug reports to the list very much welcome). +If the data_type of a field is C, C or C (or +a derivative of these datatypes, e.g. C), this +module will automatically call the appropriate parse/format method for +deflation/inflation as defined in the storage class. For instance, for +a C field the methods C and C +would be called on deflation/inflation. If the storage class does not +provide a specialized inflator/deflator, C<[parse|format]_datetime> will +be used as a fallback. See L for more information on +date formatting. + For more help with using components, see L. =cut __PACKAGE__->load_components(qw/InflateColumn/); -__PACKAGE__->mk_group_accessors('simple' => '__datetime_parser'); - =head2 register_column Chains with the L method, and sets @@ -119,6 +128,12 @@ sub register_column { if ($type eq "timestamp with time zone" || $type eq "timestamptz") { $type = "timestamp"; $info->{_ic_dt_method} ||= "timestamp_with_timezone"; + } elsif ($type eq "timestamp without time zone") { + $type = "timestamp"; + $info->{_ic_dt_method} ||= "timestamp_without_timezone"; + } elsif ($type eq "smalldatetime") { + $type = "datetime"; + $info->{_ic_dt_method} ||= "datetime"; } } @@ -207,12 +222,7 @@ sub _deflate_from_datetime { } sub _datetime_parser { - my $self = shift; - if (my $parser = $self->__datetime_parser) { - return $parser; - } - my $parser = $self->result_source->storage->datetime_parser(@_); - return $self->__datetime_parser($parser); + shift->result_source->storage->datetime_parser (@_); } 1;