2b19df47a08642927b8e4c4f535768876d3f27f2
[dbsrgits/DBIx-Class.git] / t / inflate / datetime_pg.t
1 use strict;
2 use warnings;
3
4 use Test::More;
5 use lib qw(t/lib);
6 use DBICTest;
7
8 {
9   local $SIG{__WARN__} = sub { warn @_ if $_[0] !~ /extra \=\> .+? has been deprecated/ };
10   DBICTest::Schema->load_classes('EventTZPg');
11 }
12
13 eval { require DateTime::Format::Pg };
14 plan $@
15   ? ( skip_all =>  'Need DateTime::Format::Pg for timestamp inflation tests')
16   : ( tests => 6 )
17 ;
18
19
20 my $schema = DBICTest->init_schema();
21
22 {
23   my $event = $schema->resultset("EventTZPg")->find(1);
24   $event->update({created_on => '2009-01-15 17:00:00+00'});
25   $event->discard_changes;
26   isa_ok($event->created_on, "DateTime") or diag $event->created_on;
27   is($event->created_on->time_zone->name, "America/Chicago", "Timezone changed");
28   # Time zone difference -> -6hours
29   is($event->created_on->iso8601, "2009-01-15T11:00:00", "Time with TZ correct");
30
31 # test 'timestamp without time zone'
32   my $dt = DateTime->from_epoch(epoch => time);
33   $dt->set_nanosecond(int 500_000_000);
34   $event->update({ts_without_tz => $dt});
35   $event->discard_changes;
36   isa_ok($event->ts_without_tz, "DateTime") or diag $event->created_on;
37   is($event->ts_without_tz, $dt, 'timestamp without time zone inflation');
38   is($event->ts_without_tz->microsecond, $dt->microsecond,
39     'timestamp without time zone microseconds survived');
40 }