7 require Config; import Config;
9 if ($Config{extensions} !~ m!\bTime/Piece\b!) {
10 print "1..0 # Time::Piece not built\n";
21 my $t = gmtime(951827696); # 2001-02-29T12:34:56
23 print "not " unless $t->sec == 56;
26 print "not " unless $t->second == 56;
29 print "not " unless $t->min == 34;
32 print "not " unless $t->minute == 34;
35 print "not " unless $t->hour == 12;
38 print "not " unless $t->mday == 29;
41 print "not " unless $t->day_of_month == 29;
44 print "not " unless $t->mon == 2;
47 print "not " unless $t->_mon == 1;
50 print "not " unless $t->monname eq 'Feb';
53 print "not " unless $t->month eq 'February';
56 print "not " unless $t->year == 2000;
59 print "not " unless $t->_year == 100;
62 print "not " unless $t->wday == 3;
65 print "not " unless $t->_wday == 2;
68 print "not " unless $t->day_of_week == 2;
71 print "not " unless $t->wdayname eq 'Tue';
74 print "not " unless $t->weekday eq 'Tuesday';
77 print "not " unless $t->yday == 59;
80 print "not " unless $t->day_of_year == 59;
83 # In GMT there should be no daylight savings ever.
85 print "not " unless $t->isdst == 0;
88 print "not " unless $t->daylight_savings == 0;
91 print "not " unless $t->hms eq '12:34:56';
94 print "not " unless $t->time eq '12:34:56';
97 print "not " unless $t->ymd eq '2000-02-29';
100 print "not " unless $t->date eq '2000-02-29';
103 print "not " unless $t->mdy eq '02-29-2000';
106 print "not " unless $t->dmy eq '29-02-2000';
109 print "not " unless $t->cdate eq 'Tue Feb 29 12:34:56 2000';
112 print "not " unless "$t" eq 'Tue Feb 29 12:34:56 2000';
115 print "not " unless $t->datetime eq '2000-02-29T12:34:56';
118 print "not " unless $t->epoch == 951827696;
123 print "not " unless ($t->julian_day / 2451604.0075) - 1 < 0.001;
126 print "not " unless ($t->mjd / 51603.5075) - 1 < 0.001;
129 print "not " unless $t->week == 9;
132 if ($Config{d_strftime}) {
134 print "not " unless $t->strftime('%a') eq 'Tue';
137 print "not " unless $t->strftime('%A') eq 'Tuesday';
140 print "not " unless $t->strftime('%b') eq 'Feb';
143 print "not " unless $t->strftime('%B') eq 'February';
146 print "not " unless $t->strftime('%c') eq 'Tue Feb 29 12:34:56 2000';
149 print "not " unless $t->strftime('%C') == 20;
152 print "not " unless $t->strftime('%d') == 29;
155 print "not " unless $t->strftime('%D') eq '02/29/00'; # Yech!
158 print "not " unless $t->strftime('%e') eq '29'; # should test with < 10
161 print "not " unless $t->strftime('%H') eq '12'; # should test with < 10
164 print "not " unless $t->strftime('%b') eq 'Feb';
167 print "not " unless $t->strftime('%I') eq '12'; # should test with < 10
170 print "not " unless $t->strftime('%j') eq '059';
173 print "not " unless $t->strftime('%M') eq '34'; # should test with < 10
176 print "not " unless $t->strftime('%p') eq 'am';
179 print "not " unless $t->strftime('%r') eq '12:34:56 am';
182 print "not " unless $t->strftime('%R') eq '12:34'; # should test with > 12
185 print "not " unless $t->strftime('%S') eq '56'; # should test with < 10
188 print "not " unless $t->strftime('%T') eq '12:34:56'; # < 12 and > 12
191 print "not " unless $t->strftime('%u') == 2;
194 print "not " unless $t->strftime('%U') eq '09'; # Sun cmp Mon
197 print "not " unless $t->strftime('%V') eq '09'; # Sun cmp Mon
200 print "not " unless $t->strftime('%w') == 2;
203 print "not " unless $t->strftime('%W') eq '09'; # Sun cmp Mon
206 print "not " unless $t->strftime('%x') eq '02/29/00'; # Yech!
209 print "not " unless $t->strftime('%y') == 0; # should test with 1999
212 print "not " unless $t->strftime('%Y') eq '2000';
215 # %Z can't be tested, too unportable
219 print "ok $_ # Skip: no strftime\n";
223 print "not " unless $t->ymd("") eq '20000229';
226 print "not " unless $t->mdy("/") eq '02/29/2000';
229 print "not " unless $t->dmy(".") eq '29.02.2000';
232 print "not " unless $t->date_separator() eq '-';
235 $t->date_separator("/");
237 print "not " unless $t->ymd eq '2000/02/29';
240 print "not " unless $t->date_separator() eq '/';
243 $t->date_separator("-");
245 print "not " unless $t->hms(".") eq '12.34.56';
248 print "not " unless $t->time_separator() eq ':';
251 $t->time_separator(".");
253 print "not " unless $t->hms eq '12.34.56';
256 print "not " unless $t->time_separator() eq '.';
259 $t->time_separator(":");
261 my @fidays = qw( sunnuntai maanantai tiistai keskiviikko torstai
262 perjantai lauantai );
263 my @frdays = qw( Dimanche Lundi Merdi Mercredi Jeudi Vendredi Samedi );
265 print "not " unless $t->weekday(@fidays) eq "tiistai";
268 my @days = $t->weekday_names();
270 $t->weekday_names(@frdays);
272 print "not " unless $t->weekday eq "Merdi";
275 $t->weekday_names(@days);
277 print "not " unless $t->weekday eq "Tuesday";
280 my @months = $t->mon_names();
282 my @dumonths = qw(januari februari maart april mei juni
283 juli augustus september oktober november december);
285 print "not " unless $t->month(@dumonths) eq "februari";
288 $t->month_names(@dumonths);
290 print "not " unless $t->month eq "februari";
293 $t->mon_names(@months);
295 print "not " unless $t->monname eq "Feb";
299 $t->datetime(date => '/', T => ' ', time => '-') eq "2000/02/29 12-34-56";
302 print "not " unless $t->is_leap_year;
305 print "not " unless $t->month_last_day == 29; # test more
308 print "not " if Time::Piece::_is_leap_year(1900);
311 print "not " if Time::Piece::_is_leap_year(1901);
314 print "not " unless Time::Piece::_is_leap_year(1904);