Restore 'timezone' field in column info ( extends eef9b484 )
[dbsrgits/DBIx-Class.git] / t / icdt / offline_pg.t
CommitLineData
c0329273 1BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
54a9a088 2use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt_pg );
cb551b07 3
40f75181 4use strict;
5use warnings;
6
7use Test::More;
49bceca3 8use Test::Warn;
c0329273 9
40f75181 10use DBICTest;
11
052a832c 12DBICTest::Schema->load_classes('EventTZPg');
40f75181 13
8548e45c 14{
15 my $s = DBICTest::Schema->connect('dbi:Pg:whatever');
16
17 ok (!$s->storage->_dbh, 'definitely not connected');
18
19 # Check that datetime_parser returns correctly before we explicitly connect.
20 my $store = ref $s->storage;
21 is($store, 'DBIx::Class::Storage::DBI', 'Started with generic storage');
22
23 my $parser = $s->storage->datetime_parser;
24 is( $parser, 'DateTime::Format::Pg', 'datetime_parser is as expected');
25
591df363 26 my $colinfo = $s->source('EventTZPg')->column_info('created_on');
27 is (
28 $colinfo->{timezone},
29 $colinfo->{time_zone},
30 'Legacy timezone key is still present in colinfo',
31 );
32
8548e45c 33 ok (!$s->storage->_dbh, 'still not connected');
34}
35
40f75181 36my $schema = DBICTest->init_schema();
37
da9346a0 38# this may generate warnings under certain CI flags, hence do it outside of
39# the warnings_are below
40my $dt = DateTime->new( year => 2000, time_zone => "America/Chicago" );
41
49bceca3 42warnings_are {
40f75181 43 my $event = $schema->resultset("EventTZPg")->find(1);
44 $event->update({created_on => '2009-01-15 17:00:00+00'});
45 $event->discard_changes;
46 isa_ok($event->created_on, "DateTime") or diag $event->created_on;
47 is($event->created_on->time_zone->name, "America/Chicago", "Timezone changed");
48 # Time zone difference -> -6hours
49 is($event->created_on->iso8601, "2009-01-15T11:00:00", "Time with TZ correct");
65b386df 50
51# test 'timestamp without time zone'
52 my $dt = DateTime->from_epoch(epoch => time);
53 $dt->set_nanosecond(int 500_000_000);
54 $event->update({ts_without_tz => $dt});
55 $event->discard_changes;
56 isa_ok($event->ts_without_tz, "DateTime") or diag $event->created_on;
57 is($event->ts_without_tz, $dt, 'timestamp without time zone inflation');
58 is($event->ts_without_tz->microsecond, $dt->microsecond,
59 'timestamp without time zone microseconds survived');
49bceca3 60} [], 'No warnings during DT manipulations';
68de9438 61
62done_testing;