Debian Codegraph @

t/date.parse.iso.t

raw
1 #!/usr/bin/perl
2
3 use warnings;
4 use strict;
5 use Test::Inter;
6 $::ti = new Test::Inter $0;
7 require "tests.pl";
8
9 our $obj = new Date::Manip::Date;
10 $obj->config("forcedate","2000-01-21-00:00:00,America/New_York");
11
12 sub test {
13 my(@test)=@_;
14 if ($test[0] eq "config") {
15 shift(@test);
16 $obj->config(@test);
17 return ();
18 }
19
20 my $err = $obj->parse(@test);
21 if ($err) {
22 return $obj->err();
23 } else {
24 my $d1 = $obj->value();
25 my $d2 = $obj->value("gmt");
26 return($d1,$d2);
27 }
28 }
29
30 my $tests="
31
32 # Standard dates
33
34 1996061800:00:00 => 1996061800:00:00 1996061804:00:00
35
36 1993120105:30:25 => 1993120105:30:25 1993120110:30:25
37
38 1993120105:30:25 => 1993120105:30:25 1993120110:30:25
39
40 # ISO 8601 (all digit)
41
42 19950506121314 => 1995050612:13:14 1995050616:13:14
43
44 19950506121314D => 1995050612:13:14 1995050616:13:14
45
46 '19950506121314 D' => 1995050612:13:14 1995050616:13:14
47
48 19950506121314-0500 => 1995050612:13:14 1995050617:13:14
49
50 '19950506121314 GMT' => 1995050612:13:14 1995050612:13:14
51
52 '19950506121314 America/Chicago' => 1995050612:13:14 1995050617:13:14
53
54 199505061213 => 1995050612:13:00 1995050616:13:00
55
56 1995050612 => 1995050612:00:00 1995050616:00:00
57
58 -950506121314 => 1995050612:13:14 1995050616:13:14
59
60 -9505061213 => 1995050612:13:00 1995050616:13:00
61
62 -95050612 => 1995050612:00:00 1995050616:00:00
63
64 ---06121314 => 2000010612:13:14 2000010617:13:14
65
66 ---061213 => 2000010612:13:00 2000010617:13:00
67
68 ---0612 => 2000010612:00:00 2000010617:00:00
69
70 # ISO 8601 (YYMMDD)
71
72 19930601 => 1993060100:00:00 1993060104:00:00
73
74 1993-06-01 => 1993060100:00:00 1993060104:00:00
75
76 -930601 => 1993060100:00:00 1993060104:00:00
77
78 -93-06-01 => 1993060100:00:00 1993060104:00:00
79
80 930601 => 1993060100:00:00 1993060104:00:00
81
82 93-06-01 => 1993060100:00:00 1993060104:00:00
83
84 --0601 => 2000060100:00:00 2000060104:00:00
85
86 --06-01 => 2000060100:00:00 2000060104:00:00
87
88 ---07 => 2000010700:00:00 2000010705:00:00
89
90 1996061800:00:00D => 1996061800:00:00 1996061804:00:00
91
92 '1996061800:00:00 D' => 1996061800:00:00 1996061804:00:00
93
94 '1996061800:00:00 -0500' => 1996061800:00:00 1996061805:00:00
95
96 '1996061800:00:00 America/Chicago' => 1996061800:00:00
97 1996061805:00:00
98
99 1996-11 => 1996110100:00:00 1996110105:00:00
100
101 1996 => 1996010100:00:00 1996010105:00:00
102
103 -9611 => 1996110100:00:00 1996110105:00:00
104
105 -96-11 => 1996110100:00:00 1996110105:00:00
106
107 -96 => 1996010100:00:00 1996010105:00:00
108
109 --11 => 2000110100:00:00 2000110105:00:00
110
111 1993-063 => 1993030400:00:00 1993030405:00:00
112
113 1993063 => 1993030400:00:00 1993030405:00:00
114
115 93-063 => 1993030400:00:00 1993030405:00:00
116
117 93063 => 1993030400:00:00 1993030405:00:00
118
119 -93-063 => 1993030400:00:00 1993030405:00:00
120
121 -93063 => 1993030400:00:00 1993030405:00:00
122
123 -063 => 2000030300:00:00 2000030305:00:00
124
125 # ISO 8601 (YYWwwD)
126
127 1993W101 => 1993030800:00:00 1993030805:00:00
128
129 1993W107 => 1993031400:00:00 1993031405:00:00
130
131 1993-W10-1 => 1993030800:00:00 1993030805:00:00
132
133 1993-W10-7 => 1993031400:00:00 1993031405:00:00
134
135 93W101 => 1993030800:00:00 1993030805:00:00
136
137 93W107 => 1993031400:00:00 1993031405:00:00
138
139 93-W10-1 => 1993030800:00:00 1993030805:00:00
140
141 93-W10-7 => 1993031400:00:00 1993031405:00:00
142
143 -93W101 => 1993030800:00:00 1993030805:00:00
144
145 -93W107 => 1993031400:00:00 1993031405:00:00
146
147 -93-W10-1 => 1993030800:00:00 1993030805:00:00
148
149 -93-W10-7 => 1993031400:00:00 1993031405:00:00
150
151 -W101 => 2000030600:00:00 2000030605:00:00
152
153 -W107 => 2000031200:00:00 2000031205:00:00
154
155 -W10-1 => 2000030600:00:00 2000030605:00:00
156
157 -W10-7 => 2000031200:00:00 2000031205:00:00
158
159 -W-1 => 2000011700:00:00 2000011705:00:00
160
161 -W-7 => 2000012300:00:00 2000012305:00:00
162
163 ---1 => 2000011700:00:00 2000011705:00:00
164
165 ---7 => 2000012300:00:00 2000012305:00:00
166
167 2012-W01-1 => 2012010200:00:00 2012010205:00:00
168
169 config firstday 7 =>
170
171 1993W101 => 1993030700:00:00 1993030705:00:00
172
173 1993W107 => 1993031300:00:00 1993031305:00:00
174
175 config firstday 1 =>
176
177 1993W10 => 1993030800:00:00 1993030805:00:00
178
179 1993-W10 => 1993030800:00:00 1993030805:00:00
180
181 93W10 => 1993030800:00:00 1993030805:00:00
182
183 93-W10 => 1993030800:00:00 1993030805:00:00
184
185 -93W10 => 1993030800:00:00 1993030805:00:00
186
187 -93-W10 => 1993030800:00:00 1993030805:00:00
188
189 -W10 => 2000030600:00:00 2000030605:00:00
190
191 W10 => 2000030600:00:00 2000030605:00:00
192
193 # ISO 8601 times
194
195 121314,0 => 2000012112:13:14 2000012117:13:14
196
197 121314D => 2000012112:13:14 2000012116:13:14
198
199 '121314 D' => 2000012112:13:14 2000012116:13:14
200
201 '121314 GMT' => 2000012112:13:14 2000012112:13:14
202
203 12:13:14 => 2000012112:13:14 2000012117:13:14
204
205 12:13:14-0500 => 2000012112:13:14 2000012117:13:14
206
207 '1213 D' => 2000012112:13:00 2000012116:13:00
208
209 '1213 GMT' => 2000012112:13:00 2000012112:13:00
210
211 12:13 => 2000012112:13:00 2000012117:13:00
212
213 12:13-0500 => 2000012112:13:00 2000012117:13:00
214
215 # 24:00:00 time
216
217 1993013124:00:00 => 1993020100:00:00 1993020105:00:00
218
219 1993-01-3124:00:00 => 1993020100:00:00 1993020105:00:00
220
221 # Date/time separators
222
223 '19960618 00:00:00D' => 1996061800:00:00 1996061804:00:00
224
225 19960618T00:00:00D => 1996061800:00:00 1996061804:00:00
226
227 19960618-00:00:00D => 1996061800:00:00 1996061804:00:00
228
229 # Tests from 5.x
230
231 '1993120117:30:25 GMT' => 1993120117:30:25 1993120117:30:25
232
233 19960618000000 => 1996061800:00:00 1996061804:00:00
234
235 '1993120117:30:25.25 GMT' => 1993120117:30:25 1993120117:30:25
236
237 19960618000000.25 => 1996061800:00:00 1996061804:00:00
238
239 2000-02-16T12:30:30 => 2000021612:30:30 2000021617:30:30
240
241 '20021216090000 -0500' => 2002121609:00:00 2002121614:00:00
242
243 2004-03-29T11:41:00Z => 2004032911:41:00 2004032911:41:00
244
245 '2004-03-29T11:41:00 EDT' => '[parse] Unable to determine timezone'
246
247 1992022905:30:61 => '[parse] Invalid date'
248
249 96-06-1800:00:00 => 1996061800:00:00 1996061804:00:00
250
251 1990022905:30 => '[parse] Invalid date'
252
253 97W227 => 1997060100:00:00 1997060104:00:00
254
255 1997-W22-7 => 1997060100:00:00 1997060104:00:00
256
257 1997W23 => 1997060200:00:00 1997060204:00:00
258
259 1997023 => 1997012300:00:00 1997012305:00:00
260
261 1997035 => 1997020400:00:00 1997020405:00:00
262
263 97-035 => 1997020400:00:00 1997020405:00:00
264
265 97035 => 1997020400:00:00 1997020405:00:00
266
267 '2000-02-16 24:00' => 2000021700:00:00 2000021705:00:00
268
269 '2000-02-16 15:24:00' => 2000021615:24:00 2000021620:24:00
270
271 '2000-02-16 05:24:00' => 2000021605:24:00 2000021610:24:00
272
273 '2000-02-16 5:24:00' => 2000021605:24:00 2000021610:24:00
274
275 2009-W49-1 => 2009113000:00:00 2009113005:00:00
276
277 2009-W49-2 => 2009120100:00:00 2009120105:00:00
278
279 ";
280
281 $::ti->tests(func => \&test,
282 tests => $tests);
283 $::ti->done_testing();
284
285 #Local Variables:
286 #mode: cperl
287 #indent-tabs-mode: nil
288 #cperl-indent-level: 3
289 #cperl-continued-statement-offset: 2
290 #cperl-continued-brace-offset: 0
291 #cperl-brace-offset: 0
292 #cperl-brace-imaginary-offset: 0
293 #cperl-label-offset: 0
294 #End: