Re: [PATCH] Re: [ID 20010422.003] Core dump in overloaded bool while using '
[p5sagit/p5-mst-13.2.git] / t / lib / time-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
15print "1..75\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
32#print "not " unless $t->minute == 34;
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
50#print "not " unless $t->monname eq 'Feb';
51print "ok 11\n";
52
53print "not " unless $t->month eq 'Feb';
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
74print "not " unless $t->day eq 'Tue';
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
85print "not " unless $t->isdst == 0;
86print "ok 22\n";
87
88print "not " unless $t->daylight_savings == 0;
89print "ok 23\n";
90
91print "not " unless $t->hms eq '12:34:56';
92print "ok 24\n";
93
94print "not " unless $t->time eq '12:34:56';
95print "ok 25\n";
96
97print "not " unless $t->ymd eq '2000-02-29';
98print "ok 26\n";
99
100print "not " unless $t->date eq '2000-02-29';
101print "ok 27\n";
102
103print "not " unless $t->mdy eq '02-29-2000';
104print "ok 28\n";
105
106print "not " unless $t->dmy eq '29-02-2000';
107print "ok 29\n";
108
109print "not " unless $t->cdate eq 'Tue Feb 29 12:34:56 2000';
110print "ok 30\n";
111
112print "not " unless "$t" eq 'Tue Feb 29 12:34:56 2000';
113print "ok 31\n";
114
115print "not " unless $t->datetime eq '2000-02-29T12:34:56';
116print "ok 32\n";
117
118print "not " unless $t->epoch == 951827696;
119print "ok 33\n";
120
121# ->tzoffset?
122
123print "not " unless ($t->julian_day / 2451604.0075) - 1 < 0.001;
124print "ok 34\n";
125
126print "not " unless ($t->mjd / 51603.5075) - 1 < 0.001;
127print "ok 35\n";
128
129print "not " unless $t->week == 9;
130print "ok 36\n";
131
132if ($Config{d_strftime}) {
133
134 # %a, %A, %b, %B, %c are locale-dependent
135
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.)
139
140 print "not " unless $t->strftime('%d') == 29;
141 print "ok 37\n";
142
143 print "not " unless $t->strftime('%D') eq '02/29/00'; # Yech!
144 print "ok 38\n";
145
146 print "not " unless $t->strftime('%e') eq '29'; # should test with < 10
147 print "ok 39\n";
148
149 print "not " unless $t->strftime('%H') eq '12'; # should test with < 10
150 print "ok 40\n";
151
152 # %h is locale-dependent
153
154 print "not " unless $t->strftime('%I') eq '12'; # should test with < 10
155 print "ok 41\n";
156
157 print "not " unless $t->strftime('%j') == 60; # why ->yday+1 ?
158 print "ok 42\n";
159
160 print "not " unless $t->strftime('%M') eq '34'; # should test with < 10
161 print "ok 43\n";
162
163 # %p, %P, and %r are not widely implemented,
164 # and are possibly unportable (am or AM or a.m., and so on)
165
166 print "not " unless $t->strftime('%R') eq '12:34'; # should test with > 12
167 print "ok 44\n";
168
169 print "not " unless $t->strftime('%S') eq '56'; # should test with < 10
170 print "ok 45\n";
171
172 print "not " unless $t->strftime('%T') eq '12:34:56'; # < 12 and > 12
173 print "ok 46\n";
174
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...)
178
179 print "not " unless $t->strftime('%U') eq '09'; # Sun cmp Mon
180 print "ok 47\n";
181
182 print "not " unless $t->strftime('%V') eq '09'; # Sun cmp Mon
183 print "ok 48\n";
184
185 print "not " unless $t->strftime('%w') == 2;
186 print "ok 49\n";
187
188 print "not " unless $t->strftime('%W') eq '09'; # Sun cmp Mon
189 print "ok 50\n";
190
191 # %x is locale and implementation dependent.
192
193 print "not " unless $t->strftime('%y') == 0; # should test with 1999
194 print "ok 51\n";
195
196 print "not " unless $t->strftime('%Y') eq '2000';
197 print "ok 52\n";
198
199 # %Z is locale and implementation dependent
200 # (there is NO standard for timezone names)
201
202} else {
203 for (38...52) {
204 print "ok $_ # Skip: no strftime\n";
205 }
206}
207
208print "not " unless $t->date("") eq '20000229';
209print "ok 53\n";
210
211print "not " unless $t->ymd("") eq '20000229';
212print "ok 54\n";
213print "not " unless $t->mdy("/") eq '02/29/2000';
214print "ok 55\n";
215
216print "not " unless $t->dmy(".") eq '29.02.2000';
217print "ok 56\n";
218
219print "not " unless $t->date_separator() eq '-';
220print "ok 57\n";
221
222$t->date_separator("/");
223
224print "not " unless $t->ymd eq '2000/02/29';
225print "ok 58\n";
226
227print "not " unless $t->date_separator() eq '/';
228print "ok 59\n";
229
230$t->date_separator("-");
231
232print "not " unless $t->hms(".") eq '12.34.56';
233print "ok 60\n";
234
235print "not " unless $t->time_separator() eq ':';
236print "ok 61\n";
237
238$t->time_separator(".");
239
240print "not " unless $t->hms eq '12.34.56';
241print "ok 62\n";
242
243print "not " unless $t->time_separator() eq '.';
244print "ok 63\n";
245
246$t->time_separator(":");
247
248my @fidays = qw( sunnuntai maanantai tiistai keskiviikko torstai
249 perjantai lauantai );
250my @frdays = qw( Dimanche Lundi Merdi Mercredi Jeudi Vendredi Samedi );
251
252print "not " unless $t->day(@fidays) eq "tiistai";
253print "ok 64\n";
254
255my @days = $t->day_list();
256
257$t->day_list(@frdays);
258
259print "not " unless $t->day eq "Merdi";
260print "ok 65\n";
261
262$t->day_list(@days);
263
264print "not " unless $t->day eq "Tue";
265print "ok 66\n";
266
267my @months = $t->mon_list();
268
269my @dumonths = qw(januari februari maart april mei juni
270 juli augustus september oktober november december);
271
272print "not " unless $t->month(@dumonths) eq "februari";
273print "ok 67\n";
274
275$t->mon_list(@dumonths);
276
277print "not " unless $t->month eq "februari";
278print "ok 68\n";
279
280$t->mon_list(@months);
281
282print "not " unless $t->month eq "Feb";
283print "ok 69\n";
284
285print "not " unless
286 $t->datetime(date => '/', T => ' ', time => '-') eq "2000/02/29 12-34-56";
287print "ok 70\n";
288
289print "not " unless $t->is_leap_year; # should test more with different dates
290print "ok 71\n";
291
292print "not " unless $t->month_last_day == 29; # test more
293print "ok 72\n";
294
295print "not " if Time::Piece::_is_leap_year(1900);
296print "ok 73\n";
297
298print "not " if Time::Piece::_is_leap_year(1901);
299print "ok 74\n";
300
301print "not " unless Time::Piece::_is_leap_year(1904);
302print "ok 75\n";
303