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