File: 01-constructor.t

package info (click to toggle)
libpgobject-type-datetime-perl 2.000001-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 136 kB
  • ctags: 12
  • sloc: perl: 225; makefile: 2
file content (45 lines) | stat: -rw-r--r-- 2,121 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
use PGObject::Type::DateTime;
use Test::More tests => 26;

my $test;

$test = PGObject::Type::DateTime->from_db("2013-12-11 11:11:11.11234-08");
isa_ok $test, 'DateTime', 'long parse, isa date time';
isa_ok $test, 'PGObject::Type::DateTime', 'long parse, is expected class';
is $test->to_db, "2013-12-11 11:11:11.11234-08", 'long parse, expected db out';
ok $test->is_tz, 'long parse, timezone';

$test = PGObject::Type::DateTime->from_db('2012-12-11'); 
isa_ok $test, 'DateTime', 'date only, isa date time';
isa_ok $test, 'PGObject::Type::DateTime', 'date only, is expected class';
is $test->to_db, "2012-12-11", 'date only, expected db out';
is $test->is_tz, 0, 'date only, no timezone';

$test = PGObject::Type::DateTime->from_db('11:11:23.1111');
isa_ok $test, 'DateTime', 'time only, isa date time';
isa_ok $test, 'PGObject::Type::DateTime', 'time only, is expected class';
is $test->to_db, "11:11:23.1111", 'long parse, expected db out';
is $test->is_tz, 0, 'time only, no timezone';

$test = PGObject::Type::DateTime->from_db("2013-12-11 00:00:00.0000-08");
isa_ok $test, 'DateTime', 'Midnight, isa date time';
isa_ok $test, 'PGObject::Type::DateTime', 'Midnight. is expected class';
is $test->to_db, "2013-12-11 00:00:00.0-08", 'Midnight, expected db out';
ok $test->is_tz, 'Midnight, timezone';

$test = PGObject::Type::DateTime->from_db("2013-12-11 00:00:00.0000");
isa_ok $test, 'DateTime', 'Midnight, no time zone, isa date time';
isa_ok $test, 'PGObject::Type::DateTime', 'Midnight. is expected class';
is $test->to_db, "2013-12-11 00:00:00.0", 'Midnight, expected db out';
is $test->is_tz, 0, 'Midnight, timezone';

$test = PGObject::Type::DateTime->from_db("2013-12-11 00:00:00.0000+08");
isa_ok $test, 'DateTime', 'Midnight, positive offset, isa date time';
isa_ok $test, 'PGObject::Type::DateTime', 'Midnight positive offset. is expected class';
is $test->to_db, "2013-12-11 00:00:00.0+08", 'Midnight positive offset, expected db out';
ok $test->is_tz, 'Midnight, positive offset, timezone';

$test =  PGObject::Type::DateTime->from_db(undef);
isa_ok $test, 'DateTime', 'undef';
is $test->to_db, undef;