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 'Feb';
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->day eq 'Tue';
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 # %a, %A, %b, %B, %c are locale-dependent
136 # %C is unportable: sometimes its like asctime(3) or date(1),
137 # sometimes it's the century (and whether for 2000 the century is
138 # 20 or 19, is fun, too..as far as I can read SUSv2 it should be 20.)
140 print "not " unless $t->strftime('%d') == 29;
143 print "not " unless $t->strftime('%D') eq '02/29/00'; # Yech!
146 print "not " unless $t->strftime('%e') eq '29'; # should test with < 10
149 print "not " unless $t->strftime('%H') eq '12'; # should test with < 10
152 # %h is locale-dependent
154 print "not " unless $t->strftime('%I') eq '12'; # should test with < 10
157 print "not " unless $t->strftime('%j') == 60; # why ->yday+1 ?
160 print "not " unless $t->strftime('%M') eq '34'; # should test with < 10
163 # %p, %P, and %r are not widely implemented,
164 # and are possibly unportable (am or AM or a.m., and so on)
166 print "not " unless $t->strftime('%R') eq '12:34'; # should test with > 12
169 print "not " unless $t->strftime('%S') eq '56'; # should test with < 10
172 print "not " unless $t->strftime('%T') eq '12:34:56'; # < 12 and > 12
175 # There are bugs in the implementation of %u in many platforms.
176 # (e.g. Linux seems to think, despite the man page, that %u
177 # 1-based on Sunday...)
179 print "not " unless $t->strftime('%U') eq '09'; # Sun cmp Mon
182 print "not " unless $t->strftime('%V') eq '09'; # Sun cmp Mon
185 print "not " unless $t->strftime('%w') == 2;
188 print "not " unless $t->strftime('%W') eq '09'; # Sun cmp Mon
191 # %x is locale and implementation dependent.
193 print "not " unless $t->strftime('%y') == 0; # should test with 1999
196 print "not " unless $t->strftime('%Y') eq '2000';
199 # %Z is locale and implementation dependent
200 # (there is NO standard for timezone names)
204 print "ok $_ # Skip: no strftime\n";
208 print "not " unless $t->date("") eq '20000229';
211 print "not " unless $t->ymd("") eq '20000229';
213 print "not " unless $t->mdy("/") eq '02/29/2000';
216 print "not " unless $t->dmy(".") eq '29.02.2000';
219 print "not " unless $t->date_separator() eq '-';
222 $t->date_separator("/");
224 print "not " unless $t->ymd eq '2000/02/29';
227 print "not " unless $t->date_separator() eq '/';
230 $t->date_separator("-");
232 print "not " unless $t->hms(".") eq '12.34.56';
235 print "not " unless $t->time_separator() eq ':';
238 $t->time_separator(".");
240 print "not " unless $t->hms eq '12.34.56';
243 print "not " unless $t->time_separator() eq '.';
246 $t->time_separator(":");
248 my @fidays = qw( sunnuntai maanantai tiistai keskiviikko torstai
249 perjantai lauantai );
250 my @frdays = qw( Dimanche Lundi Merdi Mercredi Jeudi Vendredi Samedi );
252 print "not " unless $t->day(@fidays) eq "tiistai";
255 my @days = $t->day_list();
257 $t->day_list(@frdays);
259 print "not " unless $t->day eq "Merdi";
264 print "not " unless $t->day eq "Tue";
267 my @months = $t->mon_list();
269 my @dumonths = qw(januari februari maart april mei juni
270 juli augustus september oktober november december);
272 print "not " unless $t->month(@dumonths) eq "februari";
275 $t->mon_list(@dumonths);
277 print "not " unless $t->month eq "februari";
280 $t->mon_list(@months);
282 print "not " unless $t->month eq "Feb";
286 $t->datetime(date => '/', T => ' ', time => '-') eq "2000/02/29 12-34-56";
289 print "not " unless $t->is_leap_year; # should test more with different dates
292 print "not " unless $t->month_last_day == 29; # test more
295 print "not " if Time::Piece::_is_leap_year(1900);
298 print "not " if Time::Piece::_is_leap_year(1901);
301 print "not " unless Time::Piece::_is_leap_year(1904);