From: Rafael Kitover Date: Tue, 28 Jul 2009 00:03:47 +0000 (+0000) Subject: add postgres "timestamp without time zone" support X-Git-Tag: v0.08109~64 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=65b386dfedd73d8b6e98d2f52039280fc63a8e7d;hp=76d51f04fff72dac109ac8533edbf902b4a126f6;p=dbsrgits%2FDBIx-Class.git add postgres "timestamp without time zone" support --- diff --git a/lib/DBIx/Class/InflateColumn/DateTime.pm b/lib/DBIx/Class/InflateColumn/DateTime.pm index 1d19012..7e50807 100644 --- a/lib/DBIx/Class/InflateColumn/DateTime.pm +++ b/lib/DBIx/Class/InflateColumn/DateTime.pm @@ -119,6 +119,9 @@ 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"; diff --git a/t/inflate/datetime_pg.t b/t/inflate/datetime_pg.t index 054edf1..2b19df4 100644 --- a/t/inflate/datetime_pg.t +++ b/t/inflate/datetime_pg.t @@ -13,7 +13,7 @@ use DBICTest; eval { require DateTime::Format::Pg }; plan $@ ? ( skip_all => 'Need DateTime::Format::Pg for timestamp inflation tests') - : ( tests => 3 ) + : ( tests => 6 ) ; @@ -27,4 +27,14 @@ my $schema = DBICTest->init_schema(); is($event->created_on->time_zone->name, "America/Chicago", "Timezone changed"); # Time zone difference -> -6hours is($event->created_on->iso8601, "2009-01-15T11:00:00", "Time with TZ correct"); + +# test 'timestamp without time zone' + my $dt = DateTime->from_epoch(epoch => time); + $dt->set_nanosecond(int 500_000_000); + $event->update({ts_without_tz => $dt}); + $event->discard_changes; + isa_ok($event->ts_without_tz, "DateTime") or diag $event->created_on; + is($event->ts_without_tz, $dt, 'timestamp without time zone inflation'); + is($event->ts_without_tz->microsecond, $dt->microsecond, + 'timestamp without time zone microseconds survived'); } diff --git a/t/lib/DBICTest/Schema/Event.pm b/t/lib/DBICTest/Schema/Event.pm index c56c1bd..22b655e 100644 --- a/t/lib/DBICTest/Schema/Event.pm +++ b/t/lib/DBICTest/Schema/Event.pm @@ -15,6 +15,7 @@ __PACKAGE__->add_columns( varchar_date => { data_type => 'varchar', inflate_date => 1, size => 20, is_nullable => 1 }, varchar_datetime => { data_type => 'varchar', inflate_datetime => 1, size => 20, is_nullable => 1 }, skip_inflation => { data_type => 'datetime', inflate_datetime => 0, is_nullable => 1 }, + ts_without_tz => { data_type => 'datetime', is_nullable => 1 }, # used in EventTZPg ); __PACKAGE__->set_primary_key('id'); diff --git a/t/lib/DBICTest/Schema/EventTZPg.pm b/t/lib/DBICTest/Schema/EventTZPg.pm index e2b512e..444fe69 100644 --- a/t/lib/DBICTest/Schema/EventTZPg.pm +++ b/t/lib/DBICTest/Schema/EventTZPg.pm @@ -12,6 +12,7 @@ __PACKAGE__->add_columns( id => { data_type => 'integer', is_auto_increment => 1 }, starts_at => { data_type => 'datetime', timezone => "America/Chicago", locale => 'de_DE' }, created_on => { data_type => 'timestamp with time zone', timezone => "America/Chicago" }, + ts_without_tz => { data_type => 'timestamp without time zone' }, ); __PACKAGE__->set_primary_key('id');