File: 04-overloaded.t

package info (click to toggle)
libpgobject-type-datetime-perl 2.000002-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 132 kB
  • sloc: perl: 225; makefile: 2
file content (39 lines) | stat: -rw-r--r-- 1,638 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
#!perl

use PGObject::Type::DateTime;
use Test::More tests => 33;

my $test;

$test = PGObject::Type::DateTime->today;
isa_ok $test, 'DateTime', 'overloaded today(), isa date time';
isa_ok $test, 'PGObject::Type::DateTime', 'overloaded today(), is expected class';
like $test->to_db, qr/^\d{4}-\d{2}-\d{2}$/, 'overloaded today() returns a date only';

for my $trunc (qw/ year month week local_week day/) {
    $test = PGObject::Type::DateTime->now->truncate( to => $trunc );
    isa_ok $test, 'DateTime', 'truncate (no time), isa date time';
    isa_ok $test, 'PGObject::Type::DateTime', 'truncate (no time), is expected class';
    ok(! $test->is_time, 'truncate (no time), has no time');
}

for my $trunc (qw/ hour minute second /) {
    $test = PGObject::Type::DateTime->now->truncate( to => $trunc );
    isa_ok $test, 'DateTime', 'truncate (with time), isa date time';
    isa_ok $test, 'PGObject::Type::DateTime', 'truncate (with time), is expected class';
    ok($test->is_time, 'truncate (with time), has time');
}


$test = PGObject::Type::DateTime->last_day_of_month(year => 2015, month => 12);
isa_ok $test, 'DateTime', 'last_day_of_month, isa date time';
isa_ok $test, 'PGObject::Type::DateTime', 'last_day_of_month, is expected class';
ok ! $test->is_time, 'last_day_of_month has no time';


$test = PGObject::Type::DateTime->from_day_of_year(year => 2015,
                                                   day_of_year => 150);
isa_ok $test, 'DateTime', 'from_day_of_year, isa date time';
isa_ok $test, 'PGObject::Type::DateTime', 'from_day_of_year, is expected class';
ok ! $test->is_time, 'from_day_of_year has no time';