From: Karen Etheridge Date: Fri, 17 Oct 2014 00:55:47 +0000 (-0700) Subject: RT#99546: preserve formatter when inflating datetimes X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=3618cedc80cbfe66faec1867f20ad056e50a69ea;p=dbsrgits%2FDBIx-Class-Historic.git RT#99546: preserve formatter when inflating datetimes --- diff --git a/lib/DBIx/Class/InflateColumn/DateTime.pm b/lib/DBIx/Class/InflateColumn/DateTime.pm index 3162223..63c6379 100644 --- a/lib/DBIx/Class/InflateColumn/DateTime.pm +++ b/lib/DBIx/Class/InflateColumn/DateTime.pm @@ -5,6 +5,7 @@ use warnings; use base qw/DBIx::Class/; use DBIx::Class::Carp; use Try::Tiny; +use Scalar::Util qw/blessed/; use namespace::clean; =head1 NAME @@ -198,7 +199,9 @@ sub _flate_or_fallback my $method = $parser->can($preferred_method) || sprintf($method_fmt, 'datetime'); return try { - $parser->$method($value); + my $thing = $parser->$method($value); + $thing->set_formatter($parser) if blessed $thing; + $thing; } catch { $self->throw_exception ("Error while inflating '$value' for $info->{__dbic_colname} on ${self}: $_") diff --git a/t/inflate/datetime.t b/t/inflate/datetime.t index 7062563..a809245 100644 --- a/t/inflate/datetime.t +++ b/t/inflate/datetime.t @@ -22,7 +22,7 @@ isa_ok($event->starts_at, 'DateTime', 'DateTime returned'); # klunky, but makes older Test::More installs happy my $starts = $event->starts_at; -is("$starts", '2006-04-25T22:24:33', 'Correct date/time'); +is("$starts", '2006-04-25 22:24:33', 'Correct date/time'); my $dt_warn_re = qr/DateTime objects.+not supported properly/; @@ -79,7 +79,7 @@ isnt(ref($event->skip_inflation), 'DateTime', 'No DateTime returned for skip inf # klunky, but makes older Test::More installs happy my $createo = $event->created_on; -is("$createo", '2006-06-22T21:00:05', 'Correct date/time'); +is("$createo", '2006-06-22 21:00:05', 'Correct date/time'); my $created_cron = $created->created_on; @@ -88,11 +88,11 @@ is("$created_cron", '2006-06-23T00:00:00', 'Correct date/time'); ## varchar field using inflate_date => 1 my $varchar_date = $event->varchar_date; -is("$varchar_date", '2006-07-23T00:00:00', 'Correct date/time'); +is("$varchar_date", '2006-07-23 00:00:00', 'Correct date/time'); ## varchar field using inflate_datetime => 1 my $varchar_datetime = $event->varchar_datetime; -is("$varchar_datetime", '2006-05-22T19:05:07', 'Correct date/time'); +is("$varchar_datetime", '2006-05-22 19:05:07', 'Correct date/time'); ## skip inflation field my $skip_inflation = $event->skip_inflation; diff --git a/t/inflate/datetime_mysql.t b/t/inflate/datetime_mysql.t index 44699ab..a36e05c 100644 --- a/t/inflate/datetime_mysql.t +++ b/t/inflate/datetime_mysql.t @@ -45,12 +45,12 @@ foreach my $tbl (qw/EventTZ EventTZDeprecated/) { isa_ok($loaded_event->starts_at, 'DateTime', 'DateTime returned'); $starts_at = $loaded_event->starts_at; - is("$starts_at", '2007-12-31T00:00:00', 'Loaded correct date/time using timezone'); + is("$starts_at", '2007-12-31 00:00:00', 'Loaded correct date/time using timezone'); is($starts_at->time_zone->name, 'America/Chicago', 'Correct timezone'); isa_ok($loaded_event->created_on, 'DateTime', 'DateTime returned'); $created_on = $loaded_event->created_on; - is("$created_on", '2006-01-31T12:34:56', 'Loaded correct timestamp using timezone'); + is("$created_on", '2006-01-31 12:34:56', 'Loaded correct timestamp using timezone'); is($created_on->time_zone->name, 'America/Chicago', 'Correct timezone'); # Test floating timezone warning