XS.xs

filter: Statementstmt 66.7% 361 / 541 Branchbran 47.8% 270 / 564 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 57.1% 631 / 1105 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« blib/lib/Date/Calc/XS.pm ↑ Summary DateCalc.c »
1  
2  
3 /*****************************************************************************/
4 /* */
5 /* Copyright (c) 1995 - 2015 by Steffen Beyer. */
6 /* All rights reserved. */
7 /* */
8 /* This package is free software; you can redistribute it */
9 /* and/or modify it under the same terms as Perl itself. */
10 /* */
11 /*****************************************************************************/
12  
13  
14 #include "EXTERN.h"
15 #include "perl.h"
16 #include "XSUB.h"
17  
18  
19 #include "patchlevel.h"
20 #if ((PATCHLEVEL < 4) || ((PATCHLEVEL == 4) && (SUBVERSION < 5)))
21 /* PL_na was introduced in perl5.004_05 */
22 #ifndef PL_na
23 #define PL_na na
24 #endif
25 #endif
26 #if (PATCHLEVEL < 4)
27 /* GIMME_V was introduced in perl5.004 */
28 #ifndef GIMME_V
29 #define GIMME_V GIMME
30 #endif
31 #endif
32  
33  
34 #include "DateCalc.h"
35  
36  
37 const char *_DateCalc_DATE_ERROR = "not a valid date";
38 const char *_DateCalc_TIME_ERROR = "not a valid time";
39 const char *_DateCalc_YEAR_ERROR = "year out of range";
40 const char *_DateCalc_MONTH_ERROR = "month out of range";
41 const char *_DateCalc_WEEK_ERROR = "week out of range";
42 const char *_DateCalc_DAYOFWEEK_ERROR = "day of week out of range";
43 const char *_DateCalc_DATE_RANGE_ERROR = "date out of range";
44 const char *_DateCalc_TIME_RANGE_ERROR = "time out of range";
45 const char *_DateCalc_FACTOR_ERROR = "factor out of range";
46 const char *_DateCalc_LANGUAGE_ERROR = "language not available";
47 const char *_DateCalc_SYSTEM_ERROR = "not available on this system";
48 const char *_DateCalc_MEMORY_ERROR = "unable to allocate memory";
49 const char *_DateCalc_STRING_ERROR = "argument is not a string";
50 const char *_DateCalc_SCALAR_ERROR = "argument is not a scalar";
51  
52  
53 #define DATECALC_STRING(ref,var,len) \
54 ( ref && !(SvROK(ref)) && SvPOK(ref) && \
55 (var = (charptr)SvPV(ref,PL_na)) && \
56 ((len = (N_int)SvCUR(ref)) | 1) )
57  
58 #define DATECALC_SCALAR(ref,typ,var) \
59 ( ref && !(SvROK(ref)) && ((var = (typ)SvIV(ref)) | 1) )
60  
61  
62 #define DATECALC_ERROR(message) \
63 croak("Date::Calc::%s(): %s", GvNAME(CvGV(cv)), message)
64  
65  
66 #define DATECALC_DATE_ERROR \
67 DATECALC_ERROR( _DateCalc_DATE_ERROR )
68  
69 #define DATECALC_TIME_ERROR \
70 DATECALC_ERROR( _DateCalc_TIME_ERROR )
71  
72 #define DATECALC_YEAR_ERROR \
73 DATECALC_ERROR( _DateCalc_YEAR_ERROR )
74  
75 #define DATECALC_MONTH_ERROR \
76 DATECALC_ERROR( _DateCalc_MONTH_ERROR )
77  
78 #define DATECALC_WEEK_ERROR \
79 DATECALC_ERROR( _DateCalc_WEEK_ERROR )
80  
81 #define DATECALC_DAYOFWEEK_ERROR \
82 DATECALC_ERROR( _DateCalc_DAYOFWEEK_ERROR )
83  
84 #define DATECALC_DATE_RANGE_ERROR \
85 DATECALC_ERROR( _DateCalc_DATE_RANGE_ERROR )
86  
87 #define DATECALC_TIME_RANGE_ERROR \
88 DATECALC_ERROR( _DateCalc_TIME_RANGE_ERROR )
89  
90 #define DATECALC_FACTOR_ERROR \
91 DATECALC_ERROR( _DateCalc_FACTOR_ERROR )
92  
93 #define DATECALC_LANGUAGE_ERROR \
94 DATECALC_ERROR( _DateCalc_LANGUAGE_ERROR )
95  
96 #define DATECALC_SYSTEM_ERROR \
97 DATECALC_ERROR( _DateCalc_SYSTEM_ERROR )
98  
99 #define DATECALC_MEMORY_ERROR \
100 DATECALC_ERROR( _DateCalc_MEMORY_ERROR )
101  
102 #define DATECALC_STRING_ERROR \
103 DATECALC_ERROR( _DateCalc_STRING_ERROR )
104  
105 #define DATECALC_SCALAR_ERROR \
106 DATECALC_ERROR( _DateCalc_SCALAR_ERROR )
107  
108  
109 MODULE = Date::Calc::XS PACKAGE = Date::Calc::XS PREFIX = DateCalc_
110  
111  
112 PROTOTYPES: DISABLE
113  
114  
115 void
116 DateCalc_Days_in_Year(year,month)
117 Z_int year
118 Z_int month
119 PPCODE:
120 {
121 191 ▶ if (year > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (year > 0) 191 0 191
122 {
123 191 ▶ if ((month >= 1) and (month <= 12))
Branch: 2 branches
BranchTrueFalseTotal
if ((month >= 1) and (month <= 12)) 191 0 191
if ((month >= 1) and (month <= 12)) 191 0 191
124 {
125 191 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 191 191
126 191 PUSHs(sv_2mortal(newSViv((IV)DateCalc_Days_in_Year_[DateCalc_leap_year(year)][month+1])));
127 }
128 0 else DATECALC_MONTH_ERROR;
129 }
130 0 else DATECALC_YEAR_ERROR;
131 }
132  
133  
134 void
135 DateCalc_Days_in_Month(year,month)
136 Z_int year
137 Z_int month
138 PPCODE:
139 {
140 26 ▶ if (year > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (year > 0) 26 0 26
141 {
142 26 ▶ if ((month >= 1) and (month <= 12))
Branch: 2 branches
BranchTrueFalseTotal
if ((month >= 1) and (month <= 12)) 24 2 26
if ((month >= 1) and (month <= 12)) 24 0 24
143 {
144 24 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 24 24
145 24 PUSHs(sv_2mortal(newSViv((IV)DateCalc_Days_in_Month_[DateCalc_leap_year(year)][month])));
146 }
147 2 else DATECALC_MONTH_ERROR;
148 }
149 0 else DATECALC_YEAR_ERROR;
150 }
151  
152  
153 Z_int
154 DateCalc_Weeks_in_Year(year)
155 Z_int year
156 CODE:
157 {
158 4 ▶ if (year > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (year > 0) 4 0 4
159 {
160 4 RETVAL = DateCalc_Weeks_in_Year(year);
161 }
162 0 else DATECALC_YEAR_ERROR;
163 }
164 OUTPUT:
165 RETVAL
166  
167  
168 boolean
169 DateCalc_leap_year(year)
170 Z_int year
171 CODE:
172 {
173 4 ▶ if (year > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (year > 0) 4 0 4
174 {
175 4 RETVAL = DateCalc_leap_year(year);
176 }
177 0 else DATECALC_YEAR_ERROR;
178 }
179 OUTPUT:
180 RETVAL
181  
182  
183 boolean
184 DateCalc_check_date(year,month,day)
185 Z_int year
186 Z_int month
187 Z_int day
188  
189  
190 boolean
191 DateCalc_check_time(hour,min,sec)
192 Z_int hour
193 Z_int min
194 Z_int sec
195  
196  
197 boolean
198 DateCalc_check_business_date(year,week,dow)
199 Z_int year
200 Z_int week
201 Z_int dow
202  
203  
204 Z_int
205 DateCalc_Day_of_Year(year,month,day)
206 Z_int year
207 Z_int month
208 Z_int day
209 CODE:
210 {
211 0 RETVAL = DateCalc_Day_of_Year(year,month,day);
212 0 ▶ if (RETVAL == 0) DATECALC_DATE_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == 0) DATECALC_DATE_ERROR; 0 0 0
213 }
214 OUTPUT:
215 RETVAL
216  
217  
218 Z_long
219 DateCalc_Date_to_Days(year,month,day)
220 Z_int year
221 Z_int month
222 Z_int day
223 CODE:
224 {
225 24648 RETVAL = DateCalc_Date_to_Days(year,month,day);
226 24648 ▶ if (RETVAL == 0) DATECALC_DATE_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == 0) DATECALC_DATE_ERROR; 0 24648 24648
227 }
228 OUTPUT:
229 RETVAL
230  
231  
232 Z_int
233 DateCalc_Day_of_Week(year,month,day)
234 Z_int year
235 Z_int month
236 Z_int day
237 CODE:
238 {
239 870 RETVAL = DateCalc_Day_of_Week(year,month,day);
240 870 ▶ if (RETVAL == 0) DATECALC_DATE_ERROR;
Branch: 1 branch
BranchTrueFalseTotal
if (RETVAL == 0) DATECALC_DATE_ERROR; 1 869 870
241 }
242 OUTPUT:
243 RETVAL
244  
245  
246 Z_int
247 DateCalc_Week_Number(year,month,day)
248 Z_int year
249 Z_int month
250 Z_int day
251 CODE:
252 {
253 0 ▶ if (DateCalc_check_date(year,month,day))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_check_date(year,month,day)) 0 0 0
254 {
255 0 RETVAL = DateCalc_Week_Number(year,month,day);
256 }
257 0 else DATECALC_DATE_ERROR;
258 }
259 OUTPUT:
260 RETVAL
261  
262  
263 void
264 DateCalc_Week_of_Year(year,month,day)
265 Z_int year
266 Z_int month
267 Z_int day
268 PPCODE:
269 {
270 Z_int week;
271  
272 9 ▶ if (DateCalc_week_of_year(&week,&year,month,day))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_week_of_year(&week,&year,month,day)) 7 2 9
273 {
274 7 ▶ if (GIMME_V == G_ARRAY)
Branch: 1 branch
BranchTrueFalseTotal
if (GIMME_V == G_ARRAY) 7 0 7
275 {
276 7 ▶ EXTEND(sp,2);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,2); 0 7 7
277 7 PUSHs(sv_2mortal(newSViv((IV)week)));
278 7 PUSHs(sv_2mortal(newSViv((IV)year)));
279 }
280 else
281 {
282 0 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 0 0
283 0 PUSHs(sv_2mortal(newSViv((IV)week)));
284 }
285 }
286 2 else DATECALC_DATE_ERROR;
287 }
288  
289  
290 void
291 DateCalc_Monday_of_Week(week,year)
292 Z_int week
293 Z_int year
294 PPCODE:
295 {
296 Z_int month;
297 Z_int day;
298  
299 17 ▶ if (year > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (year > 0) 15 2 17
300 {
301 15 ▶ if ((week > 0) and (week <= DateCalc_Weeks_in_Year(year)))
Branch: 2 branches
BranchTrueFalseTotal
if ((week > 0) and (week <= DateCalc_Weeks_in_Year(year))) 13 2 15
if ((week > 0) and (week <= DateCalc_Weeks_in_Year(year))) 11 2 13
302 {
303 22 ▶ if (DateCalc_monday_of_week(week,&year,&month,&day))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_monday_of_week(week,&year,&month,&day)) 11 0 11
304 {
305 11 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 11 11
306 11 PUSHs(sv_2mortal(newSViv((IV)year)));
307 11 PUSHs(sv_2mortal(newSViv((IV)month)));
308 11 PUSHs(sv_2mortal(newSViv((IV)day)));
309 }
310 0 else DATECALC_DATE_ERROR;
311 }
312 4 else DATECALC_WEEK_ERROR;
313 }
314 2 else DATECALC_YEAR_ERROR;
315 }
316  
317  
318 void
319 DateCalc_Nth_Weekday_of_Month_Year(year,month,dow,n)
320 Z_int year
321 Z_int month
322 Z_int dow
323 Z_int n
324 PPCODE:
325 {
326 Z_int day;
327  
328 1323 ▶ if (year > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (year > 0) 1323 0 1323
329 {
330 1323 ▶ if ((month >= 1) and (month <= 12))
Branch: 2 branches
BranchTrueFalseTotal
if ((month >= 1) and (month <= 12)) 1323 0 1323
if ((month >= 1) and (month <= 12)) 1323 0 1323
331 {
332 1323 ▶ if ((dow >= 1) and (dow <= 7))
Branch: 2 branches
BranchTrueFalseTotal
if ((dow >= 1) and (dow <= 7)) 1323 0 1323
if ((dow >= 1) and (dow <= 7)) 1323 0 1323
333 {
334 1323 ▶ if ((n >= 1) and (n <= 5))
Branch: 2 branches
BranchTrueFalseTotal
if ((n >= 1) and (n <= 5)) 1323 0 1323
if ((n >= 1) and (n <= 5)) 1323 0 1323
335 {
336 2575 ▶ if (DateCalc_nth_weekday_of_month_year(&year,&month,&day,dow,n))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_nth_weekday_of_month_year(&year,&month,&day,dow,n)) 1252 71 1323
337 {
338 1252 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 1252 1252
339 1252 PUSHs(sv_2mortal(newSViv((IV)year)));
340 1252 PUSHs(sv_2mortal(newSViv((IV)month)));
341 1252 PUSHs(sv_2mortal(newSViv((IV)day)));
342 }
343 /* else return empty list */
344 }
345 0 else DATECALC_FACTOR_ERROR;
346 }
347 0 else DATECALC_DAYOFWEEK_ERROR;
348 }
349 0 else DATECALC_MONTH_ERROR;
350 }
351 0 else DATECALC_YEAR_ERROR;
352 }
353  
354  
355 void
356 DateCalc_Standard_to_Business(year,month,day)
357 Z_int year
358 Z_int month
359 Z_int day
360 PPCODE:
361 {
362 Z_int week;
363 Z_int dow;
364  
365 629 ▶ if (DateCalc_standard_to_business(&year,&week,&dow,month,day))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_standard_to_business(&year,&week,&dow,month,day)) 629 0 629
366 {
367 629 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 629 629
368 629 PUSHs(sv_2mortal(newSViv((IV)year)));
369 629 PUSHs(sv_2mortal(newSViv((IV)week)));
370 629 PUSHs(sv_2mortal(newSViv((IV)dow)));
371 }
372 0 else DATECALC_DATE_ERROR;
373 }
374  
375  
376 void
377 DateCalc_Business_to_Standard(year,week,dow)
378 Z_int year
379 Z_int week
380 Z_int dow
381 PPCODE:
382 {
383 Z_int month;
384 Z_int day;
385  
386 629 ▶ if (DateCalc_business_to_standard(&year,&month,&day,week,dow))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_business_to_standard(&year,&month,&day,week,dow)) 629 0 629
387 {
388 629 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 629 629
389 629 PUSHs(sv_2mortal(newSViv((IV)year)));
390 629 PUSHs(sv_2mortal(newSViv((IV)month)));
391 629 PUSHs(sv_2mortal(newSViv((IV)day)));
392 }
393 0 else DATECALC_DATE_ERROR;
394 }
395  
396  
397 Z_long
398 DateCalc_Delta_Days(year1,month1,day1, year2,month2,day2)
399 Z_int year1
400 Z_int month1
401 Z_int day1
402 Z_int year2
403 Z_int month2
404 Z_int day2
405 CODE:
406 {
407 28 if (DateCalc_check_date(year1,month1,day1) and
408 13 DateCalc_check_date(year2,month2,day2))
409 {
410 12 RETVAL = DateCalc_Delta_Days(year1,month1,day1, year2,month2,day2);
411 }
412 3 else DATECALC_DATE_ERROR;
413 }
414 OUTPUT:
415 RETVAL
416  
417  
418 void
419 DateCalc_Delta_DHMS(year1,month1,day1, hour1,min1,sec1, year2,month2,day2, hour2,min2,sec2)
420 Z_int year1
421 Z_int month1
422 Z_int day1
423 Z_int hour1
424 Z_int min1
425 Z_int sec1
426 Z_int year2
427 Z_int month2
428 Z_int day2
429 Z_int hour2
430 Z_int min2
431 Z_int sec2
432 PPCODE:
433 {
434 Z_long Dd;
435 Z_int Dh;
436 Z_int Dm;
437 Z_int Ds;
438  
439 62 if (DateCalc_check_date(year1,month1,day1) and
440 30 DateCalc_check_date(year2,month2,day2))
441 {
442 69 if (DateCalc_check_time(hour1,min1,sec1) and
443 23 DateCalc_check_time(hour2,min2,sec2))
444 {
445 34 ▶ if (DateCalc_delta_dhms(&Dd,&Dh,&Dm,&Ds,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_delta_dhms(&Dd,&Dh,&Dm,&Ds, 17 0 17
446 year1,month1,day1, hour1,min1,sec1,
447 year2,month2,day2, hour2,min2,sec2))
448 {
449 17 ▶ EXTEND(sp,4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,4); 0 17 17
450 17 PUSHs(sv_2mortal(newSViv((IV)Dd)));
451 17 PUSHs(sv_2mortal(newSViv((IV)Dh)));
452 17 PUSHs(sv_2mortal(newSViv((IV)Dm)));
453 17 PUSHs(sv_2mortal(newSViv((IV)Ds)));
454 }
455 0 else DATECALC_DATE_ERROR;
456 }
457 12 else DATECALC_TIME_ERROR;
458 }
459 3 else DATECALC_DATE_ERROR;
460 }
461  
462  
463 void
464 DateCalc_Delta_YMD(year1,month1,day1, year2,month2,day2)
465 Z_int year1
466 Z_int month1
467 Z_int day1
468 Z_int year2
469 Z_int month2
470 Z_int day2
471 PPCODE:
472 {
473 5 ▶ if (DateCalc_delta_ymd(&year1,&month1,&day1, year2,month2,day2))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_delta_ymd(&year1,&month1,&day1, year2,month2,day2)) 5 0 5
474 {
475 5 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 5 5
476 5 PUSHs(sv_2mortal(newSViv((IV)year1)));
477 5 PUSHs(sv_2mortal(newSViv((IV)month1)));
478 5 PUSHs(sv_2mortal(newSViv((IV)day1)));
479 }
480 0 else DATECALC_DATE_ERROR;
481 }
482  
483  
484 void
485 DateCalc_Delta_YMDHMS(year1,month1,day1, hour1,min1,sec1, year2,month2,day2, hour2,min2,sec2)
486 Z_int year1
487 Z_int month1
488 Z_int day1
489 Z_int hour1
490 Z_int min1
491 Z_int sec1
492 Z_int year2
493 Z_int month2
494 Z_int day2
495 Z_int hour2
496 Z_int min2
497 Z_int sec2
498 PPCODE:
499 {
500 Z_int D_y;
501 Z_int D_m;
502 Z_int D_d;
503 Z_int Dh;
504 Z_int Dm;
505 Z_int Ds;
506  
507 6 if (DateCalc_check_date(year1,month1,day1) and
508 3 DateCalc_check_date(year2,month2,day2))
509 {
510 9 if (DateCalc_check_time(hour1,min1,sec1) and
511 3 DateCalc_check_time(hour2,min2,sec2))
512 {
513 6 ▶ if (DateCalc_delta_ymdhms(&D_y,&D_m,&D_d, &Dh,&Dm,&Ds,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_delta_ymdhms(&D_y,&D_m,&D_d, &Dh,&Dm,&Ds, 3 0 3
514 year1,month1,day1, hour1,min1,sec1,
515 year2,month2,day2, hour2,min2,sec2))
516 {
517 3 ▶ EXTEND(sp,6);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,6); 0 3 3
518 3 PUSHs(sv_2mortal(newSViv((IV)D_y)));
519 3 PUSHs(sv_2mortal(newSViv((IV)D_m)));
520 3 PUSHs(sv_2mortal(newSViv((IV)D_d)));
521 3 PUSHs(sv_2mortal(newSViv((IV)Dh)));
522 3 PUSHs(sv_2mortal(newSViv((IV)Dm)));
523 3 PUSHs(sv_2mortal(newSViv((IV)Ds)));
524 }
525 0 else DATECALC_DATE_ERROR;
526 }
527 0 else DATECALC_TIME_ERROR;
528 }
529 0 else DATECALC_DATE_ERROR;
530 }
531  
532  
533 void
534 DateCalc_N_Delta_YMD(year1,month1,day1, year2,month2,day2)
535 Z_int year1
536 Z_int month1
537 Z_int day1
538 Z_int year2
539 Z_int month2
540 Z_int day2
541 PPCODE:
542 {
543 82 ▶ if (DateCalc_norm_delta_ymd(&year1,&month1,&day1, year2,month2,day2))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_norm_delta_ymd(&year1,&month1,&day1, year2,month2,day2)) 74 8 82
544 {
545 74 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 74 74
546 74 PUSHs(sv_2mortal(newSViv((IV)year1)));
547 74 PUSHs(sv_2mortal(newSViv((IV)month1)));
548 74 PUSHs(sv_2mortal(newSViv((IV)day1)));
549 }
550 8 else DATECALC_DATE_ERROR;
551 }
552  
553  
554 void
555 DateCalc_N_Delta_YMDHMS(year1,month1,day1, hour1,min1,sec1, year2,month2,day2, hour2,min2,sec2)
556 Z_int year1
557 Z_int month1
558 Z_int day1
559 Z_int hour1
560 Z_int min1
561 Z_int sec1
562 Z_int year2
563 Z_int month2
564 Z_int day2
565 Z_int hour2
566 Z_int min2
567 Z_int sec2
568 PPCODE:
569 {
570 Z_int D_y;
571 Z_int D_m;
572 Z_int D_d;
573 Z_int Dhh;
574 Z_int Dmm;
575 Z_int Dss;
576  
577 167 if (DateCalc_check_date(year1,month1,day1) and
578 83 DateCalc_check_date(year2,month2,day2))
579 {
580 243 if (DateCalc_check_time(hour1,min1,sec1) and
581 81 DateCalc_check_time(hour2,min2,sec2))
582 {
583 160 ▶ if (DateCalc_norm_delta_ymdhms(&D_y,&D_m,&D_d, &Dhh,&Dmm,&Dss,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_norm_delta_ymdhms(&D_y,&D_m,&D_d, &Dhh,&Dmm,&Dss, 80 0 80
584 year1,month1,day1, hour1,min1,sec1,
585 year2,month2,day2, hour2,min2,sec2))
586 {
587 80 ▶ EXTEND(sp,6);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,6); 0 80 80
588 80 PUSHs(sv_2mortal(newSViv((IV)D_y)));
589 80 PUSHs(sv_2mortal(newSViv((IV)D_m)));
590 80 PUSHs(sv_2mortal(newSViv((IV)D_d)));
591 80 PUSHs(sv_2mortal(newSViv((IV)Dhh)));
592 80 PUSHs(sv_2mortal(newSViv((IV)Dmm)));
593 80 PUSHs(sv_2mortal(newSViv((IV)Dss)));
594 }
595 0 else DATECALC_DATE_ERROR;
596 }
597 2 else DATECALC_TIME_ERROR;
598 }
599 2 else DATECALC_DATE_ERROR;
600 }
601  
602  
603 void
604 DateCalc_Normalize_DHMS(Dd,Dh,Dm,Ds)
605 Z_long Dd
606 Z_long Dh
607 Z_long Dm
608 Z_long Ds
609 PPCODE:
610 {
611 14 DateCalc_Normalize_DHMS(&Dd,&Dh,&Dm,&Ds);
612 14 ▶ EXTEND(sp,4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,4); 0 14 14
613 14 PUSHs(sv_2mortal(newSViv((IV)Dd)));
614 14 PUSHs(sv_2mortal(newSViv((IV)Dh)));
615 14 PUSHs(sv_2mortal(newSViv((IV)Dm)));
616 14 PUSHs(sv_2mortal(newSViv((IV)Ds)));
617 }
618  
619  
620 void
621 DateCalc_Add_Delta_Days(year,month,day, Dd)
622 Z_int year
623 Z_int month
624 Z_int day
625 Z_long Dd
626 PPCODE:
627 {
628 2213 ▶ if (DateCalc_add_delta_days(&year,&month,&day, Dd))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_add_delta_days(&year,&month,&day, Dd)) 2210 3 2213
629 {
630 2210 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 2210 2210
631 2210 PUSHs(sv_2mortal(newSViv((IV)year)));
632 2210 PUSHs(sv_2mortal(newSViv((IV)month)));
633 2210 PUSHs(sv_2mortal(newSViv((IV)day)));
634 }
635 3 else DATECALC_DATE_ERROR;
636 }
637  
638  
639 void
640 DateCalc_Add_Delta_DHMS(year,month,day, hour,min,sec, Dd,Dh,Dm,Ds)
641 Z_int year
642 Z_int month
643 Z_int day
644 Z_int hour
645 Z_int min
646 Z_int sec
647 Z_long Dd
648 Z_long Dh
649 Z_long Dm
650 Z_long Ds
651 PPCODE:
652 {
653 56 ▶ if (DateCalc_check_date(year,month,day))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_check_date(year,month,day)) 55 1 56
654 {
655 55 ▶ if (DateCalc_check_time(hour,min,sec))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_check_time(hour,min,sec)) 52 3 55
656 {
657 52 ▶ if (DateCalc_add_delta_dhms(&year,&month,&day,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_add_delta_dhms(&year,&month,&day, 51 1 52
658 &hour,&min,&sec,
659 Dd,Dh,Dm,Ds))
660 {
661 51 ▶ EXTEND(sp,6);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,6); 0 51 51
662 51 PUSHs(sv_2mortal(newSViv((IV)year)));
663 51 PUSHs(sv_2mortal(newSViv((IV)month)));
664 51 PUSHs(sv_2mortal(newSViv((IV)day)));
665 51 PUSHs(sv_2mortal(newSViv((IV)hour)));
666 51 PUSHs(sv_2mortal(newSViv((IV)min)));
667 51 PUSHs(sv_2mortal(newSViv((IV)sec)));
668 }
669 1 else DATECALC_DATE_ERROR;
670 }
671 3 else DATECALC_TIME_ERROR;
672 }
673 1 else DATECALC_DATE_ERROR;
674 }
675  
676  
677 void
678 DateCalc_Add_Delta_YM(year,month,day, Dy,Dm)
679 Z_int year
680 Z_int month
681 Z_int day
682 Z_long Dy
683 Z_long Dm
684 PPCODE:
685 {
686 74 ▶ if (DateCalc_add_delta_ym(&year,&month,&day, Dy,Dm))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_add_delta_ym(&year,&month,&day, Dy,Dm)) 74 0 74
687 {
688 74 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 74 74
689 74 PUSHs(sv_2mortal(newSViv((IV)year)));
690 74 PUSHs(sv_2mortal(newSViv((IV)month)));
691 74 PUSHs(sv_2mortal(newSViv((IV)day)));
692 }
693 0 else DATECALC_DATE_ERROR;
694 }
695  
696  
697 void
698 DateCalc_Add_Delta_YMD(year,month,day, Dy,Dm,Dd)
699 Z_int year
700 Z_int month
701 Z_int day
702 Z_long Dy
703 Z_long Dm
704 Z_long Dd
705 PPCODE:
706 {
707 53 ▶ if (DateCalc_add_delta_ymd(&year,&month,&day, Dy,Dm,Dd))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_add_delta_ymd(&year,&month,&day, Dy,Dm,Dd)) 45 8 53
708 {
709 45 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 45 45
710 45 PUSHs(sv_2mortal(newSViv((IV)year)));
711 45 PUSHs(sv_2mortal(newSViv((IV)month)));
712 45 PUSHs(sv_2mortal(newSViv((IV)day)));
713 }
714 8 else DATECALC_DATE_ERROR;
715 }
716  
717  
718 void
719 DateCalc_Add_Delta_YMDHMS(year,month,day, hour,min,sec, D_y,D_m,D_d, Dh,Dm,Ds)
720 Z_int year
721 Z_int month
722 Z_int day
723 Z_int hour
724 Z_int min
725 Z_int sec
726 Z_long D_y
727 Z_long D_m
728 Z_long D_d
729 Z_long Dh
730 Z_long Dm
731 Z_long Ds
732 PPCODE:
733 {
734 6 ▶ if (DateCalc_check_date(year,month,day))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_check_date(year,month,day)) 6 0 6
735 {
736 6 ▶ if (DateCalc_check_time(hour,min,sec))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_check_time(hour,min,sec)) 6 0 6
737 {
738 6 ▶ if (DateCalc_add_delta_ymdhms(&year,&month,&day,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_add_delta_ymdhms(&year,&month,&day, 6 0 6
739 &hour,&min,&sec,
740 D_y,D_m,D_d,
741 Dh,Dm,Ds))
742 {
743 6 ▶ EXTEND(sp,6);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,6); 0 6 6
744 6 PUSHs(sv_2mortal(newSViv((IV)year)));
745 6 PUSHs(sv_2mortal(newSViv((IV)month)));
746 6 PUSHs(sv_2mortal(newSViv((IV)day)));
747 6 PUSHs(sv_2mortal(newSViv((IV)hour)));
748 6 PUSHs(sv_2mortal(newSViv((IV)min)));
749 6 PUSHs(sv_2mortal(newSViv((IV)sec)));
750 }
751 0 else DATECALC_DATE_ERROR;
752 }
753 0 else DATECALC_TIME_ERROR;
754 }
755 0 else DATECALC_DATE_ERROR;
756 }
757  
758  
759 void
760 DateCalc_Add_N_Delta_YMD(year,month,day, Dy,Dm,Dd)
761 Z_int year
762 Z_int month
763 Z_int day
764 Z_long Dy
765 Z_long Dm
766 Z_long Dd
767 PPCODE:
768 {
769 96 ▶ if (DateCalc_add_norm_delta_ymd(&year,&month,&day, Dy,Dm,Dd))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_add_norm_delta_ymd(&year,&month,&day, Dy,Dm,Dd)) 96 0 96
770 {
771 96 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 96 96
772 96 PUSHs(sv_2mortal(newSViv((IV)year)));
773 96 PUSHs(sv_2mortal(newSViv((IV)month)));
774 96 PUSHs(sv_2mortal(newSViv((IV)day)));
775 }
776 0 else DATECALC_DATE_ERROR;
777 }
778  
779  
780 void
781 DateCalc_Add_N_Delta_YMDHMS(year,month,day, hour,min,sec, D_y,D_m,D_d, Dhh,Dmm,Dss)
782 Z_int year
783 Z_int month
784 Z_int day
785 Z_int hour
786 Z_int min
787 Z_int sec
788 Z_long D_y
789 Z_long D_m
790 Z_long D_d
791 Z_long Dhh
792 Z_long Dmm
793 Z_long Dss
794 PPCODE:
795 {
796 80 ▶ if (DateCalc_check_date(year,month,day))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_check_date(year,month,day)) 80 0 80
797 {
798 80 ▶ if (DateCalc_check_time(hour,min,sec))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_check_time(hour,min,sec)) 80 0 80
799 {
800 80 ▶ if (DateCalc_add_norm_delta_ymdhms(&year,&month,&day,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_add_norm_delta_ymdhms(&year,&month,&day, 80 0 80
801 &hour,&min,&sec,
802 D_y,D_m,D_d,
803 Dhh,Dmm,Dss))
804 {
805 80 ▶ EXTEND(sp,6);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,6); 0 80 80
806 80 PUSHs(sv_2mortal(newSViv((IV)year)));
807 80 PUSHs(sv_2mortal(newSViv((IV)month)));
808 80 PUSHs(sv_2mortal(newSViv((IV)day)));
809 80 PUSHs(sv_2mortal(newSViv((IV)hour)));
810 80 PUSHs(sv_2mortal(newSViv((IV)min)));
811 80 PUSHs(sv_2mortal(newSViv((IV)sec)));
812 }
813 0 else DATECALC_DATE_ERROR;
814 }
815 0 else DATECALC_TIME_ERROR;
816 }
817 0 else DATECALC_DATE_ERROR;
818 }
819  
820  
821 void
822 DateCalc_System_Clock(...)
823 PPCODE:
824 {
825 Z_int year;
826 Z_int month;
827 Z_int day;
828 Z_int hour;
829 Z_int min;
830 Z_int sec;
831 Z_int doy;
832 Z_int dow;
833 Z_int dst;
834 boolean gmt;
835  
836 0 ▶ if ((items == 0) or (items == 1))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 0) or (items == 1)) 0 0 0
if ((items == 0) or (items == 1)) 0 0 0
837 {
838 0 ▶ if (items == 1) gmt = (boolean) SvIV( ST(0) );
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) gmt = (boolean) SvIV( ST(0) ); 0 0 0
839 0 else gmt = false;
840 0 ▶ if (DateCalc_system_clock(&year,&month,&day,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_system_clock(&year,&month,&day, 0 0 0
841 &hour,&min,&sec,
842 &doy,&dow,&dst,
843 gmt))
844 {
845 0 ▶ EXTEND(sp,9);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,9); 0 0 0
846 0 PUSHs(sv_2mortal(newSViv((IV)year)));
847 0 PUSHs(sv_2mortal(newSViv((IV)month)));
848 0 PUSHs(sv_2mortal(newSViv((IV)day)));
849 0 PUSHs(sv_2mortal(newSViv((IV)hour)));
850 0 PUSHs(sv_2mortal(newSViv((IV)min)));
851 0 PUSHs(sv_2mortal(newSViv((IV)sec)));
852 0 PUSHs(sv_2mortal(newSViv((IV)doy)));
853 0 PUSHs(sv_2mortal(newSViv((IV)dow)));
854 0 PUSHs(sv_2mortal(newSViv((IV)dst)));
855 }
856 0 else DATECALC_SYSTEM_ERROR;
857 }
858 0 else croak("Usage: Date::Calc::System_Clock([gmt])");
859 }
860  
861  
862 void
863 DateCalc_Today(...)
864 PPCODE:
865 {
866 Z_int year;
867 Z_int month;
868 Z_int day;
869 Z_int hour;
870 Z_int min;
871 Z_int sec;
872 Z_int doy;
873 Z_int dow;
874 Z_int dst;
875 boolean gmt;
876  
877 0 ▶ if ((items == 0) or (items == 1))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 0) or (items == 1)) 0 0 0
if ((items == 0) or (items == 1)) 0 0 0
878 {
879 0 ▶ if (items == 1) gmt = (boolean) SvIV( ST(0) );
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) gmt = (boolean) SvIV( ST(0) ); 0 0 0
880 0 else gmt = false;
881 0 ▶ if (DateCalc_system_clock(&year,&month,&day,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_system_clock(&year,&month,&day, 0 0 0
882 &hour,&min,&sec,
883 &doy,&dow,&dst,
884 gmt))
885 {
886 0 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 0 0
887 0 PUSHs(sv_2mortal(newSViv((IV)year)));
888 0 PUSHs(sv_2mortal(newSViv((IV)month)));
889 0 PUSHs(sv_2mortal(newSViv((IV)day)));
890 }
891 0 else DATECALC_SYSTEM_ERROR;
892 }
893 0 else croak("Usage: Date::Calc::Today([gmt])");
894 }
895  
896  
897 void
898 DateCalc_Now(...)
899 PPCODE:
900 {
901 Z_int year;
902 Z_int month;
903 Z_int day;
904 Z_int hour;
905 Z_int min;
906 Z_int sec;
907 Z_int doy;
908 Z_int dow;
909 Z_int dst;
910 boolean gmt;
911  
912 0 ▶ if ((items == 0) or (items == 1))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 0) or (items == 1)) 0 0 0
if ((items == 0) or (items == 1)) 0 0 0
913 {
914 0 ▶ if (items == 1) gmt = (boolean) SvIV( ST(0) );
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) gmt = (boolean) SvIV( ST(0) ); 0 0 0
915 0 else gmt = false;
916 0 ▶ if (DateCalc_system_clock(&year,&month,&day,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_system_clock(&year,&month,&day, 0 0 0
917 &hour,&min,&sec,
918 &doy,&dow,&dst,
919 gmt))
920 {
921 0 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 0 0
922 0 PUSHs(sv_2mortal(newSViv((IV)hour)));
923 0 PUSHs(sv_2mortal(newSViv((IV)min)));
924 0 PUSHs(sv_2mortal(newSViv((IV)sec)));
925 }
926 0 else DATECALC_SYSTEM_ERROR;
927 }
928 0 else croak("Usage: Date::Calc::Now([gmt])");
929 }
930  
931  
932 void
933 DateCalc_Today_and_Now(...)
934 PPCODE:
935 {
936 Z_int year;
937 Z_int month;
938 Z_int day;
939 Z_int hour;
940 Z_int min;
941 Z_int sec;
942 Z_int doy;
943 Z_int dow;
944 Z_int dst;
945 boolean gmt;
946  
947 1 ▶ if ((items == 0) or (items == 1))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 0) or (items == 1)) 0 1 1
if ((items == 0) or (items == 1)) 0 0 0
948 {
949 1 ▶ if (items == 1) gmt = (boolean) SvIV( ST(0) );
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) gmt = (boolean) SvIV( ST(0) ); 0 1 1
950 1 else gmt = false;
951 2 ▶ if (DateCalc_system_clock(&year,&month,&day,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_system_clock(&year,&month,&day, 1 0 1
952 &hour,&min,&sec,
953 &doy,&dow,&dst,
954 gmt))
955 {
956 1 ▶ EXTEND(sp,6);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,6); 0 1 1
957 1 PUSHs(sv_2mortal(newSViv((IV)year)));
958 1 PUSHs(sv_2mortal(newSViv((IV)month)));
959 1 PUSHs(sv_2mortal(newSViv((IV)day)));
960 1 PUSHs(sv_2mortal(newSViv((IV)hour)));
961 1 PUSHs(sv_2mortal(newSViv((IV)min)));
962 1 PUSHs(sv_2mortal(newSViv((IV)sec)));
963 }
964 0 else DATECALC_SYSTEM_ERROR;
965 }
966 0 else croak("Usage: Date::Calc::Today_and_Now([gmt])");
967 }
968  
969  
970 void
971 DateCalc_This_Year(...)
972 PPCODE:
973 {
974 Z_int year;
975 Z_int month;
976 Z_int day;
977 Z_int hour;
978 Z_int min;
979 Z_int sec;
980 Z_int doy;
981 Z_int dow;
982 Z_int dst;
983 boolean gmt;
984  
985 0 ▶ if ((items == 0) or (items == 1))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 0) or (items == 1)) 0 0 0
if ((items == 0) or (items == 1)) 0 0 0
986 {
987 0 ▶ if (items == 1) gmt = (boolean) SvIV( ST(0) );
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) gmt = (boolean) SvIV( ST(0) ); 0 0 0
988 0 else gmt = false;
989 0 ▶ if (DateCalc_system_clock(&year,&month,&day,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_system_clock(&year,&month,&day, 0 0 0
990 &hour,&min,&sec,
991 &doy,&dow,&dst,
992 gmt))
993 {
994 0 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 0 0
995 0 PUSHs(sv_2mortal(newSViv((IV)year)));
996 }
997 0 else DATECALC_SYSTEM_ERROR;
998 }
999 0 else croak("Usage: Date::Calc::This_Year([gmt])");
1000 }
1001  
1002  
1003 void
1004 DateCalc_Gmtime(...)
1005 PPCODE:
1006 {
1007 #ifdef MACOS_TRADITIONAL
1008 double f_seconds;
1009 #endif
1010 time_t seconds;
1011 Z_int year;
1012 Z_int month;
1013 Z_int day;
1014 Z_int hour;
1015 Z_int min;
1016 Z_int sec;
1017 Z_int doy;
1018 Z_int dow;
1019 Z_int dst;
1020  
1021 2 ▶ if ((items == 0) or (items == 1))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 0) or (items == 1)) 0 2 2
if ((items == 0) or (items == 1)) 0 0 0
1022 {
1023 #ifdef MACOS_TRADITIONAL
1024 if (items == 1) f_seconds = (double) SvNV( ST(0) );
1025 else f_seconds = (double) time(NULL);
1026 if ((f_seconds < 0) or (f_seconds > 0xFFFFFFFF))
1027 DATECALC_TIME_RANGE_ERROR;
1028 seconds = (time_t) f_seconds;
1029 #else
1030 2 ▶ if (items == 1) seconds = (time_t) SvIV( ST(0) );
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) seconds = (time_t) SvIV( ST(0) ); 0 2 2
1031 2 else seconds = time(NULL);
1032 #endif
1033 4 ▶ if (DateCalc_gmtime(&year,&month,&day,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_gmtime(&year,&month,&day, 2 0 2
1034 &hour,&min,&sec,
1035 &doy,&dow,&dst,
1036 seconds))
1037 {
1038 2 ▶ EXTEND(sp,9);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,9); 0 2 2
1039 2 PUSHs(sv_2mortal(newSViv((IV)year)));
1040 2 PUSHs(sv_2mortal(newSViv((IV)month)));
1041 2 PUSHs(sv_2mortal(newSViv((IV)day)));
1042 2 PUSHs(sv_2mortal(newSViv((IV)hour)));
1043 2 PUSHs(sv_2mortal(newSViv((IV)min)));
1044 2 PUSHs(sv_2mortal(newSViv((IV)sec)));
1045 2 PUSHs(sv_2mortal(newSViv((IV)doy)));
1046 2 PUSHs(sv_2mortal(newSViv((IV)dow)));
1047 2 PUSHs(sv_2mortal(newSViv((IV)dst)));
1048 }
1049 0 else DATECALC_TIME_RANGE_ERROR;
1050 }
1051 0 else croak("Usage: Date::Calc::Gmtime([time])");
1052 }
1053  
1054  
1055 void
1056 DateCalc_Localtime(...)
1057 PPCODE:
1058 {
1059 #ifdef MACOS_TRADITIONAL
1060 double f_seconds;
1061 #endif
1062 time_t seconds;
1063 Z_int year;
1064 Z_int month;
1065 Z_int day;
1066 Z_int hour;
1067 Z_int min;
1068 Z_int sec;
1069 Z_int doy;
1070 Z_int dow;
1071 Z_int dst;
1072  
1073 2 ▶ if ((items == 0) or (items == 1))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 0) or (items == 1)) 0 2 2
if ((items == 0) or (items == 1)) 0 0 0
1074 {
1075 #ifdef MACOS_TRADITIONAL
1076 if (items == 1) f_seconds = (double) SvNV( ST(0) );
1077 else f_seconds = (double) time(NULL);
1078 if ((f_seconds < 0) or (f_seconds > 0xFFFFFFFF))
1079 DATECALC_TIME_RANGE_ERROR;
1080 seconds = (time_t) f_seconds;
1081 #else
1082 2 ▶ if (items == 1) seconds = (time_t) SvIV( ST(0) );
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) seconds = (time_t) SvIV( ST(0) ); 0 2 2
1083 2 else seconds = time(NULL);
1084 #endif
1085 4 ▶ if (DateCalc_localtime(&year,&month,&day,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_localtime(&year,&month,&day, 2 0 2
1086 &hour,&min,&sec,
1087 &doy,&dow,&dst,
1088 seconds))
1089 {
1090 2 ▶ EXTEND(sp,9);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,9); 0 2 2
1091 2 PUSHs(sv_2mortal(newSViv((IV)year)));
1092 2 PUSHs(sv_2mortal(newSViv((IV)month)));
1093 2 PUSHs(sv_2mortal(newSViv((IV)day)));
1094 2 PUSHs(sv_2mortal(newSViv((IV)hour)));
1095 2 PUSHs(sv_2mortal(newSViv((IV)min)));
1096 2 PUSHs(sv_2mortal(newSViv((IV)sec)));
1097 2 PUSHs(sv_2mortal(newSViv((IV)doy)));
1098 2 PUSHs(sv_2mortal(newSViv((IV)dow)));
1099 2 PUSHs(sv_2mortal(newSViv((IV)dst)));
1100 }
1101 0 else DATECALC_TIME_RANGE_ERROR;
1102 }
1103 0 else croak("Usage: Date::Calc::Localtime([time])");
1104 }
1105  
1106  
1107 void
1108 DateCalc_Mktime(year,month,day, hour,min,sec)
1109 Z_int year
1110 Z_int month
1111 Z_int day
1112 Z_int hour
1113 Z_int min
1114 Z_int sec
1115 PPCODE:
1116 {
1117 time_t seconds;
1118  
1119 2 ▶ if (DateCalc_mktime(&seconds, year,month,day, hour,min,sec, -1,-1,-1))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_mktime(&seconds, year,month,day, hour,min,sec, -1,-1,-1)) 2 0 2
1120 {
1121 2 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 2 2
1122 #ifdef MACOS_TRADITIONAL
1123 PUSHs(sv_2mortal(newSVuv((UV)seconds)));
1124 #else
1125 2 PUSHs(sv_2mortal(newSViv((IV)seconds)));
1126 #endif
1127 }
1128 0 else DATECALC_DATE_RANGE_ERROR;
1129 }
1130  
1131  
1132 void
1133 DateCalc_Timezone(...)
1134 PPCODE:
1135 {
1136 #ifdef MACOS_TRADITIONAL
1137 double f_when;
1138 #endif
1139 time_t when;
1140 Z_int year;
1141 Z_int month;
1142 Z_int day;
1143 Z_int hour;
1144 Z_int min;
1145 Z_int sec;
1146 Z_int dst;
1147  
1148 0 ▶ if ((items == 0) or (items == 1))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 0) or (items == 1)) 0 0 0
if ((items == 0) or (items == 1)) 0 0 0
1149 {
1150 #ifdef MACOS_TRADITIONAL
1151 if (items == 1) f_when = (double) SvNV( ST(0) );
1152 else f_when = (double) time(NULL);
1153 if ((f_when < 0) or (f_when > 0xFFFFFFFF))
1154 DATECALC_TIME_RANGE_ERROR;
1155 when = (time_t) f_when;
1156 #else
1157 0 ▶ if (items == 1) when = (time_t) SvIV( ST(0) );
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) when = (time_t) SvIV( ST(0) ); 0 0 0
1158 0 else when = time(NULL);
1159 #endif
1160 0 ▶ if (DateCalc_timezone(&year,&month,&day,
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_timezone(&year,&month,&day, 0 0 0
1161 &hour,&min,&sec,
1162 &dst,when))
1163 {
1164 0 ▶ EXTEND(sp,7);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,7); 0 0 0
1165 0 PUSHs(sv_2mortal(newSViv((IV)year)));
1166 0 PUSHs(sv_2mortal(newSViv((IV)month)));
1167 0 PUSHs(sv_2mortal(newSViv((IV)day)));
1168 0 PUSHs(sv_2mortal(newSViv((IV)hour)));
1169 0 PUSHs(sv_2mortal(newSViv((IV)min)));
1170 0 PUSHs(sv_2mortal(newSViv((IV)sec)));
1171 0 PUSHs(sv_2mortal(newSViv((IV)dst)));
1172 }
1173 0 else DATECALC_TIME_RANGE_ERROR;
1174 }
1175 0 else croak("Usage: Date::Calc::Timezone([time])");
1176 }
1177  
1178  
1179 void
1180 DateCalc_Date_to_Time(year,month,day, hour,min,sec)
1181 Z_int year
1182 Z_int month
1183 Z_int day
1184 Z_int hour
1185 Z_int min
1186 Z_int sec
1187 PPCODE:
1188 {
1189 time_t seconds;
1190  
1191 6 ▶ if (DateCalc_date2time(&seconds, year,month,day, hour,min,sec))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_date2time(&seconds, year,month,day, hour,min,sec)) 6 0 6
1192 {
1193 6 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 6 6
1194 #ifdef MACOS_TRADITIONAL
1195 PUSHs(sv_2mortal(newSVuv((UV)seconds)));
1196 #else
1197 6 PUSHs(sv_2mortal(newSViv((IV)seconds)));
1198 #endif
1199 }
1200 0 else DATECALC_DATE_RANGE_ERROR;
1201 }
1202  
1203  
1204 void
1205 DateCalc_Time_to_Date(...)
1206 PPCODE:
1207 {
1208 #ifdef MACOS_TRADITIONAL
1209 double f_seconds;
1210 #endif
1211 time_t seconds;
1212 Z_int year;
1213 Z_int month;
1214 Z_int day;
1215 Z_int hour;
1216 Z_int min;
1217 Z_int sec;
1218  
1219 8 ▶ if ((items == 0) or (items == 1))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 0) or (items == 1)) 6 2 8
if ((items == 0) or (items == 1)) 6 0 6
1220 {
1221 #ifdef MACOS_TRADITIONAL
1222 if (items == 1) f_seconds = (double) SvNV( ST(0) );
1223 else f_seconds = (double) time(NULL);
1224 if ((f_seconds < 0) or (f_seconds > 0xFFFFFFFF))
1225 DATECALC_TIME_RANGE_ERROR;
1226 seconds = (time_t) f_seconds;
1227 #else
1228 8 ▶ if (items == 1) seconds = (time_t) SvIV( ST(0) );
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) seconds = (time_t) SvIV( ST(0) ); 6 2 8
1229 2 else seconds = time(NULL);
1230 #endif
1231 16 ▶ if (DateCalc_time2date(&year,&month,&day, &hour,&min,&sec, seconds))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_time2date(&year,&month,&day, &hour,&min,&sec, seconds)) 8 0 8
1232 {
1233 8 ▶ EXTEND(sp,6);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,6); 0 8 8
1234 8 PUSHs(sv_2mortal(newSViv((IV)year)));
1235 8 PUSHs(sv_2mortal(newSViv((IV)month)));
1236 8 PUSHs(sv_2mortal(newSViv((IV)day)));
1237 8 PUSHs(sv_2mortal(newSViv((IV)hour)));
1238 8 PUSHs(sv_2mortal(newSViv((IV)min)));
1239 8 PUSHs(sv_2mortal(newSViv((IV)sec)));
1240 }
1241 0 else DATECALC_TIME_RANGE_ERROR;
1242 }
1243 0 else croak("Usage: Date::Calc::Time_to_Date([time])");
1244 }
1245  
1246  
1247 void
1248 DateCalc_Easter_Sunday(year)
1249 Z_int year
1250 PPCODE:
1251 {
1252 Z_int month;
1253 Z_int day;
1254  
1255 910 ▶ if ((year > 0) and DateCalc_easter_sunday(&year,&month,&day))
Branch: 2 branches
BranchTrueFalseTotal
if ((year > 0) and DateCalc_easter_sunday(&year,&month,&day)) 910 0 910
if ((year > 0) and DateCalc_easter_sunday(&year,&month,&day)) 908 2 910
1256 {
1257 908 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 908 908
1258 908 PUSHs(sv_2mortal(newSViv((IV)year)));
1259 908 PUSHs(sv_2mortal(newSViv((IV)month)));
1260 908 PUSHs(sv_2mortal(newSViv((IV)day)));
1261 }
1262 2 else DATECALC_YEAR_ERROR;
1263 }
1264  
1265  
1266 void
1267 DateCalc_Decode_Month(...)
1268 PPCODE:
1269 {
1270 charptr string;
1271 N_int length;
1272 Z_int lang;
1273  
1274 2109 ▶ if ((items == 1) or (items == 2))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 1) or (items == 2)) 1210 899 2109
if ((items == 1) or (items == 2)) 1210 0 1210
1275 {
1276 4218 ▶ if ( DATECALC_STRING(ST(0),string,length) )
Branch: 4 branches
BranchTrueFalseTotal
if ( DATECALC_STRING(ST(0),string,length) ) 2109 0 2109
if ( DATECALC_STRING(ST(0),string,length) ) 2109 0 2109
if ( DATECALC_STRING(ST(0),string,length) ) 2109 0 2109
if ( DATECALC_STRING(ST(0),string,length) ) 2109 0 2109
1277 {
1278 2109 ▶ if (items == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 2) 1210 899 2109
1279 {
1280 1210 ▶ if ( not DATECALC_SCALAR(ST(1),Z_int,lang) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 1210 0 1210
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 1210 0 1210
1281 0 DATECALC_SCALAR_ERROR;
1282 }
1283 899 else lang = 0;
1284 2109 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 2109 2109
1285 2109 PUSHs(sv_2mortal(newSViv((IV)DateCalc_Decode_Month(string,length,lang))));
1286 }
1287 0 else DATECALC_STRING_ERROR;
1288 }
1289 0 else croak("Usage: Date::Calc::Decode_Month(string[,lang])");
1290 }
1291  
1292  
1293 void
1294 DateCalc_Decode_Day_of_Week(...)
1295 PPCODE:
1296 {
1297 charptr string;
1298 N_int length;
1299 Z_int lang;
1300  
1301 1187 ▶ if ((items == 1) or (items == 2))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 1) or (items == 2)) 1153 34 1187
if ((items == 1) or (items == 2)) 1153 0 1153
1302 {
1303 2374 ▶ if ( DATECALC_STRING(ST(0),string,length) )
Branch: 4 branches
BranchTrueFalseTotal
if ( DATECALC_STRING(ST(0),string,length) ) 1187 0 1187
if ( DATECALC_STRING(ST(0),string,length) ) 1187 0 1187
if ( DATECALC_STRING(ST(0),string,length) ) 1187 0 1187
if ( DATECALC_STRING(ST(0),string,length) ) 1187 0 1187
1304 {
1305 1187 ▶ if (items == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 2) 1153 34 1187
1306 {
1307 1153 ▶ if ( not DATECALC_SCALAR(ST(1),Z_int,lang) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 1153 0 1153
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 1153 0 1153
1308 0 DATECALC_SCALAR_ERROR;
1309 }
1310 34 else lang = 0;
1311 1187 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 1187 1187
1312 1187 PUSHs(sv_2mortal(newSViv((IV)DateCalc_Decode_Day_of_Week(string,length,lang))));
1313 }
1314 0 else DATECALC_STRING_ERROR;
1315 }
1316 0 else croak("Usage: Date::Calc::Decode_Day_of_Week(string[,lang])");
1317 }
1318  
1319  
1320 Z_int
1321 DateCalc_Decode_Language(string)
1322 charptr string
1323 CODE:
1324 {
1325 10 RETVAL = DateCalc_Decode_Language(string,strlen((char *)string));
1326 }
1327 OUTPUT:
1328 RETVAL
1329  
1330  
1331 void
1332 DateCalc_Decode_Date_EU(...)
1333 PPCODE:
1334 {
1335 charptr string;
1336 N_int length;
1337 Z_int lang;
1338 Z_int year;
1339 Z_int month;
1340 Z_int day;
1341  
1342 14 ▶ if ((items == 1) or (items == 2))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 1) or (items == 2)) 4 10 14
if ((items == 1) or (items == 2)) 4 0 4
1343 {
1344 28 ▶ if ( DATECALC_STRING(ST(0),string,length) )
Branch: 4 branches
BranchTrueFalseTotal
if ( DATECALC_STRING(ST(0),string,length) ) 14 0 14
if ( DATECALC_STRING(ST(0),string,length) ) 14 0 14
if ( DATECALC_STRING(ST(0),string,length) ) 14 0 14
if ( DATECALC_STRING(ST(0),string,length) ) 14 0 14
1345 {
1346 14 ▶ if (items == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 2) 4 10 14
1347 {
1348 4 ▶ if ( not DATECALC_SCALAR(ST(1),Z_int,lang) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 4 0 4
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 4 0 4
1349 0 DATECALC_SCALAR_ERROR;
1350 }
1351 10 else lang = 0;
1352 27 ▶ if (DateCalc_decode_date_eu(string,&year,&month,&day,lang))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_decode_date_eu(string,&year,&month,&day,lang)) 13 1 14
1353 {
1354 13 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 13 13
1355 13 PUSHs(sv_2mortal(newSViv((IV)year)));
1356 13 PUSHs(sv_2mortal(newSViv((IV)month)));
1357 13 PUSHs(sv_2mortal(newSViv((IV)day)));
1358 }
1359 /* else return empty list */
1360 }
1361 0 else DATECALC_STRING_ERROR;
1362 }
1363 0 else croak("Usage: Date::Calc::Decode_Date_EU(string[,lang])");
1364 }
1365  
1366  
1367 void
1368 DateCalc_Decode_Date_US(...)
1369 PPCODE:
1370 {
1371 charptr string;
1372 N_int length;
1373 Z_int lang;
1374 Z_int year;
1375 Z_int month;
1376 Z_int day;
1377  
1378 11 ▶ if ((items == 1) or (items == 2))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 1) or (items == 2)) 0 11 11
if ((items == 1) or (items == 2)) 0 0 0
1379 {
1380 22 ▶ if ( DATECALC_STRING(ST(0),string,length) )
Branch: 4 branches
BranchTrueFalseTotal
if ( DATECALC_STRING(ST(0),string,length) ) 11 0 11
if ( DATECALC_STRING(ST(0),string,length) ) 11 0 11
if ( DATECALC_STRING(ST(0),string,length) ) 11 0 11
if ( DATECALC_STRING(ST(0),string,length) ) 11 0 11
1381 {
1382 11 ▶ if (items == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 2) 0 11 11
1383 {
1384 0 ▶ if ( not DATECALC_SCALAR(ST(1),Z_int,lang) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 0 0 0
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 0 0 0
1385 0 DATECALC_SCALAR_ERROR;
1386 }
1387 11 else lang = 0;
1388 21 ▶ if (DateCalc_decode_date_us(string,&year,&month,&day,lang))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_decode_date_us(string,&year,&month,&day,lang)) 10 1 11
1389 {
1390 10 ▶ EXTEND(sp,3);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,3); 0 10 10
1391 10 PUSHs(sv_2mortal(newSViv((IV)year)));
1392 10 PUSHs(sv_2mortal(newSViv((IV)month)));
1393 10 PUSHs(sv_2mortal(newSViv((IV)day)));
1394 }
1395 /* else return empty list */
1396 }
1397 0 else DATECALC_STRING_ERROR;
1398 }
1399 0 else croak("Usage: Date::Calc::Decode_Date_US(string[,lang])");
1400 }
1401  
1402  
1403 Z_int
1404 DateCalc_Fixed_Window(year)
1405 Z_int year
1406  
1407  
1408 Z_int
1409 DateCalc_Moving_Window(year)
1410 Z_int year
1411  
1412  
1413 Z_int
1414 DateCalc_Compress(year,month,day)
1415 Z_int year
1416 Z_int month
1417 Z_int day
1418  
1419  
1420 void
1421 DateCalc_Uncompress(date)
1422 Z_int date
1423 PPCODE:
1424 {
1425 Z_int century;
1426 Z_int year;
1427 Z_int month;
1428 Z_int day;
1429  
1430 5 ▶ if (DateCalc_uncompress(date,&century,&year,&month,&day))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_uncompress(date,&century,&year,&month,&day)) 3 2 5
1431 {
1432 3 ▶ EXTEND(sp,4);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,4); 0 3 3
1433 3 PUSHs(sv_2mortal(newSViv((IV)century)));
1434 3 PUSHs(sv_2mortal(newSViv((IV)year)));
1435 3 PUSHs(sv_2mortal(newSViv((IV)month)));
1436 3 PUSHs(sv_2mortal(newSViv((IV)day)));
1437 }
1438 /* else return empty list */
1439 /* else DATECALC_DATE_ERROR; */
1440 }
1441  
1442  
1443 boolean
1444 DateCalc_check_compressed(date)
1445 Z_int date
1446  
1447  
1448 void
1449 DateCalc_Compressed_to_Text(...)
1450 PPCODE:
1451 {
1452 charptr string;
1453 Z_int date;
1454 Z_int lang;
1455  
1456 20 ▶ if ((items == 1) or (items == 2))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 1) or (items == 2)) 15 5 20
if ((items == 1) or (items == 2)) 15 0 15
1457 {
1458 20 ▶ if ( DATECALC_SCALAR(ST(0),Z_int,date) )
Branch: 2 branches
BranchTrueFalseTotal
if ( DATECALC_SCALAR(ST(0),Z_int,date) ) 20 0 20
if ( DATECALC_SCALAR(ST(0),Z_int,date) ) 20 0 20
1459 {
1460 20 ▶ if (items == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 2) 15 5 20
1461 {
1462 15 ▶ if ( not DATECALC_SCALAR(ST(1),Z_int,lang) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 15 0 15
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 15 0 15
1463 0 DATECALC_SCALAR_ERROR;
1464 }
1465 5 else lang = 0;
1466 20 string = DateCalc_Compressed_to_Text(date,lang);
1467 20 ▶ if (string != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (string != NULL) 20 0 20
1468 {
1469 20 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 20 20
1470 20 PUSHs(sv_2mortal(newSVpv((char *)string,0)));
1471 20 DateCalc_Dispose(string);
1472 }
1473 0 else DATECALC_MEMORY_ERROR;
1474 }
1475 0 else DATECALC_SCALAR_ERROR;
1476 }
1477 0 else croak("Usage: Date::Calc::Compressed_to_Text(date[,lang])");
1478 }
1479  
1480  
1481 void
1482 DateCalc_Date_to_Text(...)
1483 PPCODE:
1484 {
1485 charptr string;
1486 Z_int year;
1487 Z_int month;
1488 Z_int day;
1489 Z_int lang;
1490  
1491 9 ▶ if ((items == 3) or (items == 4))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 3) or (items == 4)) 7 2 9
if ((items == 3) or (items == 4)) 7 0 7
1492 {
1493 9 ▶ if ( DATECALC_SCALAR(ST(0),Z_int,year) and
Branch: 2 branches
BranchTrueFalseTotal
if ( DATECALC_SCALAR(ST(0),Z_int,year) and 9 0 9
if ( DATECALC_SCALAR(ST(0),Z_int,year) and 9 0 9
1494 9 ▶ DATECALC_SCALAR(ST(1),Z_int,month) and
Branch: 2 branches
BranchTrueFalseTotal
DATECALC_SCALAR(ST(1),Z_int,month) and 9 0 9
DATECALC_SCALAR(ST(1),Z_int,month) and 9 0 9
1495 9 ▶ DATECALC_SCALAR(ST(2),Z_int,day) )
Branch: 2 branches
BranchTrueFalseTotal
DATECALC_SCALAR(ST(2),Z_int,day) ) 9 0 9
DATECALC_SCALAR(ST(2),Z_int,day) ) 9 0 9
1496 {
1497 9 ▶ if (items == 4)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 4) 7 2 9
1498 {
1499 7 ▶ if ( not DATECALC_SCALAR(ST(3),Z_int,lang) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(3),Z_int,lang) ) 7 0 7
if ( not DATECALC_SCALAR(ST(3),Z_int,lang) ) 7 0 7
1500 0 DATECALC_SCALAR_ERROR;
1501 }
1502 2 else lang = 0;
1503 18 ▶ if (DateCalc_check_date(year,month,day))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_check_date(year,month,day)) 9 0 9
1504 {
1505 9 string = DateCalc_Date_to_Text(year,month,day,lang);
1506 9 ▶ if (string != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (string != NULL) 9 0 9
1507 {
1508 9 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 9 9
1509 9 PUSHs(sv_2mortal(newSVpv((char *)string,0)));
1510 9 DateCalc_Dispose(string);
1511 }
1512 0 else DATECALC_MEMORY_ERROR;
1513 }
1514 0 else DATECALC_DATE_ERROR;
1515 }
1516 0 else DATECALC_SCALAR_ERROR;
1517 }
1518 0 else croak("Usage: Date::Calc::Date_to_Text(year,month,day[,lang])");
1519 }
1520  
1521  
1522 void
1523 DateCalc_Date_to_Text_Long(...)
1524 PPCODE:
1525 {
1526 charptr string;
1527 Z_int year;
1528 Z_int month;
1529 Z_int day;
1530 Z_int lang;
1531  
1532 55 ▶ if ((items == 3) or (items == 4))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 3) or (items == 4)) 40 15 55
if ((items == 3) or (items == 4)) 40 0 40
1533 {
1534 55 ▶ if ( DATECALC_SCALAR(ST(0),Z_int,year) and
Branch: 2 branches
BranchTrueFalseTotal
if ( DATECALC_SCALAR(ST(0),Z_int,year) and 55 0 55
if ( DATECALC_SCALAR(ST(0),Z_int,year) and 55 0 55
1535 55 ▶ DATECALC_SCALAR(ST(1),Z_int,month) and
Branch: 2 branches
BranchTrueFalseTotal
DATECALC_SCALAR(ST(1),Z_int,month) and 55 0 55
DATECALC_SCALAR(ST(1),Z_int,month) and 55 0 55
1536 55 ▶ DATECALC_SCALAR(ST(2),Z_int,day) )
Branch: 2 branches
BranchTrueFalseTotal
DATECALC_SCALAR(ST(2),Z_int,day) ) 55 0 55
DATECALC_SCALAR(ST(2),Z_int,day) ) 55 0 55
1537 {
1538 55 ▶ if (items == 4)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 4) 40 15 55
1539 {
1540 40 ▶ if ( not DATECALC_SCALAR(ST(3),Z_int,lang) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(3),Z_int,lang) ) 40 0 40
if ( not DATECALC_SCALAR(ST(3),Z_int,lang) ) 40 0 40
1541 0 DATECALC_SCALAR_ERROR;
1542 }
1543 15 else lang = 0;
1544 110 ▶ if (DateCalc_check_date(year,month,day))
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_check_date(year,month,day)) 55 0 55
1545 {
1546 55 string = DateCalc_Date_to_Text_Long(year,month,day,lang);
1547 55 ▶ if (string != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (string != NULL) 55 0 55
1548 {
1549 55 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 55 55
1550 55 PUSHs(sv_2mortal(newSVpv((char *)string,0)));
1551 55 DateCalc_Dispose(string);
1552 }
1553 0 else DATECALC_MEMORY_ERROR;
1554 }
1555 0 else DATECALC_DATE_ERROR;
1556 }
1557 0 else DATECALC_SCALAR_ERROR;
1558 }
1559 0 else croak("Usage: Date::Calc::Date_to_Text_Long(year,month,day[,lang])");
1560 }
1561  
1562  
1563 void
1564 DateCalc_English_Ordinal(number)
1565 Z_int number
1566 PPCODE:
1567 {
1568 blockdef(string,64);
1569  
1570 0 DateCalc_English_Ordinal(string,number);
1571 0 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 0 0
1572 0 PUSHs(sv_2mortal(newSVpv((char *)string,0)));
1573 }
1574  
1575  
1576 void
1577 DateCalc_Calendar(...)
1578 PPCODE:
1579 {
1580 charptr string;
1581 Z_int year;
1582 Z_int month;
1583 boolean orthodox;
1584 Z_int lang;
1585  
1586 24 ▶ if ((items >= 2) and (items <= 4))
Branch: 2 branches
BranchTrueFalseTotal
if ((items >= 2) and (items <= 4)) 24 0 24
if ((items >= 2) and (items <= 4)) 24 0 24
1587 {
1588 24 ▶ if ( DATECALC_SCALAR(ST(0),Z_int,year) and
Branch: 2 branches
BranchTrueFalseTotal
if ( DATECALC_SCALAR(ST(0),Z_int,year) and 24 0 24
if ( DATECALC_SCALAR(ST(0),Z_int,year) and 24 0 24
1589 24 ▶ DATECALC_SCALAR(ST(1),Z_int,month) )
Branch: 2 branches
BranchTrueFalseTotal
DATECALC_SCALAR(ST(1),Z_int,month) ) 24 0 24
DATECALC_SCALAR(ST(1),Z_int,month) ) 24 0 24
1590 {
1591 24 ▶ if (items > 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 2) 24 0 24
1592 {
1593 24 ▶ if ( not DATECALC_SCALAR(ST(2),boolean,orthodox) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(2),boolean,orthodox) ) 24 0 24
if ( not DATECALC_SCALAR(ST(2),boolean,orthodox) ) 24 0 24
1594 0 DATECALC_SCALAR_ERROR;
1595 24 ▶ if (items > 3)
Branch: 1 branch
BranchTrueFalseTotal
if (items > 3) 0 24 24
1596 {
1597 0 ▶ if ( not DATECALC_SCALAR(ST(3),Z_int,lang) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(3),Z_int,lang) ) 0 0 0
if ( not DATECALC_SCALAR(ST(3),Z_int,lang) ) 0 0 0
1598 0 DATECALC_SCALAR_ERROR;
1599 }
1600 24 else { lang = 0; }
1601 }
1602 0 else { orthodox = false; lang = 0; }
1603 24 ▶ if (year > 0)
Branch: 1 branch
BranchTrueFalseTotal
if (year > 0) 24 0 24
1604 {
1605 24 ▶ if ((month >= 1) and (month <= 12))
Branch: 2 branches
BranchTrueFalseTotal
if ((month >= 1) and (month <= 12)) 24 0 24
if ((month >= 1) and (month <= 12)) 24 0 24
1606 {
1607 24 string = DateCalc_Calendar(year,month,orthodox,lang);
1608 24 ▶ if (string != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (string != NULL) 24 0 24
1609 {
1610 24 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 24 24
1611 24 PUSHs(sv_2mortal(newSVpv((char *)string,0)));
1612 24 DateCalc_Dispose(string);
1613 }
1614 0 else DATECALC_MEMORY_ERROR;
1615 }
1616 0 else DATECALC_MONTH_ERROR;
1617 }
1618 0 else DATECALC_YEAR_ERROR;
1619 }
1620 0 else DATECALC_SCALAR_ERROR;
1621 }
1622 0 else croak("Usage: Date::Calc::Calendar(year,month[,orthodox[,lang]])");
1623 }
1624  
1625  
1626 void
1627 DateCalc_Month_to_Text(...)
1628 PPCODE:
1629 {
1630 Z_int month;
1631 134 Z_int lang = 0;
1632  
1633 134 ▶ if ((items == 1) or (items == 2))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 1) or (items == 2)) 109 25 134
if ((items == 1) or (items == 2)) 109 0 109
1634 {
1635 134 ▶ if ( DATECALC_SCALAR(ST(0),Z_int,month) )
Branch: 2 branches
BranchTrueFalseTotal
if ( DATECALC_SCALAR(ST(0),Z_int,month) ) 134 0 134
if ( DATECALC_SCALAR(ST(0),Z_int,month) ) 134 0 134
1636 {
1637 134 ▶ if (items == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 2) 109 25 134
1638 {
1639 109 ▶ if ( not DATECALC_SCALAR(ST(1),Z_int,lang) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 109 0 109
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 109 0 109
1640 0 DATECALC_SCALAR_ERROR;
1641 }
1642 134 ▶ if ((lang < 1) or (lang > DateCalc_LANGUAGES)) lang = DateCalc_Language;
Branch: 2 branches
BranchTrueFalseTotal
if ((lang < 1) or (lang > DateCalc_LANGUAGES)) lang = DateCalc_Language; 96 38 134
if ((lang < 1) or (lang > DateCalc_LANGUAGES)) lang = DateCalc_Language; 0 96 96
1643 134 ▶ if ((month >= 1) and (month <= 12))
Branch: 2 branches
BranchTrueFalseTotal
if ((month >= 1) and (month <= 12)) 133 1 134
if ((month >= 1) and (month <= 12)) 119 14 133
1644 {
1645 119 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 119 119
1646 119 PUSHs(sv_2mortal(newSVpv((char *)DateCalc_Month_to_Text_[lang][month],0)));
1647 }
1648 15 else DATECALC_MONTH_ERROR;
1649 }
1650 0 else DATECALC_SCALAR_ERROR;
1651 }
1652 0 else croak("Usage: Date::Calc::Month_to_Text(month[,lang])");
1653 }
1654  
1655  
1656 void
1657 DateCalc_Day_of_Week_to_Text(...)
1658 PPCODE:
1659 {
1660 Z_int dow;
1661 48 Z_int lang = 0;
1662  
1663 48 ▶ if ((items == 1) or (items == 2))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 1) or (items == 2)) 23 25 48
if ((items == 1) or (items == 2)) 23 0 23
1664 {
1665 48 ▶ if ( DATECALC_SCALAR(ST(0),Z_int,dow) )
Branch: 2 branches
BranchTrueFalseTotal
if ( DATECALC_SCALAR(ST(0),Z_int,dow) ) 48 0 48
if ( DATECALC_SCALAR(ST(0),Z_int,dow) ) 48 0 48
1666 {
1667 48 ▶ if (items == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 2) 23 25 48
1668 {
1669 23 ▶ if ( not DATECALC_SCALAR(ST(1),Z_int,lang) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 23 0 23
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 23 0 23
1670 0 DATECALC_SCALAR_ERROR;
1671 }
1672 48 ▶ if ((lang < 1) or (lang > DateCalc_LANGUAGES)) lang = DateCalc_Language;
Branch: 2 branches
BranchTrueFalseTotal
if ((lang < 1) or (lang > DateCalc_LANGUAGES)) lang = DateCalc_Language; 15 33 48
if ((lang < 1) or (lang > DateCalc_LANGUAGES)) lang = DateCalc_Language; 0 15 15
1673 48 ▶ if ((dow >= 1) and (dow <= 7))
Branch: 2 branches
BranchTrueFalseTotal
if ((dow >= 1) and (dow <= 7)) 47 1 48
if ((dow >= 1) and (dow <= 7)) 38 9 47
1674 {
1675 38 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 38 38
1676 38 PUSHs(sv_2mortal(newSVpv((char *)DateCalc_Day_of_Week_to_Text_[lang][dow],0)));
1677 }
1678 10 else DATECALC_DAYOFWEEK_ERROR;
1679 }
1680 0 else DATECALC_SCALAR_ERROR;
1681 }
1682 0 else croak("Usage: Date::Calc::Day_of_Week_to_Text(dow[,lang])");
1683 }
1684  
1685  
1686 void
1687 DateCalc_Day_of_Week_Abbreviation(...)
1688 PPCODE:
1689 {
1690 blockdef(buffer,4);
1691 Z_int dow;
1692 0 Z_int lang = 0;
1693  
1694 0 ▶ if ((items == 1) or (items == 2))
Branch: 2 branches
BranchTrueFalseTotal
if ((items == 1) or (items == 2)) 0 0 0
if ((items == 1) or (items == 2)) 0 0 0
1695 {
1696 0 ▶ if ( DATECALC_SCALAR(ST(0),Z_int,dow) )
Branch: 2 branches
BranchTrueFalseTotal
if ( DATECALC_SCALAR(ST(0),Z_int,dow) ) 0 0 0
if ( DATECALC_SCALAR(ST(0),Z_int,dow) ) 0 0 0
1697 {
1698 0 ▶ if (items == 2)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 2) 0 0 0
1699 {
1700 0 ▶ if ( not DATECALC_SCALAR(ST(1),Z_int,lang) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 0 0 0
if ( not DATECALC_SCALAR(ST(1),Z_int,lang) ) 0 0 0
1701 0 DATECALC_SCALAR_ERROR;
1702 }
1703 0 ▶ if ((lang < 1) or (lang > DateCalc_LANGUAGES)) lang = DateCalc_Language;
Branch: 2 branches
BranchTrueFalseTotal
if ((lang < 1) or (lang > DateCalc_LANGUAGES)) lang = DateCalc_Language; 0 0 0
if ((lang < 1) or (lang > DateCalc_LANGUAGES)) lang = DateCalc_Language; 0 0 0
1704 0 ▶ if ((dow >= 1) and (dow <= 7))
Branch: 2 branches
BranchTrueFalseTotal
if ((dow >= 1) and (dow <= 7)) 0 0 0
if ((dow >= 1) and (dow <= 7)) 0 0 0
1705 {
1706 0 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 0 0
1707 0 ▶ if (DateCalc_Day_of_Week_Abbreviation_[lang][0][0] != '\0')
Branch: 1 branch
BranchTrueFalseTotal
if (DateCalc_Day_of_Week_Abbreviation_[lang][0][0] != '\0') 0 0 0
1708 {
1709 0 PUSHs(sv_2mortal(newSVpv((char *)DateCalc_Day_of_Week_Abbreviation_[lang][dow],0)));
1710 }
1711 else
1712 {
1713 0 strncpy((char *)buffer,(char *)DateCalc_Day_of_Week_to_Text_[lang][dow],3);
1714 0 buffer[3] = '\0';
1715 0 PUSHs(sv_2mortal(newSVpv((char *)buffer,0)));
1716 }
1717 }
1718 0 else DATECALC_DAYOFWEEK_ERROR;
1719 }
1720 0 else DATECALC_SCALAR_ERROR;
1721 }
1722 0 else croak("Usage: Date::Calc::Day_of_Week_Abbreviation(dow[,lang])");
1723 }
1724  
1725  
1726 void
1727 DateCalc_Language_to_Text(lang)
1728 Z_int lang
1729 PPCODE:
1730 {
1731 20 ▶ if ((lang >= 1) and (lang <= DateCalc_LANGUAGES))
Branch: 2 branches
BranchTrueFalseTotal
if ((lang >= 1) and (lang <= DateCalc_LANGUAGES)) 19 1 20
if ((lang >= 1) and (lang <= DateCalc_LANGUAGES)) 19 0 19
1732 {
1733 19 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 19 19
1734 19 PUSHs(sv_2mortal(newSVpv((char *)DateCalc_Language_to_Text_[lang],0)));
1735 }
1736 1 else DATECALC_LANGUAGE_ERROR;
1737 }
1738  
1739  
1740 Z_int
1741 DateCalc_Language(...)
1742 CODE:
1743 {
1744 Z_int lang;
1745  
1746 425 ▶ if ((items >= 0) and (items <= 1))
Branch: 2 branches
BranchTrueFalseTotal
if ((items >= 0) and (items <= 1)) 425 0 425
if ((items >= 0) and (items <= 1)) 425 0 425
1747 {
1748 425 RETVAL = DateCalc_Language;
1749 425 ▶ if (items == 1)
Branch: 1 branch
BranchTrueFalseTotal
if (items == 1) 6 419 425
1750 {
1751 6 ▶ if ( not DATECALC_SCALAR(ST(0),Z_int,lang) )
Branch: 2 branches
BranchTrueFalseTotal
if ( not DATECALC_SCALAR(ST(0),Z_int,lang) ) 6 0 6
if ( not DATECALC_SCALAR(ST(0),Z_int,lang) ) 6 0 6
1752 0 DATECALC_SCALAR_ERROR;
1753 6 ▶ if ((lang >= 1) and (lang <= DateCalc_LANGUAGES))
Branch: 2 branches
BranchTrueFalseTotal
if ((lang >= 1) and (lang <= DateCalc_LANGUAGES)) 6 0 6
if ((lang >= 1) and (lang <= DateCalc_LANGUAGES)) 6 0 6
1754 {
1755 6 DateCalc_Language = lang;
1756 }
1757 0 else DATECALC_LANGUAGE_ERROR;
1758 }
1759 }
1760 0 else croak("Usage: Date::Calc::Language([lang])");
1761 }
1762 OUTPUT:
1763 RETVAL
1764  
1765  
1766 Z_int
1767 DateCalc_Languages()
1768 CODE:
1769 {
1770 169 ▶ RETVAL = DateCalc_LANGUAGES;
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = DateCalc_LANGUAGES; 152 17 169
1771 }
1772 OUTPUT:
1773 RETVAL
1774  
1775  
1776 void
1777 DateCalc_ISO_LC(scalar)
1778 SV * scalar
1779 PPCODE:
1780 {
1781 charptr string;
1782 charptr buffer;
1783 N_int length;
1784 N_int index;
1785  
1786 0 ▶ if ( DATECALC_STRING(scalar,string,length) )
Branch: 4 branches
BranchTrueFalseTotal
if ( DATECALC_STRING(scalar,string,length) ) 0 0 0
if ( DATECALC_STRING(scalar,string,length) ) 0 0 0
if ( DATECALC_STRING(scalar,string,length) ) 0 0 0
if ( DATECALC_STRING(scalar,string,length) ) 0 0 0
1787 {
1788 0 buffer = (charptr) malloc(length+1);
1789 0 ▶ if (buffer != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (buffer != NULL) 0 0 0
1790 {
1791 0 ▶ for ( index = 0; index < length; index++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( index = 0; index < length; index++ ) 0 0 0
1792 0 buffer[index] = DateCalc_ISO_LC(string[index]);
1793 0 buffer[length] = '\0';
1794 0 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 0 0
1795 0 PUSHs(sv_2mortal(newSVpv((char *)buffer,length)));
1796 0 free(buffer);
1797 }
1798 0 else DATECALC_MEMORY_ERROR;
1799 }
1800 0 else DATECALC_STRING_ERROR;
1801 }
1802  
1803  
1804 void
1805 DateCalc_ISO_UC(scalar)
1806 SV * scalar
1807 PPCODE:
1808 {
1809 charptr string;
1810 charptr buffer;
1811 N_int length;
1812 N_int index;
1813  
1814 504 ▶ if ( DATECALC_STRING(scalar,string,length) )
Branch: 4 branches
BranchTrueFalseTotal
if ( DATECALC_STRING(scalar,string,length) ) 252 0 252
if ( DATECALC_STRING(scalar,string,length) ) 252 0 252
if ( DATECALC_STRING(scalar,string,length) ) 252 0 252
if ( DATECALC_STRING(scalar,string,length) ) 252 0 252
1815 {
1816 252 buffer = (charptr) malloc(length+1);
1817 252 ▶ if (buffer != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (buffer != NULL) 252 0 252
1818 {
1819 3505 ▶ for ( index = 0; index < length; index++ )
Branch: 1 branch
BranchTrueFalseTotal
for ( index = 0; index < length; index++ ) 3253 252 3505
1820 3253 buffer[index] = DateCalc_ISO_UC(string[index]);
1821 252 buffer[length] = '\0';
1822 252 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 252 252
1823 252 PUSHs(sv_2mortal(newSVpv((char *)buffer,length)));
1824 252 free(buffer);
1825 }
1826 0 else DATECALC_MEMORY_ERROR;
1827 }
1828 0 else DATECALC_STRING_ERROR;
1829 }
1830  
1831  
1832 void
1833 DateCalc_Version()
1834 PPCODE:
1835 {
1836 charptr string;
1837  
1838 1 string = DateCalc_Version();
1839 1 ▶ if (string != NULL)
Branch: 1 branch
BranchTrueFalseTotal
if (string != NULL) 1 0 1
1840 {
1841 1 ▶ EXTEND(sp,1);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(sp,1); 0 1 1
1842 1 PUSHs(sv_2mortal(newSVpv((char *)string,0)));
1843 }
1844 0 else DATECALC_MEMORY_ERROR;
1845 }
1846  
1847  
« blib/lib/Date/Calc/XS.pm ↑ Summary DateCalc.c »