Newer Older
82 lines | 2.422kb
packing
yuki-kimoto authored on 2009-11-12
1
use Test::More;
2
use strict;
3
use warnings;
4

            
5
BEGIN {
6
    eval { require Time::Piece; 1 }
7
        or plan skip_all => 'Time::Piece required';
8
    
9
    plan 'no_plan';
10
    use_ok('DBIx::Custom');
11
}
12

            
13
# Function for test name
14
my $test;
15
sub test {
16
    $test = shift;
17
}
18

            
19
# Varialbe for tests
20

            
21
my $format;
22
my $data;
23
my $timepiece;
24
my $dbi;
25

            
26
use DBIx::Custom::MySQL;
27

            
28

            
29
test 'SQL99 format';
30
$dbi = DBIx::Custom::MySQL->new;
31
$data   = '2009-01-02 03:04:05';
32
$format = $dbi->formats->{'SQL99_datetime'};
33
$timepiece = Time::Piece->strptime($data, $format);
34
is($timepiece->strftime('%F'), '2009-01-02', "$test : datetime date");
35
is($timepiece->strftime('%T'), '03:04:05',  "$test : datetime time");
36

            
37
$data   = '2009-01-02';
38
$format = $dbi->formats->{'SQL99_date'};
39
$timepiece = Time::Piece->strptime($data, $format);
40
is($timepiece->strftime('%F'), '2009-01-02', "$test : date");
41

            
42
$data   = '03:04:05';
43
$format = $dbi->formats->{'SQL99_time'};
44
$timepiece = Time::Piece->strptime($data, $format);
45
is($timepiece->strftime('%T'), '03:04:05',  "$test : time");
46

            
47

            
48
test 'ISO-8601 format';
49
$data   = '2009-01-02T03:04:05';
50
$format = $dbi->formats->{'ISO-8601_datetime'};
51
$timepiece = Time::Piece->strptime($data, $format);
52
is($timepiece->strftime('%F'), '2009-01-02', "$test : datetime date");
53
is($timepiece->strftime('%T'), '03:04:05',  "$test : datetime time");
54

            
55
$data   = '2009-01-02';
56
$format = $dbi->formats->{'ISO-8601_date'};
57
$timepiece = Time::Piece->strptime($data, $format);
58
is($timepiece->strftime('%F'), '2009-01-02', "$test : date");
59

            
60
$data   = '03:04:05';
61
$format = $dbi->formats->{'ISO-8601_time'};
62
$timepiece = Time::Piece->strptime($data, $format);
63
is($timepiece->strftime('%T'), '03:04:05',  "$test : time");
64

            
65

            
66
test 'default format';
67
$data   = '2009-01-02 03:04:05';
68
$format = $dbi->formats->{'datetime'};
69
$timepiece = Time::Piece->strptime($data, $format);
70
is($timepiece->strftime('%F'), '2009-01-02', "$test : datetime date");
71
is($timepiece->strftime('%T'), '03:04:05',  "$test : datetime time");
72

            
73
$data   = '2009-01-02';
74
$format = $dbi->formats->{'date'};
75
$timepiece = Time::Piece->strptime($data, $format);
76
is($timepiece->strftime('%F'), '2009-01-02', "$test : date");
77

            
78
$data   = '03:04:05';
79
$format = $dbi->formats->{'time'};
80
$timepiece = Time::Piece->strptime($data, $format);
81
is($timepiece->strftime('%T'), '03:04:05',  "$test : time");
82