From: Dagfinn Ilmari Mannsåker Date: Tue, 17 May 2016 14:31:47 +0000 (+0100) Subject: Fix and simplify datetime method selection X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=refs%2Fheads%2Fpeople%2Filmari%2Ficdt-method-fix Fix and simplify datetime method selection No DateTime::Format class has ever provided methods called (parse|format)_timestamp_with(out)?_timezone. Both Pg and Oracle spell it time_zone (as does the rest of the DateTime ecosystem). While we're at it unify all the almost-identical branches to a single regex match and substitution instead. --- diff --git a/lib/DBIx/Class/InflateColumn/DateTime.pm b/lib/DBIx/Class/InflateColumn/DateTime.pm index bb6223d..9bb7029 100644 --- a/lib/DBIx/Class/InflateColumn/DateTime.pm +++ b/lib/DBIx/Class/InflateColumn/DateTime.pm @@ -132,17 +132,12 @@ sub register_column { # _ic_dt_method will follow whatever the registration requests # thus = instead of ||= - if ($data_type eq 'timestamp with time zone' || $data_type eq 'timestamptz') { - $info->{_ic_dt_method} = 'timestamp_with_timezone'; - } - elsif ($data_type eq 'timestamp without time zone') { - $info->{_ic_dt_method} = 'timestamp_without_timezone'; - } - elsif ($data_type eq 'smalldatetime') { - $info->{_ic_dt_method} = 'smalldatetime'; - } - elsif ($data_type =~ /^ (?: date | datetime | timestamp ) $/x) { - $info->{_ic_dt_method} = $data_type; + if ( $data_type =~ /\A (?: + timestamp \s+ with(?:out)? \s+ time \s+ zone | + date | (small)? datetime | timestamp(?:tz)? + ) \z/x + ) { + ($info->{_ic_dt_method} = $data_type) =~ s/\s+/_/g; } elsif ($requested_type) { $info->{_ic_dt_method} = $requested_type;