DBIx-Custom / t / dbi-custom-sqlite-timeformat.t /
Newer Older
85 lines | 2.609kb
packaging one directory
yuki-kimoto authored on 2009-11-16
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
    eval { Time::Piece->VERSION >= 1.15 }
10
        or plan skip_all => 'Time::Piece >= 1.15 requred';
11
        
12
    plan 'no_plan';
13
    use_ok('DBIx::Custom');
14
}
15

            
16
# Function for test name
17
my $test;
18
sub test {
19
    $test = shift;
20
}
21

            
22
# Varialbe for tests
23

            
24
my $format;
25
my $data;
26
my $timepiece;
27
my $dbi;
28

            
29
use DBIx::Custom::SQLite;
30

            
31

            
32
test 'SQL99 format';
33
$dbi = DBIx::Custom::SQLite->new;
34
$data   = '2009-01-02 03:04:05';
35
$format = $dbi->formats->{'SQL99_datetime'};
36
$timepiece = Time::Piece->strptime($data, $format);
fix timeformat tests
yuki-kimoto authored on 2009-11-23
37
is($timepiece->strftime('%Y-%m-%d'), '2009-01-02', "$test : datetime date");
38
is($timepiece->strftime('%H:%M:%S'), '03:04:05',  "$test : datetime time");
packaging one directory
yuki-kimoto authored on 2009-11-16
39

            
40
$data   = '2009-01-02';
41
$format = $dbi->formats->{'SQL99_date'};
42
$timepiece = Time::Piece->strptime($data, $format);
fix timeformat tests
yuki-kimoto authored on 2009-11-23
43
is($timepiece->strftime('%Y-%m-%d'), '2009-01-02', "$test : date");
packaging one directory
yuki-kimoto authored on 2009-11-16
44

            
45
$data   = '03:04:05';
46
$format = $dbi->formats->{'SQL99_time'};
47
$timepiece = Time::Piece->strptime($data, $format);
fix timeformat tests
yuki-kimoto authored on 2009-11-23
48
is($timepiece->strftime('%H:%M:%S'), '03:04:05',  "$test : time");
packaging one directory
yuki-kimoto authored on 2009-11-16
49

            
50

            
51
test 'ISO-8601 format';
52
$data   = '2009-01-02T03:04:05';
53
$format = $dbi->formats->{'ISO-8601_datetime'};
54
$timepiece = Time::Piece->strptime($data, $format);
fix timeformat tests
yuki-kimoto authored on 2009-11-23
55
is($timepiece->strftime('%Y-%m-%d'), '2009-01-02', "$test : datetime date");
56
is($timepiece->strftime('%H:%M:%S'), '03:04:05',  "$test : datetime time");
packaging one directory
yuki-kimoto authored on 2009-11-16
57

            
58
$data   = '2009-01-02';
59
$format = $dbi->formats->{'ISO-8601_date'};
60
$timepiece = Time::Piece->strptime($data, $format);
fix timeformat tests
yuki-kimoto authored on 2009-11-23
61
is($timepiece->strftime('%Y-%m-%d'), '2009-01-02', "$test : date");
packaging one directory
yuki-kimoto authored on 2009-11-16
62

            
63
$data   = '03:04:05';
64
$format = $dbi->formats->{'ISO-8601_time'};
65
$timepiece = Time::Piece->strptime($data, $format);
fix timeformat tests
yuki-kimoto authored on 2009-11-23
66
is($timepiece->strftime('%H:%M:%S'), '03:04:05',  "$test : time");
packaging one directory
yuki-kimoto authored on 2009-11-16
67

            
68

            
69
test 'default format';
70
$data   = '2009-01-02 03:04:05';
71
$format = $dbi->formats->{'datetime'};
72
$timepiece = Time::Piece->strptime($data, $format);
fix timeformat tests
yuki-kimoto authored on 2009-11-23
73
is($timepiece->strftime('%Y-%m-%d'), '2009-01-02', "$test : datetime date");
74
is($timepiece->strftime('%H:%M:%S'), '03:04:05',  "$test : datetime time");
packaging one directory
yuki-kimoto authored on 2009-11-16
75

            
76
$data   = '2009-01-02';
77
$format = $dbi->formats->{'date'};
78
$timepiece = Time::Piece->strptime($data, $format);
fix timeformat tests
yuki-kimoto authored on 2009-11-23
79
is($timepiece->strftime('%Y-%m-%d'), '2009-01-02', "$test : date");
packaging one directory
yuki-kimoto authored on 2009-11-16
80

            
81
$data   = '03:04:05';
82
$format = $dbi->formats->{'time'};
83
$timepiece = Time::Piece->strptime($data, $format);
fix timeformat tests
yuki-kimoto authored on 2009-11-23
84
is($timepiece->strftime('%H:%M:%S'), '03:04:05',  "$test : time");
packaging one directory
yuki-kimoto authored on 2009-11-16
85