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.
89 $dst = (CORE::gmtime(0))[8];
90 $dst_mess = ' # skipped: gmtime(0) thinks DST gmtime 0 == -1';
92 print "not " unless $t->isdst == $dst;
93 print "ok 22$dst_mess\n";
95 print "not " unless $t->daylight_savings == $dst;
96 print "ok 23$dst_mess\n";
98 print "not " unless $t->hms eq '12:34:56';
101 print "not " unless $t->time eq '12:34:56';
104 print "not " unless $t->ymd eq '2000-02-29';
107 print "not " unless $t->date eq '2000-02-29';
110 print "not " unless $t->mdy eq '02-29-2000';
113 print "not " unless $t->dmy eq '29-02-2000';
116 print "not " unless $t->cdate eq 'Tue Feb 29 12:34:56 2000';
119 print "not " unless "$t" eq 'Tue Feb 29 12:34:56 2000';
122 print "not " unless $t->datetime eq '2000-02-29T12:34:56';
125 print "not " unless $t->epoch == 951827696;
130 print "not " unless ($t->julian_day / 2451604.0075) - 1 < 0.001;
133 print "not " unless ($t->mjd / 51603.5075) - 1 < 0.001;
136 print "not " unless $t->week == 9;
139 if ($Config{d_strftime}) {
141 print "not " unless $t->strftime('%a') eq 'Tue';
144 print "not " unless $t->strftime('%A') eq 'Tuesday';
147 print "not " unless $t->strftime('%b') eq 'Feb';
150 print "not " unless $t->strftime('%B') eq 'February';
153 print "not " unless $t->strftime('%c') eq 'Tue Feb 29 12:34:56 2000';
156 print "not " unless $t->strftime('%C') == 20;
159 print "not " unless $t->strftime('%d') == 29;
162 print "not " unless $t->strftime('%D') eq '02/29/00'; # Yech!
165 print "not " unless $t->strftime('%e') eq '29'; # should test with < 10
168 print "not " unless $t->strftime('%H') eq '12'; # should test with < 10
171 print "not " unless $t->strftime('%b') eq 'Feb';
174 print "not " unless $t->strftime('%I') eq '12'; # should test with < 10
177 print "not " unless $t->strftime('%j') eq '059';
180 print "not " unless $t->strftime('%M') eq '34'; # should test with < 10
183 print "not " unless $t->strftime('%p') eq 'am';
186 print "not " unless $t->strftime('%r') eq '12:34:56 am';
189 print "not " unless $t->strftime('%R') eq '12:34'; # should test with > 12
192 print "not " unless $t->strftime('%S') eq '56'; # should test with < 10
195 print "not " unless $t->strftime('%T') eq '12:34:56'; # < 12 and > 12
198 print "not " unless $t->strftime('%u') == 2;
201 print "not " unless $t->strftime('%U') eq '09'; # Sun cmp Mon
204 print "not " unless $t->strftime('%V') eq '09'; # Sun cmp Mon
207 print "not " unless $t->strftime('%w') == 2;
210 print "not " unless $t->strftime('%W') eq '09'; # Sun cmp Mon
213 print "not " unless $t->strftime('%x') eq '02/29/00'; # Yech!
216 print "not " unless $t->strftime('%y') == 0; # should test with 1999
219 print "not " unless $t->strftime('%Y') eq '2000';
222 # %Z can't be tested, too unportable
226 print "ok $_ # Skip: no strftime\n";
230 print "not " unless $t->ymd("") eq '20000229';
233 print "not " unless $t->mdy("/") eq '02/29/2000';
236 print "not " unless $t->dmy(".") eq '29.02.2000';
239 print "not " unless $t->date_separator() eq '-';
242 $t->date_separator("/");
244 print "not " unless $t->ymd eq '2000/02/29';
247 print "not " unless $t->date_separator() eq '/';
250 $t->date_separator("-");
252 print "not " unless $t->hms(".") eq '12.34.56';
255 print "not " unless $t->time_separator() eq ':';
258 $t->time_separator(".");
260 print "not " unless $t->hms eq '12.34.56';
263 print "not " unless $t->time_separator() eq '.';
266 $t->time_separator(":");
268 my @fidays = qw( sunnuntai maanantai tiistai keskiviikko torstai
269 perjantai lauantai );
270 my @frdays = qw( Dimanche Lundi Merdi Mercredi Jeudi Vendredi Samedi );
272 print "not " unless $t->weekday(@fidays) eq "tiistai";
275 my @days = $t->weekday_names();
277 Time::Piece::weekday_names(@frdays);
279 print "not " unless $t->weekday eq "Merdi";
282 Time::Piece::weekday_names(@days);
284 print "not " unless $t->weekday eq "Tuesday";
287 my @months = $t->mon_names();
289 my @dumonths = qw(januari februari maart april mei juni
290 juli augustus september oktober november december);
292 print "not " unless $t->month(@dumonths) eq "februari";
295 Time::Piece::month_names(@dumonths);
297 print "not " unless $t->month eq "februari";
300 Time::Piece::mon_names(@months);
302 print "not " unless $t->monname eq "Feb";
306 $t->datetime(date => '/', T => ' ', time => '-') eq "2000/02/29 12-34-56";
309 print "not " unless $t->is_leap_year;
312 print "not " unless $t->month_last_day == 29; # test more
315 print "not " if Time::Piece::_is_leap_year(1900);
318 print "not " if Time::Piece::_is_leap_year(1901);
321 print "not " unless Time::Piece::_is_leap_year(1904);
324 use Time::Piece 'strptime';
326 my %T = strptime("%T", "12:34:56");
328 print "not " unless keys %T == 3 && $T{H} == 12 && $T{M} == 34 && $T{S} == 56;