use lib qw(t/lib);
use DBICTest;
-DBICTest::Schema->load_classes('EventTZDeprecated');
+{
+ local $SIG{__WARN__} = sub { warn @_ if $_[0] !~ /extra \=\> .+? has been deprecated/ };
+ DBICTest::Schema->load_classes('EventTZDeprecated');
+ DBICTest::Schema->load_classes('EventTZPg');
+}
my $schema = DBICTest->init_schema();
-eval { require DateTime::Format::MySQL };
-plan skip_all => "Need DateTime::Format::MySQL for inflation tests" if $@;
+plan tests => 57;
+
+SKIP: {
+ eval { require DateTime::Format::MySQL };
+ skip "Need DateTime::Format::MySQL for inflation tests", 50 if $@;
-plan tests => 50;
# inflation test
my $event = $schema->resultset("Event")->find(1);
my $starts = $event->starts_at;
is("$starts", '2006-04-25T22:24:33', 'Correct date/time');
+TODO: {
+ local $TODO = "We can't do this yet before 0.09" if DBIx::Class->VERSION < 0.09;
+
+ ok(my $row =
+ $schema->resultset('Event')->search({ starts_at => $starts })->single);
+ is(eval { $row->id }, 1, 'DT in search');
+
+ ok($row =
+ $schema->resultset('Event')->search({ starts_at => { '>=' => $starts } })->single);
+ is(eval { $row->id }, 1, 'DT in search with condition');
+}
+
# create using DateTime
my $created = $schema->resultset('Event')->create({
starts_at => DateTime->new(year=>2006, month=>6, day=>18),
## skip inflation field
my $skip_inflation = $event->skip_inflation;
is ("$skip_inflation", '2006-04-21 18:04:06', 'Correct date/time');
+
+} # Skip if no MySQL DT::Formatter
+
+SKIP: {
+ eval { require DateTime::Format::Pg };
+ skip ('Need DateTime::Format::Pg for timestamp inflation tests', 3) if $@;
+
+ my $event = $schema->resultset("EventTZPg")->find(1);
+ $event->update({created_on => '2009-01-15 17:00:00+00'});
+ $event->discard_changes;
+ isa_ok($event->created_on, "DateTime") or diag $event->created_on;
+ 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");
+}