Commit | Line | Data |
cb551b07 |
1 | use DBIx::Class::Optional::Dependencies -skip_all_without => 'test_dt_pg'; |
2 | |
40f75181 |
3 | use strict; |
4 | use warnings; |
5 | |
6 | use Test::More; |
49bceca3 |
7 | use Test::Warn; |
40f75181 |
8 | use lib qw(t/lib); |
9 | use DBICTest; |
10 | |
052a832c |
11 | DBICTest::Schema->load_classes('EventTZPg'); |
40f75181 |
12 | |
8548e45c |
13 | { |
14 | my $s = DBICTest::Schema->connect('dbi:Pg:whatever'); |
15 | |
16 | ok (!$s->storage->_dbh, 'definitely not connected'); |
17 | |
18 | # Check that datetime_parser returns correctly before we explicitly connect. |
19 | my $store = ref $s->storage; |
20 | is($store, 'DBIx::Class::Storage::DBI', 'Started with generic storage'); |
21 | |
22 | my $parser = $s->storage->datetime_parser; |
23 | is( $parser, 'DateTime::Format::Pg', 'datetime_parser is as expected'); |
24 | |
25 | ok (!$s->storage->_dbh, 'still not connected'); |
26 | } |
27 | |
40f75181 |
28 | my $schema = DBICTest->init_schema(); |
29 | |
49bceca3 |
30 | warnings_are { |
40f75181 |
31 | my $event = $schema->resultset("EventTZPg")->find(1); |
32 | $event->update({created_on => '2009-01-15 17:00:00+00'}); |
33 | $event->discard_changes; |
34 | isa_ok($event->created_on, "DateTime") or diag $event->created_on; |
35 | is($event->created_on->time_zone->name, "America/Chicago", "Timezone changed"); |
36 | # Time zone difference -> -6hours |
37 | is($event->created_on->iso8601, "2009-01-15T11:00:00", "Time with TZ correct"); |
65b386df |
38 | |
39 | # test 'timestamp without time zone' |
40 | my $dt = DateTime->from_epoch(epoch => time); |
41 | $dt->set_nanosecond(int 500_000_000); |
42 | $event->update({ts_without_tz => $dt}); |
43 | $event->discard_changes; |
44 | isa_ok($event->ts_without_tz, "DateTime") or diag $event->created_on; |
45 | is($event->ts_without_tz, $dt, 'timestamp without time zone inflation'); |
46 | is($event->ts_without_tz->microsecond, $dt->microsecond, |
47 | 'timestamp without time zone microseconds survived'); |
49bceca3 |
48 | } [], 'No warnings during DT manipulations'; |
68de9438 |
49 | |
50 | done_testing; |