Restore 'timezone' field in column info ( extends eef9b484 )
[dbsrgits/DBIx-Class.git] / t / icdt / offline_pg.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2 use DBIx::Class::Optional::Dependencies -skip_all_without => qw( ic_dt_pg );
3
4 use strict;
5 use warnings;
6
7 use Test::More;
8 use Test::Warn;
9
10 use DBICTest;
11
12 DBICTest::Schema->load_classes('EventTZPg');
13
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
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
33   ok (!$s->storage->_dbh, 'still not connected');
34 }
35
36 my $schema = DBICTest->init_schema();
37
38 # this may generate warnings under certain CI flags, hence do it outside of
39 # the warnings_are below
40 my $dt = DateTime->new( year => 2000, time_zone => "America/Chicago" );
41
42 warnings_are {
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");
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');
60 } [], 'No warnings during DT manipulations';
61
62 done_testing;