Debian Codegraph @

t/02parse.t

raw symbols SCIP
1 use strict;
2
3 use Test::More tests => 84;
4
5 use DateTime::Format::MySQL;
6
7 my $mysql = 'DateTime::Format::MySQL';
8
9 {
10 my $dt = $mysql->parse_date( '2003_02_15' );
11 is( $dt->year, 2003 );
12 is( $dt->month, 2 );
13 is( $dt->day, 15 );
14 }
15
16 {
17 my $dt = $mysql->parse_datetime( '2003-02-15 10:09:08' );
18 is( $dt->year, 2003 );
19 is( $dt->month, 2 );
20 is( $dt->day, 15 );
21 is( $dt->hour, 10 );
22 is( $dt->minute, 9 );
23 is( $dt->second, 8 );
24 }
25
26 {
27 my $dt = $mysql->parse_datetime( '2003-02-15 10:09:08.2' );
28 is( $dt->year, 2003 );
29 is( $dt->month, 2 );
30 is( $dt->day, 15 );
31 is( $dt->hour, 10 );
32 is( $dt->minute, 9 );
33 is( $dt->second, 8 );
34 is( $dt->microsecond, 200_000 );
35 is( $dt->nanosecond, 200_000_000 );
36 }
37
38 {
39 my $dt = $mysql->parse_datetime( '2014:10:26 01:02:03.002' );
40 is( $dt->year, 2014 );
41 is( $dt->month, 10 );
42 is( $dt->day_of_month, 26 );
43 is( $dt->hour, 1 );
44 is( $dt->minute, 02 );
45 is( $dt->second, 03 );
46 is( $dt->microsecond, 2_000 );
47 is( $dt->nanosecond, 2_000_000 );
48 }
49
50 {
51 my $dt = $mysql->parse_timestamp( '2003-02-15 10:09:08.0' );
52 is( $dt->year, 2003 );
53 is( $dt->month, 2 );
54 is( $dt->day, 15 );
55 is( $dt->hour, 10 );
56 is( $dt->minute, 9 );
57 is( $dt->second, 8 );
58 is( $dt->microsecond, 0 );
59 is( $dt->nanosecond, 0 );
60 }
61
62 {
63 my $dt = $mysql->parse_timestamp( '2014:10:26 01:02:03' );
64 is( $dt->year, 2014 );
65 is( $dt->month, 10 );
66 is( $dt->day_of_month, 26 );
67 is( $dt->hour, 1 );
68 is( $dt->minute, 02 );
69 is( $dt->second, 03 );
70 is( $dt->microsecond, 0 );
71 is( $dt->nanosecond, 0 );
72 }
73
74 {
75 my $dt = $mysql->parse_datetime( '2014-10-26T01:02:03.2' );
76 is( $dt->year, 2014 );
77 is( $dt->month, 10 );
78 is( $dt->day_of_month, 26 );
79 is( $dt->hour, 1 );
80 is( $dt->minute, 02 );
81 is( $dt->second, 03 );
82 is( $dt->microsecond, 200_000 );
83 is( $dt->nanosecond, 200_000_000 );
84 }
85
86 {
87 my $dt = $mysql->parse_timestamp( '2014^1^6 1^2^3.123456' );
88 is( $dt->year, 2014 );
89 is( $dt->month, 1 );
90 is( $dt->day_of_month, 6 );
91 is( $dt->hour, 1 );
92 is( $dt->minute, 2 );
93 is( $dt->second, 3 );
94 is( $dt->microsecond, 123_456 );
95 is( $dt->nanosecond, 123_456_000 );
96 }
97
98 {
99 my $dt = $mysql->parse_timestamp('70');
100 is( $dt->year, 1970 );
101 }
102
103 {
104 my $dt = $mysql->parse_timestamp('69');
105 is( $dt->year, 2069 );
106 }
107
108 {
109 my $dt = $mysql->parse_timestamp('1202');
110 is( $dt->year, 2012 );
111 is( $dt->month, 2 );
112 }
113
114 {
115 my $dt = $mysql->parse_timestamp('120211');
116 is( $dt->year, 2012 );
117 is( $dt->month, 2 );
118 is( $dt->day_of_month, 11 );
119 }
120
121 {
122 my $dt = $mysql->parse_timestamp('20120211');
123 is( $dt->year, 2012 );
124 is( $dt->month, 2 );
125 is( $dt->day_of_month, 11 );
126 }
127
128 {
129 my $dt = $mysql->parse_timestamp('1202110545');
130 is( $dt->year, 2012 );
131 is( $dt->month, 2 );
132 is( $dt->day_of_month, 11 );
133 is( $dt->hour, 5 );
134 is( $dt->minute, 45 );
135 }
136
137 {
138 my $dt = $mysql->parse_timestamp('120211054537');
139 is( $dt->year, 2012 );
140 is( $dt->month, 2 );
141 is( $dt->day_of_month, 11 );
142 is( $dt->hour, 5 );
143 is( $dt->minute, 45 );
144 is( $dt->second, 37 );
145 }
146
147 {
148 my $dt = $mysql->parse_timestamp('20120211054537');
149 is( $dt->year, 2012 );
150 is( $dt->month, 2 );
151 is( $dt->day_of_month, 11 );
152 is( $dt->hour, 5 );
153 is( $dt->minute, 45 );
154 is( $dt->second, 37 );
155 }