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