Typo in #11083.
[p5sagit/p5-mst-13.2.git] / ext / Time / Piece / Piece.t
1 BEGIN {
2     chdir 't' if -d 't';
3     @INC = '../lib';
4 }
5
6 BEGIN {
7     require Config; import Config;
8
9     if ($Config{extensions} !~ m!\bTime/Piece\b!) {
10         print "1..0 # Time::Piece not built\n";
11         exit 0;
12     }
13 }
14
15 print "1..86\n";
16
17 use Time::Piece;
18
19 print "ok 1\n";
20
21 my $t = gmtime(951827696); # 2001-02-29T12:34:56
22
23 print "not " unless $t->sec == 56;
24 print "ok 2\n";
25
26 print "not " unless $t->second == 56;
27 print "ok 3\n";
28
29 print "not " unless $t->min == 34;
30 print "ok 4\n";
31
32 print "not " unless $t->minute == 34;
33 print "ok 5\n";
34
35 print "not " unless $t->hour == 12;
36 print "ok 6\n";
37
38 print "not " unless $t->mday == 29;
39 print "ok 7\n";
40
41 print "not " unless $t->day_of_month == 29;
42 print "ok 8\n";
43
44 print "not " unless $t->mon == 2;
45 print "ok 9\n";
46
47 print "not " unless $t->_mon == 1;
48 print "ok 10\n";
49
50 print "not " unless $t->monname eq 'Feb';
51 print "ok 11\n";
52
53 print "not " unless $t->month eq 'February';
54 print "ok 12\n";
55
56 print "not " unless $t->year == 2000;
57 print "ok 13\n";
58
59 print "not " unless $t->_year == 100;
60 print "ok 14\n";
61
62 print "not " unless $t->wday == 3;
63 print "ok 15\n";
64
65 print "not " unless $t->_wday == 2;
66 print "ok 16\n";
67
68 print "not " unless $t->day_of_week == 2;
69 print "ok 17\n";
70
71 print "not " unless $t->wdayname eq 'Tue';
72 print "ok 18\n";
73
74 print "not " unless $t->weekday eq 'Tuesday';
75 print "ok 19\n";
76
77 print "not " unless $t->yday == 59;
78 print "ok 20\n";
79
80 print "not " unless $t->day_of_year == 59;
81 print "ok 21\n";
82
83 # In GMT there should be no daylight savings ever.
84
85 my $dst      = 0;
86 my $dst_mess = '';
87 if ($^O eq 'os2') {
88     # OS/2 EMX bug
89     $dst      = (CORE::gmtime(0))[8];
90     $dst_mess = ' # skipped: gmtime(0) thinks DST gmtime 0 == -1';
91 }       
92 print "not " unless $t->isdst == $dst;
93 print "ok 22$dst_mess\n";
94
95 print "not " unless $t->daylight_savings == $dst;
96 print "ok 23$dst_mess\n";
97
98 print "not " unless $t->hms eq '12:34:56';
99 print "ok 24\n";
100
101 print "not " unless $t->time eq '12:34:56';
102 print "ok 25\n";
103
104 print "not " unless $t->ymd eq '2000-02-29';
105 print "ok 26\n";
106
107 print "not " unless $t->date eq '2000-02-29';
108 print "ok 27\n";
109
110 print "not " unless $t->mdy eq '02-29-2000';
111 print "ok 28\n";
112
113 print "not " unless $t->dmy eq '29-02-2000';
114 print "ok 29\n";
115
116 print "not " unless $t->cdate eq 'Tue Feb 29 12:34:56 2000';
117 print "ok 30\n";
118
119 print "not " unless "$t" eq 'Tue Feb 29 12:34:56 2000';
120 print "ok 31\n";
121
122 print "not " unless $t->datetime eq '2000-02-29T12:34:56';
123 print "ok 32\n";
124
125 print "not " unless $t->epoch == 951827696;
126 print "ok 33\n";
127
128 # ->tzoffset?
129
130 print "not " unless ($t->julian_day / 2451604.0075) - 1 < 0.001;
131 print "ok 34\n";
132
133 print "not " unless ($t->mjd        /   51603.5075) - 1 < 0.001;
134 print "ok 35\n";
135
136 print "not " unless $t->week == 9;
137 print "ok 36\n";
138
139 if ($Config{d_strftime}) {
140
141     print "not " unless $t->strftime('%a') eq 'Tue';
142     print "ok 37\n";
143
144     print "not " unless $t->strftime('%A') eq 'Tuesday';
145     print "ok 38\n";
146
147     print "not " unless $t->strftime('%b') eq 'Feb';
148     print "ok 39\n";
149
150     print "not " unless $t->strftime('%B') eq 'February';
151     print "ok 40\n";
152
153     print "not " unless $t->strftime('%c') eq 'Tue Feb 29 12:34:56 2000';
154     print "ok 41\n";
155
156     print "not " unless $t->strftime('%C') == 20;
157     print "ok 42\n";
158
159     print "not " unless $t->strftime('%d') == 29;
160     print "ok 43\n";
161
162     print "not " unless $t->strftime('%D') eq '02/29/00'; # Yech!
163     print "ok 44\n";
164
165     print "not " unless $t->strftime('%e') eq '29'; # should test with < 10
166     print "ok 45\n";
167
168     print "not " unless $t->strftime('%H') eq '12'; # should test with < 10
169     print "ok 46\n";
170
171     print "not " unless $t->strftime('%b') eq 'Feb';
172     print "ok 47\n";
173
174     print "not " unless $t->strftime('%I') eq '12'; # should test with < 10
175     print "ok 48\n";
176
177     print "not " unless $t->strftime('%j') eq '059';
178     print "ok 49\n";
179
180     print "not " unless $t->strftime('%M') eq '34'; # should test with < 10
181     print "ok 50\n";
182
183     print "not " unless $t->strftime('%p') eq 'am';
184     print "ok 51\n";
185
186     print "not " unless $t->strftime('%r') eq '12:34:56 am';
187     print "ok 52\n";
188
189     print "not " unless $t->strftime('%R') eq '12:34'; # should test with > 12
190     print "ok 53\n";
191
192     print "not " unless $t->strftime('%S') eq '56'; # should test with < 10
193     print "ok 54\n";
194
195     print "not " unless $t->strftime('%T') eq '12:34:56'; # < 12 and > 12
196     print "ok 55\n";
197
198     print "not " unless $t->strftime('%u') == 2;
199     print "ok 56\n";
200
201     print "not " unless $t->strftime('%U') eq '09'; # Sun cmp Mon
202     print "ok 57\n";
203
204     print "not " unless $t->strftime('%V') eq '09'; # Sun cmp Mon
205     print "ok 58\n";
206
207     print "not " unless $t->strftime('%w') == 2;
208     print "ok 59\n";
209
210     print "not " unless $t->strftime('%W') eq '09'; # Sun cmp Mon
211     print "ok 60\n";
212
213     print "not " unless $t->strftime('%x') eq '02/29/00'; # Yech!
214     print "ok 61\n";
215
216     print "not " unless $t->strftime('%y') == 0; # should test with 1999
217     print "ok 62\n";
218
219     print "not " unless $t->strftime('%Y') eq '2000';
220     print "ok 63\n";
221
222     # %Z can't be tested, too unportable
223
224 } else {
225     for (38...63) {
226         print "ok $_ # Skip: no strftime\n";
227     }
228 }
229
230 print "not " unless $t->ymd("") eq '20000229';
231 print "ok 64\n";
232
233 print "not " unless $t->mdy("/") eq '02/29/2000';
234 print "ok 65\n";
235
236 print "not " unless $t->dmy(".") eq '29.02.2000';
237 print "ok 66\n";
238
239 print "not " unless $t->date_separator() eq '-';
240 print "ok 67\n";
241
242 $t->date_separator("/");
243
244 print "not " unless $t->ymd eq '2000/02/29';
245 print "ok 68\n";
246
247 print "not " unless $t->date_separator() eq '/';
248 print "ok 69\n";
249
250 $t->date_separator("-");
251
252 print "not " unless $t->hms(".") eq '12.34.56';
253 print "ok 70\n";
254
255 print "not " unless $t->time_separator() eq ':';
256 print "ok 71\n";
257
258 $t->time_separator(".");
259
260 print "not " unless $t->hms eq '12.34.56';
261 print "ok 72\n";
262
263 print "not " unless $t->time_separator() eq '.';
264 print "ok 73\n";
265
266 $t->time_separator(":");
267
268 my @fidays = qw( sunnuntai maanantai tiistai keskiviikko torstai
269                  perjantai lauantai );
270 my @frdays = qw( Dimanche Lundi Merdi Mercredi Jeudi Vendredi Samedi );
271
272 print "not " unless $t->weekday(@fidays) eq "tiistai";
273 print "ok 74\n";
274
275 my @days = $t->weekday_names();
276
277 Time::Piece::weekday_names(@frdays);
278
279 print "not " unless $t->weekday eq "Merdi";
280 print "ok 75\n";
281
282 Time::Piece::weekday_names(@days);
283
284 print "not " unless $t->weekday eq "Tuesday";
285 print "ok 76\n";
286
287 my @months = $t->mon_names();
288
289 my @dumonths = qw(januari februari maart april mei juni
290                   juli augustus september oktober november december);
291
292 print "not " unless $t->month(@dumonths) eq "februari";
293 print "ok 77\n";
294
295 Time::Piece::month_names(@dumonths);
296
297 print "not " unless $t->month eq "februari";
298 print "ok 78\n";
299
300 Time::Piece::mon_names(@months);
301
302 print "not " unless $t->monname eq "Feb";
303 print "ok 79\n";
304
305 print "not " unless
306     $t->datetime(date => '/', T => ' ', time => '-') eq "2000/02/29 12-34-56";
307 print "ok 80\n";
308
309 print "not " unless $t->is_leap_year;
310 print "ok 81\n";
311
312 print "not " unless $t->month_last_day == 29; # test more
313 print "ok 82\n";
314
315 print "not " if Time::Piece::_is_leap_year(1900);
316 print "ok 83\n";
317
318 print "not " if Time::Piece::_is_leap_year(1901);
319 print "ok 84\n";
320
321 print "not " unless Time::Piece::_is_leap_year(1904);
322 print "ok 85\n";
323
324 use Time::Piece 'strptime';
325
326 my %T = strptime("%T", "12:34:56");
327
328 print "not " unless keys %T == 3 && $T{H} == 12 && $T{M} == 34 && $T{S} == 56;
329 print "ok 86\n";
330