| 1 |
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 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 |
|
|---|
| 22 |
#ifndef PL_na |
|---|
| 23 |
#define PL_na na |
|---|
| 24 |
#endif |
|---|
| 25 |
#endif |
|---|
| 26 |
#if (PATCHLEVEL < 4) |
|---|
| 27 |
|
|---|
| 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 |
|
|---|
| 51 |
|
|---|
| 52 |
#define DATECALC_STRING(ref,var,len) \ |
|---|
| 53 |
( ref && !(SvROK(ref)) && SvPOK(ref) && \ |
|---|
| 54 |
(var = (charptr)SvPV(ref,PL_na)) && \ |
|---|
| 55 |
((len = (N_int)SvCUR(ref)) | 1) ) |
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 |
#define DATECALC_ERROR(message) \ |
|---|
| 59 |
croak("Date::Calc::%s(): %s", GvNAME(CvGV(cv)), message) |
|---|
| 60 |
|
|---|
| 61 |
|
|---|
| 62 |
#define DATECALC_DATE_ERROR \ |
|---|
| 63 |
DATECALC_ERROR( _DateCalc_DATE_ERROR ) |
|---|
| 64 |
|
|---|
| 65 |
#define DATECALC_TIME_ERROR \ |
|---|
| 66 |
DATECALC_ERROR( _DateCalc_TIME_ERROR ) |
|---|
| 67 |
|
|---|
| 68 |
#define DATECALC_YEAR_ERROR \ |
|---|
| 69 |
DATECALC_ERROR( _DateCalc_YEAR_ERROR ) |
|---|
| 70 |
|
|---|
| 71 |
#define DATECALC_MONTH_ERROR \ |
|---|
| 72 |
DATECALC_ERROR( _DateCalc_MONTH_ERROR ) |
|---|
| 73 |
|
|---|
| 74 |
#define DATECALC_WEEK_ERROR \ |
|---|
| 75 |
DATECALC_ERROR( _DateCalc_WEEK_ERROR ) |
|---|
| 76 |
|
|---|
| 77 |
#define DATECALC_DAYOFWEEK_ERROR \ |
|---|
| 78 |
DATECALC_ERROR( _DateCalc_DAYOFWEEK_ERROR ) |
|---|
| 79 |
|
|---|
| 80 |
#define DATECALC_DATE_RANGE_ERROR \ |
|---|
| 81 |
DATECALC_ERROR( _DateCalc_DATE_RANGE_ERROR ) |
|---|
| 82 |
|
|---|
| 83 |
#define DATECALC_TIME_RANGE_ERROR \ |
|---|
| 84 |
DATECALC_ERROR( _DateCalc_TIME_RANGE_ERROR ) |
|---|
| 85 |
|
|---|
| 86 |
#define DATECALC_FACTOR_ERROR \ |
|---|
| 87 |
DATECALC_ERROR( _DateCalc_FACTOR_ERROR ) |
|---|
| 88 |
|
|---|
| 89 |
#define DATECALC_LANGUAGE_ERROR \ |
|---|
| 90 |
DATECALC_ERROR( _DateCalc_LANGUAGE_ERROR ) |
|---|
| 91 |
|
|---|
| 92 |
#define DATECALC_SYSTEM_ERROR \ |
|---|
| 93 |
DATECALC_ERROR( _DateCalc_SYSTEM_ERROR ) |
|---|
| 94 |
|
|---|
| 95 |
#define DATECALC_MEMORY_ERROR \ |
|---|
| 96 |
DATECALC_ERROR( _DateCalc_MEMORY_ERROR ) |
|---|
| 97 |
|
|---|
| 98 |
#define DATECALC_STRING_ERROR \ |
|---|
| 99 |
DATECALC_ERROR( _DateCalc_STRING_ERROR ) |
|---|
| 100 |
|
|---|
| 101 |
|
|---|
| 102 |
MODULE = Date::Calc PACKAGE = Date::Calc PREFIX = DateCalc_ |
|---|
| 103 |
|
|---|
| 104 |
|
|---|
| 105 |
PROTOTYPES: DISABLE |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
void |
|---|
| 109 |
DateCalc_Days_in_Year(year,month) |
|---|
| 110 |
Z_int year |
|---|
| 111 |
Z_int month |
|---|
| 112 |
PPCODE: |
|---|
| 113 |
{ |
|---|
| 114 |
if (year > 0) |
|---|
| 115 |
{ |
|---|
| 116 |
if ((month >= 1) and (month <= 12)) |
|---|
| 117 |
{ |
|---|
| 118 |
EXTEND(sp,1); |
|---|
| 119 |
PUSHs(sv_2mortal(newSViv((IV)DateCalc_Days_in_Year_[DateCalc_leap_year(year)][month+1]))); |
|---|
| 120 |
} |
|---|
| 121 |
else DATECALC_MONTH_ERROR; |
|---|
| 122 |
} |
|---|
| 123 |
else DATECALC_YEAR_ERROR; |
|---|
| 124 |
} |
|---|
| 125 |
|
|---|
| 126 |
|
|---|
| 127 |
void |
|---|
| 128 |
DateCalc_Days_in_Month(year,month) |
|---|
| 129 |
Z_int year |
|---|
| 130 |
Z_int month |
|---|
| 131 |
PPCODE: |
|---|
| 132 |
{ |
|---|
| 133 |
if (year > 0) |
|---|
| 134 |
{ |
|---|
| 135 |
if ((month >= 1) and (month <= 12)) |
|---|
| 136 |
{ |
|---|
| 137 |
EXTEND(sp,1); |
|---|
| 138 |
PUSHs(sv_2mortal(newSViv((IV)DateCalc_Days_in_Month_[DateCalc_leap_year(year)][month]))); |
|---|
| 139 |
} |
|---|
| 140 |
else DATECALC_MONTH_ERROR; |
|---|
| 141 |
} |
|---|
| 142 |
else DATECALC_YEAR_ERROR; |
|---|
| 143 |
} |
|---|
| 144 |
|
|---|
| 145 |
|
|---|
| 146 |
Z_int |
|---|
| 147 |
DateCalc_Weeks_in_Year(year) |
|---|
| 148 |
Z_int year |
|---|
| 149 |
CODE: |
|---|
| 150 |
{ |
|---|
| 151 |
if (year > 0) |
|---|
| 152 |
{ |
|---|
| 153 |
RETVAL = DateCalc_Weeks_in_Year(year); |
|---|
| 154 |
} |
|---|
| 155 |
else DATECALC_YEAR_ERROR; |
|---|
| 156 |
} |
|---|
| 157 |
OUTPUT: |
|---|
| 158 |
RETVAL |
|---|
| 159 |
|
|---|
| 160 |
|
|---|
| 161 |
boolean |
|---|
| 162 |
DateCalc_leap_year(year) |
|---|
| 163 |
Z_int year |
|---|
| 164 |
CODE: |
|---|
| 165 |
{ |
|---|
| 166 |
if (year > 0) |
|---|
| 167 |
{ |
|---|
| 168 |
RETVAL = DateCalc_leap_year(year); |
|---|
| 169 |
} |
|---|
| 170 |
else DATECALC_YEAR_ERROR; |
|---|
| 171 |
} |
|---|
| 172 |
OUTPUT: |
|---|
| 173 |
RETVAL |
|---|
| 174 |
|
|---|
| 175 |
|
|---|
| 176 |
boolean |
|---|
| 177 |
DateCalc_check_date(year,month,day) |
|---|
| 178 |
Z_int year |
|---|
| 179 |
Z_int month |
|---|
| 180 |
Z_int day |
|---|
| 181 |
|
|---|
| 182 |
|
|---|
| 183 |
boolean |
|---|
| 184 |
DateCalc_check_time(hour,min,sec) |
|---|
| 185 |
Z_int hour |
|---|
| 186 |
Z_int min |
|---|
| 187 |
Z_int sec |
|---|
| 188 |
|
|---|
| 189 |
|
|---|
| 190 |
boolean |
|---|
| 191 |
DateCalc_check_business_date(year,week,dow) |
|---|
| 192 |
Z_int year |
|---|
| 193 |
Z_int week |
|---|
| 194 |
Z_int dow |
|---|
| 195 |
|
|---|
| 196 |
|
|---|
| 197 |
Z_int |
|---|
| 198 |
DateCalc_Day_of_Year(year,month,day) |
|---|
| 199 |
Z_int year |
|---|
| 200 |
Z_int month |
|---|
| 201 |
Z_int day |
|---|
| 202 |
CODE: |
|---|
| 203 |
{ |
|---|
| 204 |
RETVAL = DateCalc_Day_of_Year(year,month,day); |
|---|
| 205 |
if (RETVAL == 0) DATECALC_DATE_ERROR; |
|---|
| 206 |
} |
|---|
| 207 |
OUTPUT: |
|---|
| 208 |
RETVAL |
|---|
| 209 |
|
|---|
| 210 |
|
|---|
| 211 |
Z_long |
|---|
| 212 |
DateCalc_Date_to_Days(year,month,day) |
|---|
| 213 |
Z_int year |
|---|
| 214 |
Z_int month |
|---|
| 215 |
Z_int day |
|---|
| 216 |
CODE: |
|---|
| 217 |
{ |
|---|
| 218 |
RETVAL = DateCalc_Date_to_Days(year,month,day); |
|---|
| 219 |
if (RETVAL == 0) DATECALC_DATE_ERROR; |
|---|
| 220 |
} |
|---|
| 221 |
OUTPUT: |
|---|
| 222 |
RETVAL |
|---|
| 223 |
|
|---|
| 224 |
|
|---|
| 225 |
Z_int |
|---|
| 226 |
DateCalc_Day_of_Week(year,month,day) |
|---|
| 227 |
Z_int year |
|---|
| 228 |
Z_int month |
|---|
| 229 |
Z_int day |
|---|
| 230 |
CODE: |
|---|
| 231 |
{ |
|---|
| 232 |
RETVAL = DateCalc_Day_of_Week(year,month,day); |
|---|
| 233 |
if (RETVAL == 0) DATECALC_DATE_ERROR; |
|---|
| 234 |
} |
|---|
| 235 |
OUTPUT: |
|---|
| 236 |
RETVAL |
|---|
| 237 |
|
|---|
| 238 |
|
|---|
| 239 |
Z_int |
|---|
| 240 |
DateCalc_Week_Number(year,month,day) |
|---|
| 241 |
Z_int year |
|---|
| 242 |
Z_int month |
|---|
| 243 |
Z_int day |
|---|
| 244 |
CODE: |
|---|
| 245 |
{ |
|---|
| 246 |
if (DateCalc_check_date(year,month,day)) |
|---|
| 247 |
{ |
|---|
| 248 |
RETVAL = DateCalc_Week_Number(year,month,day); |
|---|
| 249 |
} |
|---|
| 250 |
else DATECALC_DATE_ERROR; |
|---|
| 251 |
} |
|---|
| 252 |
OUTPUT: |
|---|
| 253 |
RETVAL |
|---|
| 254 |
|
|---|
| 255 |
|
|---|
| 256 |
void |
|---|
| 257 |
DateCalc_Week_of_Year(year,month,day) |
|---|
| 258 |
Z_int year |
|---|
| 259 |
Z_int month |
|---|
| 260 |
Z_int day |
|---|
| 261 |
PPCODE: |
|---|
| 262 |
{ |
|---|
| 263 |
Z_int week; |
|---|
| 264 |
|
|---|
| 265 |
if (DateCalc_week_of_year(&week,&year,month,day)) |
|---|
| 266 |
{ |
|---|
| 267 |
if (GIMME_V == G_ARRAY) |
|---|
| 268 |
{ |
|---|
| 269 |
EXTEND(sp,2); |
|---|
| 270 |
PUSHs(sv_2mortal(newSViv((IV)week))); |
|---|
| 271 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 272 |
} |
|---|
| 273 |
else |
|---|
| 274 |
{ |
|---|
| 275 |
EXTEND(sp,1); |
|---|
| 276 |
PUSHs(sv_2mortal(newSViv((IV)week))); |
|---|
| 277 |
} |
|---|
| 278 |
} |
|---|
| 279 |
else DATECALC_DATE_ERROR; |
|---|
| 280 |
} |
|---|
| 281 |
|
|---|
| 282 |
|
|---|
| 283 |
void |
|---|
| 284 |
DateCalc_Monday_of_Week(week,year) |
|---|
| 285 |
Z_int week |
|---|
| 286 |
Z_int year |
|---|
| 287 |
PPCODE: |
|---|
| 288 |
{ |
|---|
| 289 |
Z_int month; |
|---|
| 290 |
Z_int day; |
|---|
| 291 |
|
|---|
| 292 |
if (year > 0) |
|---|
| 293 |
{ |
|---|
| 294 |
if ((week > 0) and (week <= DateCalc_Weeks_in_Year(year))) |
|---|
| 295 |
{ |
|---|
| 296 |
if (DateCalc_monday_of_week(week,&year,&month,&day)) |
|---|
| 297 |
{ |
|---|
| 298 |
EXTEND(sp,3); |
|---|
| 299 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 300 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 301 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 302 |
} |
|---|
| 303 |
else DATECALC_DATE_ERROR; |
|---|
| 304 |
} |
|---|
| 305 |
else DATECALC_WEEK_ERROR; |
|---|
| 306 |
} |
|---|
| 307 |
else DATECALC_YEAR_ERROR; |
|---|
| 308 |
} |
|---|
| 309 |
|
|---|
| 310 |
|
|---|
| 311 |
void |
|---|
| 312 |
DateCalc_Nth_Weekday_of_Month_Year(year,month,dow,n) |
|---|
| 313 |
Z_int year |
|---|
| 314 |
Z_int month |
|---|
| 315 |
Z_int dow |
|---|
| 316 |
Z_int n |
|---|
| 317 |
PPCODE: |
|---|
| 318 |
{ |
|---|
| 319 |
Z_int day; |
|---|
| 320 |
|
|---|
| 321 |
if (year > 0) |
|---|
| 322 |
{ |
|---|
| 323 |
if ((month >= 1) and (month <= 12)) |
|---|
| 324 |
{ |
|---|
| 325 |
if ((dow >= 1) and (dow <= 7)) |
|---|
| 326 |
{ |
|---|
| 327 |
if ((n >= 1) and (n <= 5)) |
|---|
| 328 |
{ |
|---|
| 329 |
if (DateCalc_nth_weekday_of_month_year(&year,&month,&day,dow,n)) |
|---|
| 330 |
{ |
|---|
| 331 |
EXTEND(sp,3); |
|---|
| 332 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 333 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 334 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 335 |
} |
|---|
| 336 |
|
|---|
| 337 |
} |
|---|
| 338 |
else DATECALC_FACTOR_ERROR; |
|---|
| 339 |
} |
|---|
| 340 |
else DATECALC_DAYOFWEEK_ERROR; |
|---|
| 341 |
} |
|---|
| 342 |
else DATECALC_MONTH_ERROR; |
|---|
| 343 |
} |
|---|
| 344 |
else DATECALC_YEAR_ERROR; |
|---|
| 345 |
} |
|---|
| 346 |
|
|---|
| 347 |
|
|---|
| 348 |
void |
|---|
| 349 |
DateCalc_Standard_to_Business(year,month,day) |
|---|
| 350 |
Z_int year |
|---|
| 351 |
Z_int month |
|---|
| 352 |
Z_int day |
|---|
| 353 |
PPCODE: |
|---|
| 354 |
{ |
|---|
| 355 |
Z_int week; |
|---|
| 356 |
Z_int dow; |
|---|
| 357 |
|
|---|
| 358 |
if (DateCalc_standard_to_business(&year,&week,&dow,month,day)) |
|---|
| 359 |
{ |
|---|
| 360 |
EXTEND(sp,3); |
|---|
| 361 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 362 |
PUSHs(sv_2mortal(newSViv((IV)week))); |
|---|
| 363 |
PUSHs(sv_2mortal(newSViv((IV)dow))); |
|---|
| 364 |
} |
|---|
| 365 |
else DATECALC_DATE_ERROR; |
|---|
| 366 |
} |
|---|
| 367 |
|
|---|
| 368 |
|
|---|
| 369 |
void |
|---|
| 370 |
DateCalc_Business_to_Standard(year,week,dow) |
|---|
| 371 |
Z_int year |
|---|
| 372 |
Z_int week |
|---|
| 373 |
Z_int dow |
|---|
| 374 |
PPCODE: |
|---|
| 375 |
{ |
|---|
| 376 |
Z_int month; |
|---|
| 377 |
Z_int day; |
|---|
| 378 |
|
|---|
| 379 |
if (DateCalc_business_to_standard(&year,&month,&day,week,dow)) |
|---|
| 380 |
{ |
|---|
| 381 |
EXTEND(sp,3); |
|---|
| 382 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 383 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 384 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 385 |
} |
|---|
| 386 |
else DATECALC_DATE_ERROR; |
|---|
| 387 |
} |
|---|
| 388 |
|
|---|
| 389 |
|
|---|
| 390 |
Z_long |
|---|
| 391 |
DateCalc_Delta_Days(year1,month1,day1, year2,month2,day2) |
|---|
| 392 |
Z_int year1 |
|---|
| 393 |
Z_int month1 |
|---|
| 394 |
Z_int day1 |
|---|
| 395 |
Z_int year2 |
|---|
| 396 |
Z_int month2 |
|---|
| 397 |
Z_int day2 |
|---|
| 398 |
CODE: |
|---|
| 399 |
{ |
|---|
| 400 |
if (DateCalc_check_date(year1,month1,day1) and |
|---|
| 401 |
DateCalc_check_date(year2,month2,day2)) |
|---|
| 402 |
{ |
|---|
| 403 |
RETVAL = DateCalc_Delta_Days(year1,month1,day1, year2,month2,day2); |
|---|
| 404 |
} |
|---|
| 405 |
else DATECALC_DATE_ERROR; |
|---|
| 406 |
} |
|---|
| 407 |
OUTPUT: |
|---|
| 408 |
RETVAL |
|---|
| 409 |
|
|---|
| 410 |
|
|---|
| 411 |
void |
|---|
| 412 |
DateCalc_Delta_DHMS(year1,month1,day1, hour1,min1,sec1, year2,month2,day2, hour2,min2,sec2) |
|---|
| 413 |
Z_int year1 |
|---|
| 414 |
Z_int month1 |
|---|
| 415 |
Z_int day1 |
|---|
| 416 |
Z_int hour1 |
|---|
| 417 |
Z_int min1 |
|---|
| 418 |
Z_int sec1 |
|---|
| 419 |
Z_int year2 |
|---|
| 420 |
Z_int month2 |
|---|
| 421 |
Z_int day2 |
|---|
| 422 |
Z_int hour2 |
|---|
| 423 |
Z_int min2 |
|---|
| 424 |
Z_int sec2 |
|---|
| 425 |
PPCODE: |
|---|
| 426 |
{ |
|---|
| 427 |
Z_long Dd; |
|---|
| 428 |
Z_int Dh; |
|---|
| 429 |
Z_int Dm; |
|---|
| 430 |
Z_int Ds; |
|---|
| 431 |
|
|---|
| 432 |
if (DateCalc_check_date(year1,month1,day1) and |
|---|
| 433 |
DateCalc_check_date(year2,month2,day2)) |
|---|
| 434 |
{ |
|---|
| 435 |
if (DateCalc_check_time(hour1,min1,sec1) and |
|---|
| 436 |
DateCalc_check_time(hour2,min2,sec2)) |
|---|
| 437 |
{ |
|---|
| 438 |
if (DateCalc_delta_dhms(&Dd,&Dh,&Dm,&Ds, |
|---|
| 439 |
year1,month1,day1, hour1,min1,sec1, |
|---|
| 440 |
year2,month2,day2, hour2,min2,sec2)) |
|---|
| 441 |
{ |
|---|
| 442 |
EXTEND(sp,4); |
|---|
| 443 |
PUSHs(sv_2mortal(newSViv((IV)Dd))); |
|---|
| 444 |
PUSHs(sv_2mortal(newSViv((IV)Dh))); |
|---|
| 445 |
PUSHs(sv_2mortal(newSViv((IV)Dm))); |
|---|
| 446 |
PUSHs(sv_2mortal(newSViv((IV)Ds))); |
|---|
| 447 |
} |
|---|
| 448 |
else DATECALC_DATE_ERROR; |
|---|
| 449 |
} |
|---|
| 450 |
else DATECALC_TIME_ERROR; |
|---|
| 451 |
} |
|---|
| 452 |
else DATECALC_DATE_ERROR; |
|---|
| 453 |
} |
|---|
| 454 |
|
|---|
| 455 |
|
|---|
| 456 |
void |
|---|
| 457 |
DateCalc_Delta_YMD(year1,month1,day1, year2,month2,day2) |
|---|
| 458 |
Z_int year1 |
|---|
| 459 |
Z_int month1 |
|---|
| 460 |
Z_int day1 |
|---|
| 461 |
Z_int year2 |
|---|
| 462 |
Z_int month2 |
|---|
| 463 |
Z_int day2 |
|---|
| 464 |
PPCODE: |
|---|
| 465 |
{ |
|---|
| 466 |
if (DateCalc_delta_ymd(&year1,&month1,&day1, year2,month2,day2)) |
|---|
| 467 |
{ |
|---|
| 468 |
EXTEND(sp,3); |
|---|
| 469 |
PUSHs(sv_2mortal(newSViv((IV)year1))); |
|---|
| 470 |
PUSHs(sv_2mortal(newSViv((IV)month1))); |
|---|
| 471 |
PUSHs(sv_2mortal(newSViv((IV)day1))); |
|---|
| 472 |
} |
|---|
| 473 |
else DATECALC_DATE_ERROR; |
|---|
| 474 |
} |
|---|
| 475 |
|
|---|
| 476 |
|
|---|
| 477 |
void |
|---|
| 478 |
DateCalc_Delta_YMDHMS(year1,month1,day1, hour1,min1,sec1, year2,month2,day2, hour2,min2,sec2) |
|---|
| 479 |
Z_int year1 |
|---|
| 480 |
Z_int month1 |
|---|
| 481 |
Z_int day1 |
|---|
| 482 |
Z_int hour1 |
|---|
| 483 |
Z_int min1 |
|---|
| 484 |
Z_int sec1 |
|---|
| 485 |
Z_int year2 |
|---|
| 486 |
Z_int month2 |
|---|
| 487 |
Z_int day2 |
|---|
| 488 |
Z_int hour2 |
|---|
| 489 |
Z_int min2 |
|---|
| 490 |
Z_int sec2 |
|---|
| 491 |
PPCODE: |
|---|
| 492 |
{ |
|---|
| 493 |
Z_int D_y; |
|---|
| 494 |
Z_int D_m; |
|---|
| 495 |
Z_int D_d; |
|---|
| 496 |
Z_int Dh; |
|---|
| 497 |
Z_int Dm; |
|---|
| 498 |
Z_int Ds; |
|---|
| 499 |
|
|---|
| 500 |
if (DateCalc_check_date(year1,month1,day1) and |
|---|
| 501 |
DateCalc_check_date(year2,month2,day2)) |
|---|
| 502 |
{ |
|---|
| 503 |
if (DateCalc_check_time(hour1,min1,sec1) and |
|---|
| 504 |
DateCalc_check_time(hour2,min2,sec2)) |
|---|
| 505 |
{ |
|---|
| 506 |
if (DateCalc_delta_ymdhms(&D_y,&D_m,&D_d, &Dh,&Dm,&Ds, |
|---|
| 507 |
year1,month1,day1, hour1,min1,sec1, |
|---|
| 508 |
year2,month2,day2, hour2,min2,sec2)) |
|---|
| 509 |
{ |
|---|
| 510 |
EXTEND(sp,6); |
|---|
| 511 |
PUSHs(sv_2mortal(newSViv((IV)D_y))); |
|---|
| 512 |
PUSHs(sv_2mortal(newSViv((IV)D_m))); |
|---|
| 513 |
PUSHs(sv_2mortal(newSViv((IV)D_d))); |
|---|
| 514 |
PUSHs(sv_2mortal(newSViv((IV)Dh))); |
|---|
| 515 |
PUSHs(sv_2mortal(newSViv((IV)Dm))); |
|---|
| 516 |
PUSHs(sv_2mortal(newSViv((IV)Ds))); |
|---|
| 517 |
} |
|---|
| 518 |
else DATECALC_DATE_ERROR; |
|---|
| 519 |
} |
|---|
| 520 |
else DATECALC_TIME_ERROR; |
|---|
| 521 |
} |
|---|
| 522 |
else DATECALC_DATE_ERROR; |
|---|
| 523 |
} |
|---|
| 524 |
|
|---|
| 525 |
|
|---|
| 526 |
void |
|---|
| 527 |
DateCalc_Normalize_DHMS(Dd,Dh,Dm,Ds) |
|---|
| 528 |
Z_long Dd |
|---|
| 529 |
Z_long Dh |
|---|
| 530 |
Z_long Dm |
|---|
| 531 |
Z_long Ds |
|---|
| 532 |
PPCODE: |
|---|
| 533 |
{ |
|---|
| 534 |
DateCalc_Normalize_DHMS(&Dd,&Dh,&Dm,&Ds); |
|---|
| 535 |
EXTEND(sp,4); |
|---|
| 536 |
PUSHs(sv_2mortal(newSViv((IV)Dd))); |
|---|
| 537 |
PUSHs(sv_2mortal(newSViv((IV)Dh))); |
|---|
| 538 |
PUSHs(sv_2mortal(newSViv((IV)Dm))); |
|---|
| 539 |
PUSHs(sv_2mortal(newSViv((IV)Ds))); |
|---|
| 540 |
} |
|---|
| 541 |
|
|---|
| 542 |
|
|---|
| 543 |
void |
|---|
| 544 |
DateCalc_Add_Delta_Days(year,month,day, Dd) |
|---|
| 545 |
Z_int year |
|---|
| 546 |
Z_int month |
|---|
| 547 |
Z_int day |
|---|
| 548 |
Z_long Dd |
|---|
| 549 |
PPCODE: |
|---|
| 550 |
{ |
|---|
| 551 |
if (DateCalc_add_delta_days(&year,&month,&day, Dd)) |
|---|
| 552 |
{ |
|---|
| 553 |
EXTEND(sp,3); |
|---|
| 554 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 555 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 556 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 557 |
} |
|---|
| 558 |
else DATECALC_DATE_ERROR; |
|---|
| 559 |
} |
|---|
| 560 |
|
|---|
| 561 |
|
|---|
| 562 |
void |
|---|
| 563 |
DateCalc_Add_Delta_DHMS(year,month,day, hour,min,sec, Dd,Dh,Dm,Ds) |
|---|
| 564 |
Z_int year |
|---|
| 565 |
Z_int month |
|---|
| 566 |
Z_int day |
|---|
| 567 |
Z_int hour |
|---|
| 568 |
Z_int min |
|---|
| 569 |
Z_int sec |
|---|
| 570 |
Z_long Dd |
|---|
| 571 |
Z_long Dh |
|---|
| 572 |
Z_long Dm |
|---|
| 573 |
Z_long Ds |
|---|
| 574 |
PPCODE: |
|---|
| 575 |
{ |
|---|
| 576 |
if (DateCalc_check_date(year,month,day)) |
|---|
| 577 |
{ |
|---|
| 578 |
if (DateCalc_check_time(hour,min,sec)) |
|---|
| 579 |
{ |
|---|
| 580 |
if (DateCalc_add_delta_dhms(&year,&month,&day, |
|---|
| 581 |
&hour,&min,&sec, |
|---|
| 582 |
Dd,Dh,Dm,Ds)) |
|---|
| 583 |
{ |
|---|
| 584 |
EXTEND(sp,6); |
|---|
| 585 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 586 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 587 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 588 |
PUSHs(sv_2mortal(newSViv((IV)hour))); |
|---|
| 589 |
PUSHs(sv_2mortal(newSViv((IV)min))); |
|---|
| 590 |
PUSHs(sv_2mortal(newSViv((IV)sec))); |
|---|
| 591 |
} |
|---|
| 592 |
else DATECALC_DATE_ERROR; |
|---|
| 593 |
} |
|---|
| 594 |
else DATECALC_TIME_ERROR; |
|---|
| 595 |
} |
|---|
| 596 |
else DATECALC_DATE_ERROR; |
|---|
| 597 |
} |
|---|
| 598 |
|
|---|
| 599 |
|
|---|
| 600 |
void |
|---|
| 601 |
DateCalc_Add_Delta_YM(year,month,day, Dy,Dm) |
|---|
| 602 |
Z_int year |
|---|
| 603 |
Z_int month |
|---|
| 604 |
Z_int day |
|---|
| 605 |
Z_long Dy |
|---|
| 606 |
Z_long Dm |
|---|
| 607 |
PPCODE: |
|---|
| 608 |
{ |
|---|
| 609 |
if (DateCalc_add_delta_ym(&year,&month,&day, Dy,Dm)) |
|---|
| 610 |
{ |
|---|
| 611 |
EXTEND(sp,3); |
|---|
| 612 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 613 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 614 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 615 |
} |
|---|
| 616 |
else DATECALC_DATE_ERROR; |
|---|
| 617 |
} |
|---|
| 618 |
|
|---|
| 619 |
|
|---|
| 620 |
void |
|---|
| 621 |
DateCalc_Add_Delta_YMD(year,month,day, Dy,Dm,Dd) |
|---|
| 622 |
Z_int year |
|---|
| 623 |
Z_int month |
|---|
| 624 |
Z_int day |
|---|
| 625 |
Z_long Dy |
|---|
| 626 |
Z_long Dm |
|---|
| 627 |
Z_long Dd |
|---|
| 628 |
PPCODE: |
|---|
| 629 |
{ |
|---|
| 630 |
if (DateCalc_add_delta_ymd(&year,&month,&day, Dy,Dm,Dd)) |
|---|
| 631 |
{ |
|---|
| 632 |
EXTEND(sp,3); |
|---|
| 633 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 634 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 635 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 636 |
} |
|---|
| 637 |
else DATECALC_DATE_ERROR; |
|---|
| 638 |
} |
|---|
| 639 |
|
|---|
| 640 |
|
|---|
| 641 |
void |
|---|
| 642 |
DateCalc_Add_Delta_YMDHMS(year,month,day, hour,min,sec, D_y,D_m,D_d, Dh,Dm,Ds) |
|---|
| 643 |
Z_int year |
|---|
| 644 |
Z_int month |
|---|
| 645 |
Z_int day |
|---|
| 646 |
Z_int hour |
|---|
| 647 |
Z_int min |
|---|
| 648 |
Z_int sec |
|---|
| 649 |
Z_long D_y |
|---|
| 650 |
Z_long D_m |
|---|
| 651 |
Z_long D_d |
|---|
| 652 |
Z_long Dh |
|---|
| 653 |
Z_long Dm |
|---|
| 654 |
Z_long Ds |
|---|
| 655 |
PPCODE: |
|---|
| 656 |
{ |
|---|
| 657 |
if (DateCalc_check_date(year,month,day)) |
|---|
| 658 |
{ |
|---|
| 659 |
if (DateCalc_check_time(hour,min,sec)) |
|---|
| 660 |
{ |
|---|
| 661 |
if (DateCalc_add_delta_ymdhms(&year,&month,&day, |
|---|
| 662 |
&hour,&min,&sec, |
|---|
| 663 |
D_y,D_m,D_d, |
|---|
| 664 |
Dh,Dm,Ds)) |
|---|
| 665 |
{ |
|---|
| 666 |
EXTEND(sp,6); |
|---|
| 667 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 668 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 669 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 670 |
PUSHs(sv_2mortal(newSViv((IV)hour))); |
|---|
| 671 |
PUSHs(sv_2mortal(newSViv((IV)min))); |
|---|
| 672 |
PUSHs(sv_2mortal(newSViv((IV)sec))); |
|---|
| 673 |
} |
|---|
| 674 |
else DATECALC_DATE_ERROR; |
|---|
| 675 |
} |
|---|
| 676 |
else DATECALC_TIME_ERROR; |
|---|
| 677 |
} |
|---|
| 678 |
else DATECALC_DATE_ERROR; |
|---|
| 679 |
} |
|---|
| 680 |
|
|---|
| 681 |
|
|---|
| 682 |
void |
|---|
| 683 |
DateCalc_System_Clock(...) |
|---|
| 684 |
PPCODE: |
|---|
| 685 |
{ |
|---|
| 686 |
Z_int year; |
|---|
| 687 |
Z_int month; |
|---|
| 688 |
Z_int day; |
|---|
| 689 |
Z_int hour; |
|---|
| 690 |
Z_int min; |
|---|
| 691 |
Z_int sec; |
|---|
| 692 |
Z_int doy; |
|---|
| 693 |
Z_int dow; |
|---|
| 694 |
Z_int dst; |
|---|
| 695 |
boolean gmt; |
|---|
| 696 |
|
|---|
| 697 |
if ((items == 0) or (items == 1)) |
|---|
| 698 |
{ |
|---|
| 699 |
if (items == 1) gmt = (boolean) SvIV( ST(0) ); |
|---|
| 700 |
else gmt = false; |
|---|
| 701 |
if (DateCalc_system_clock(&year,&month,&day, |
|---|
| 702 |
&hour,&min,&sec, |
|---|
| 703 |
&doy,&dow,&dst, |
|---|
| 704 |
gmt)) |
|---|
| 705 |
{ |
|---|
| 706 |
EXTEND(sp,9); |
|---|
| 707 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 708 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 709 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 710 |
PUSHs(sv_2mortal(newSViv((IV)hour))); |
|---|
| 711 |
PUSHs(sv_2mortal(newSViv((IV)min))); |
|---|
| 712 |
PUSHs(sv_2mortal(newSViv((IV)sec))); |
|---|
| 713 |
PUSHs(sv_2mortal(newSViv((IV)doy))); |
|---|
| 714 |
PUSHs(sv_2mortal(newSViv((IV)dow))); |
|---|
| 715 |
PUSHs(sv_2mortal(newSViv((IV)dst))); |
|---|
| 716 |
} |
|---|
| 717 |
else DATECALC_SYSTEM_ERROR; |
|---|
| 718 |
} |
|---|
| 719 |
else croak("Usage: Date::Calc::System_Clock([gmt])"); |
|---|
| 720 |
} |
|---|
| 721 |
|
|---|
| 722 |
|
|---|
| 723 |
void |
|---|
| 724 |
DateCalc_Today(...) |
|---|
| 725 |
PPCODE: |
|---|
| 726 |
{ |
|---|
| 727 |
Z_int year; |
|---|
| 728 |
Z_int month; |
|---|
| 729 |
Z_int day; |
|---|
| 730 |
Z_int hour; |
|---|
| 731 |
Z_int min; |
|---|
| 732 |
Z_int sec; |
|---|
| 733 |
Z_int doy; |
|---|
| 734 |
Z_int dow; |
|---|
| 735 |
Z_int dst; |
|---|
| 736 |
boolean gmt; |
|---|
| 737 |
|
|---|
| 738 |
if ((items == 0) or (items == 1)) |
|---|
| 739 |
{ |
|---|
| 740 |
if (items == 1) gmt = (boolean) SvIV( ST(0) ); |
|---|
| 741 |
else gmt = false; |
|---|
| 742 |
if (DateCalc_system_clock(&year,&month,&day, |
|---|
| 743 |
&hour,&min,&sec, |
|---|
| 744 |
&doy,&dow,&dst, |
|---|
| 745 |
gmt)) |
|---|
| 746 |
{ |
|---|
| 747 |
EXTEND(sp,3); |
|---|
| 748 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 749 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 750 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 751 |
} |
|---|
| 752 |
else DATECALC_SYSTEM_ERROR; |
|---|
| 753 |
} |
|---|
| 754 |
else croak("Usage: Date::Calc::Today([gmt])"); |
|---|
| 755 |
} |
|---|
| 756 |
|
|---|
| 757 |
|
|---|
| 758 |
void |
|---|
| 759 |
DateCalc_Now(...) |
|---|
| 760 |
PPCODE: |
|---|
| 761 |
{ |
|---|
| 762 |
Z_int year; |
|---|
| 763 |
Z_int month; |
|---|
| 764 |
Z_int day; |
|---|
| 765 |
Z_int hour; |
|---|
| 766 |
Z_int min; |
|---|
| 767 |
Z_int sec; |
|---|
| 768 |
Z_int doy; |
|---|
| 769 |
Z_int dow; |
|---|
| 770 |
Z_int dst; |
|---|
| 771 |
boolean gmt; |
|---|
| 772 |
|
|---|
| 773 |
if ((items == 0) or (items == 1)) |
|---|
| 774 |
{ |
|---|
| 775 |
if (items == 1) gmt = (boolean) SvIV( ST(0) ); |
|---|
| 776 |
else gmt = false; |
|---|
| 777 |
if (DateCalc_system_clock(&year,&month,&day, |
|---|
| 778 |
&hour,&min,&sec, |
|---|
| 779 |
&doy,&dow,&dst, |
|---|
| 780 |
gmt)) |
|---|
| 781 |
{ |
|---|
| 782 |
EXTEND(sp,3); |
|---|
| 783 |
PUSHs(sv_2mortal(newSViv((IV)hour))); |
|---|
| 784 |
PUSHs(sv_2mortal(newSViv((IV)min))); |
|---|
| 785 |
PUSHs(sv_2mortal(newSViv((IV)sec))); |
|---|
| 786 |
} |
|---|
| 787 |
else DATECALC_SYSTEM_ERROR; |
|---|
| 788 |
} |
|---|
| 789 |
else croak("Usage: Date::Calc::Now([gmt])"); |
|---|
| 790 |
} |
|---|
| 791 |
|
|---|
| 792 |
|
|---|
| 793 |
void |
|---|
| 794 |
DateCalc_Today_and_Now(...) |
|---|
| 795 |
PPCODE: |
|---|
| 796 |
{ |
|---|
| 797 |
Z_int year; |
|---|
| 798 |
Z_int month; |
|---|
| 799 |
Z_int day; |
|---|
| 800 |
Z_int hour; |
|---|
| 801 |
Z_int min; |
|---|
| 802 |
Z_int sec; |
|---|
| 803 |
Z_int doy; |
|---|
| 804 |
Z_int dow; |
|---|
| 805 |
Z_int dst; |
|---|
| 806 |
boolean gmt; |
|---|
| 807 |
|
|---|
| 808 |
if ((items == 0) or (items == 1)) |
|---|
| 809 |
{ |
|---|
| 810 |
if (items == 1) gmt = (boolean) SvIV( ST(0) ); |
|---|
| 811 |
else gmt = false; |
|---|
| 812 |
if (DateCalc_system_clock(&year,&month,&day, |
|---|
| 813 |
&hour,&min,&sec, |
|---|
| 814 |
&doy,&dow,&dst, |
|---|
| 815 |
gmt)) |
|---|
| 816 |
{ |
|---|
| 817 |
EXTEND(sp,6); |
|---|
| 818 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 819 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 820 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 821 |
PUSHs(sv_2mortal(newSViv((IV)hour))); |
|---|
| 822 |
PUSHs(sv_2mortal(newSViv((IV)min))); |
|---|
| 823 |
PUSHs(sv_2mortal(newSViv((IV)sec))); |
|---|
| 824 |
} |
|---|
| 825 |
else DATECALC_SYSTEM_ERROR; |
|---|
| 826 |
} |
|---|
| 827 |
else croak("Usage: Date::Calc::Today_and_Now([gmt])"); |
|---|
| 828 |
} |
|---|
| 829 |
|
|---|
| 830 |
|
|---|
| 831 |
void |
|---|
| 832 |
DateCalc_This_Year(...) |
|---|
| 833 |
PPCODE: |
|---|
| 834 |
{ |
|---|
| 835 |
Z_int year; |
|---|
| 836 |
Z_int month; |
|---|
| 837 |
Z_int day; |
|---|
| 838 |
Z_int hour; |
|---|
| 839 |
Z_int min; |
|---|
| 840 |
Z_int sec; |
|---|
| 841 |
Z_int doy; |
|---|
| 842 |
Z_int dow; |
|---|
| 843 |
Z_int dst; |
|---|
| 844 |
boolean gmt; |
|---|
| 845 |
|
|---|
| 846 |
if ((items == 0) or (items == 1)) |
|---|
| 847 |
{ |
|---|
| 848 |
if (items == 1) gmt = (boolean) SvIV( ST(0) ); |
|---|
| 849 |
else gmt = false; |
|---|
| 850 |
if (DateCalc_system_clock(&year,&month,&day, |
|---|
| 851 |
&hour,&min,&sec, |
|---|
| 852 |
&doy,&dow,&dst, |
|---|
| 853 |
gmt)) |
|---|
| 854 |
{ |
|---|
| 855 |
EXTEND(sp,1); |
|---|
| 856 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 857 |
} |
|---|
| 858 |
else DATECALC_SYSTEM_ERROR; |
|---|
| 859 |
} |
|---|
| 860 |
else croak("Usage: Date::Calc::This_Year([gmt])"); |
|---|
| 861 |
} |
|---|
| 862 |
|
|---|
| 863 |
|
|---|
| 864 |
void |
|---|
| 865 |
DateCalc_Gmtime(...) |
|---|
| 866 |
PPCODE: |
|---|
| 867 |
{ |
|---|
| 868 |
#ifdef MACOS_TRADITIONAL |
|---|
| 869 |
double f_seconds; |
|---|
| 870 |
#endif |
|---|
| 871 |
time_t seconds; |
|---|
| 872 |
Z_int year; |
|---|
| 873 |
Z_int month; |
|---|
| 874 |
Z_int day; |
|---|
| 875 |
Z_int hour; |
|---|
| 876 |
Z_int min; |
|---|
| 877 |
Z_int sec; |
|---|
| 878 |
Z_int doy; |
|---|
| 879 |
Z_int dow; |
|---|
| 880 |
Z_int dst; |
|---|
| 881 |
|
|---|
| 882 |
if ((items == 0) or (items == 1)) |
|---|
| 883 |
{ |
|---|
| 884 |
#ifdef MACOS_TRADITIONAL |
|---|
| 885 |
if (items == 1) f_seconds = (double) SvNV( ST(0) ); |
|---|
| 886 |
else f_seconds = (double) time(NULL); |
|---|
| 887 |
if ((f_seconds < 0) or (f_seconds > 0xFFFFFFFF)) |
|---|
| 888 |
DATECALC_TIME_RANGE_ERROR; |
|---|
| 889 |
seconds = (time_t) f_seconds; |
|---|
| 890 |
#else |
|---|
| 891 |
if (items == 1) seconds = (time_t) SvIV( ST(0) ); |
|---|
| 892 |
else seconds = time(NULL); |
|---|
| 893 |
#endif |
|---|
| 894 |
if (DateCalc_gmtime(&year,&month,&day, |
|---|
| 895 |
&hour,&min,&sec, |
|---|
| 896 |
&doy,&dow,&dst, |
|---|
| 897 |
seconds)) |
|---|
| 898 |
{ |
|---|
| 899 |
EXTEND(sp,9); |
|---|
| 900 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 901 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 902 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 903 |
PUSHs(sv_2mortal(newSViv((IV)hour))); |
|---|
| 904 |
PUSHs(sv_2mortal(newSViv((IV)min))); |
|---|
| 905 |
PUSHs(sv_2mortal(newSViv((IV)sec))); |
|---|
| 906 |
PUSHs(sv_2mortal(newSViv((IV)doy))); |
|---|
| 907 |
PUSHs(sv_2mortal(newSViv((IV)dow))); |
|---|
| 908 |
PUSHs(sv_2mortal(newSViv((IV)dst))); |
|---|
| 909 |
} |
|---|
| 910 |
else DATECALC_TIME_RANGE_ERROR; |
|---|
| 911 |
} |
|---|
| 912 |
else croak("Usage: Date::Calc::Gmtime([time])"); |
|---|
| 913 |
} |
|---|
| 914 |
|
|---|
| 915 |
|
|---|
| 916 |
void |
|---|
| 917 |
DateCalc_Localtime(...) |
|---|
| 918 |
PPCODE: |
|---|
| 919 |
{ |
|---|
| 920 |
#ifdef MACOS_TRADITIONAL |
|---|
| 921 |
double f_seconds; |
|---|
| 922 |
#endif |
|---|
| 923 |
time_t seconds; |
|---|
| 924 |
Z_int year; |
|---|
| 925 |
Z_int month; |
|---|
| 926 |
Z_int day; |
|---|
| 927 |
Z_int hour; |
|---|
| 928 |
Z_int min; |
|---|
| 929 |
Z_int sec; |
|---|
| 930 |
Z_int doy; |
|---|
| 931 |
Z_int dow; |
|---|
| 932 |
Z_int dst; |
|---|
| 933 |
|
|---|
| 934 |
if ((items == 0) or (items == 1)) |
|---|
| 935 |
{ |
|---|
| 936 |
#ifdef MACOS_TRADITIONAL |
|---|
| 937 |
if (items == 1) f_seconds = (double) SvNV( ST(0) ); |
|---|
| 938 |
else f_seconds = (double) time(NULL); |
|---|
| 939 |
if ((f_seconds < 0) or (f_seconds > 0xFFFFFFFF)) |
|---|
| 940 |
DATECALC_TIME_RANGE_ERROR; |
|---|
| 941 |
seconds = (time_t) f_seconds; |
|---|
| 942 |
#else |
|---|
| 943 |
if (items == 1) seconds = (time_t) SvIV( ST(0) ); |
|---|
| 944 |
else seconds = time(NULL); |
|---|
| 945 |
#endif |
|---|
| 946 |
if (DateCalc_localtime(&year,&month,&day, |
|---|
| 947 |
&hour,&min,&sec, |
|---|
| 948 |
&doy,&dow,&dst, |
|---|
| 949 |
seconds)) |
|---|
| 950 |
{ |
|---|
| 951 |
EXTEND(sp,9); |
|---|
| 952 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 953 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 954 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 955 |
PUSHs(sv_2mortal(newSViv((IV)hour))); |
|---|
| 956 |
PUSHs(sv_2mortal(newSViv((IV)min))); |
|---|
| 957 |
PUSHs(sv_2mortal(newSViv((IV)sec))); |
|---|
| 958 |
PUSHs(sv_2mortal(newSViv((IV)doy))); |
|---|
| 959 |
PUSHs(sv_2mortal(newSViv((IV)dow))); |
|---|
| 960 |
PUSHs(sv_2mortal(newSViv((IV)dst))); |
|---|
| 961 |
} |
|---|
| 962 |
else DATECALC_TIME_RANGE_ERROR; |
|---|
| 963 |
} |
|---|
| 964 |
else croak("Usage: Date::Calc::Localtime([time])"); |
|---|
| 965 |
} |
|---|
| 966 |
|
|---|
| 967 |
|
|---|
| 968 |
void |
|---|
| 969 |
DateCalc_Mktime(year,month,day, hour,min,sec) |
|---|
| 970 |
Z_int year |
|---|
| 971 |
Z_int month |
|---|
| 972 |
Z_int day |
|---|
| 973 |
Z_int hour |
|---|
| 974 |
Z_int min |
|---|
| 975 |
Z_int sec |
|---|
| 976 |
PPCODE: |
|---|
| 977 |
{ |
|---|
| 978 |
time_t seconds; |
|---|
| 979 |
|
|---|
| 980 |
if (DateCalc_mktime(&seconds, year,month,day, hour,min,sec, -1,-1,-1)) |
|---|
| 981 |
{ |
|---|
| 982 |
EXTEND(sp,1); |
|---|
| 983 |
#ifdef MACOS_TRADITIONAL |
|---|
| 984 |
PUSHs(sv_2mortal(newSVuv((UV)seconds))); |
|---|
| 985 |
#else |
|---|
| 986 |
PUSHs(sv_2mortal(newSViv((IV)seconds))); |
|---|
| 987 |
#endif |
|---|
| 988 |
} |
|---|
| 989 |
else DATECALC_DATE_RANGE_ERROR; |
|---|
| 990 |
} |
|---|
| 991 |
|
|---|
| 992 |
|
|---|
| 993 |
void |
|---|
| 994 |
DateCalc_Timezone(...) |
|---|
| 995 |
PPCODE: |
|---|
| 996 |
{ |
|---|
| 997 |
#ifdef MACOS_TRADITIONAL |
|---|
| 998 |
double f_when; |
|---|
| 999 |
#endif |
|---|
| 1000 |
time_t when; |
|---|
| 1001 |
Z_int year; |
|---|
| 1002 |
Z_int month; |
|---|
| 1003 |
Z_int day; |
|---|
| 1004 |
Z_int hour; |
|---|
| 1005 |
Z_int min; |
|---|
| 1006 |
Z_int sec; |
|---|
| 1007 |
Z_int dst; |
|---|
| 1008 |
|
|---|
| 1009 |
if ((items == 0) or (items == 1)) |
|---|
| 1010 |
{ |
|---|
| 1011 |
#ifdef MACOS_TRADITIONAL |
|---|
| 1012 |
if (items == 1) f_when = (double) SvNV( ST(0) ); |
|---|
| 1013 |
else f_when = (double) time(NULL); |
|---|
| 1014 |
if ((f_when < 0) or (f_when > 0xFFFFFFFF)) |
|---|
| 1015 |
DATECALC_TIME_RANGE_ERROR; |
|---|
| 1016 |
when = (time_t) f_when; |
|---|
| 1017 |
#else |
|---|
| 1018 |
if (items == 1) when = (time_t) SvIV( ST(0) ); |
|---|
| 1019 |
else when = time(NULL); |
|---|
| 1020 |
#endif |
|---|
| 1021 |
if (DateCalc_timezone(&year,&month,&day, |
|---|
| 1022 |
&hour,&min,&sec, |
|---|
| 1023 |
&dst,when)) |
|---|
| 1024 |
{ |
|---|
| 1025 |
EXTEND(sp,7); |
|---|
| 1026 |
PUSHs(sv_2mortal(newSViv((IV)year))); |
|---|
| 1027 |
PUSHs(sv_2mortal(newSViv((IV)month))); |
|---|
| 1028 |
PUSHs(sv_2mortal(newSViv((IV)day))); |
|---|
| 1029 |
PUSHs(sv_2mortal(newSViv((IV)hour))); |
|---|
| 1030 |
PUSHs(sv_2mortal(newSViv((IV)min))); |
|---|
| 1031 |
PUSHs(sv_2mortal(newSViv((IV)sec))); |
|---|
| 1032 |
PUSHs(sv_2mortal(newSViv((IV)dst))); |
|---|
| 1033 |
} |
|---|
| 1034 |
else DATECALC_TIME_RANGE_ERROR; |
|---|
| 1035 |
} |
|---|
| 1036 |
else croak("Usage: Date::Calc::Timezone([time])"); |
|---|
| 1037 |
} |
|---|
| 1038 |
|
|---|
| 1039 |
|
|---|
| 1040 |
void |
|---|
| 1041 |
DateCalc_Date_to_Time(year,month,day, hour,min,sec) |
|---|
| 1042 |
Z_int year |
|---|
| 1043 |
Z_int month |
|---|
| 1044 |
Z_int day |
|---|
| 1045 |
Z_int hour |
|---|
| 1046 |
Z_int min |
|---|
| 1047 |
Z_int sec |
|---|
| 1048 |
PPCODE: |
|---|
| 1049 |
{ |
|---|
| 1050 |
time_t seconds; |
|---|
| 1051 |
|
|---|
| 1052 |
if (DateCalc_date2time(&seconds, year,month,day, hour,min,sec)) |
|---|
| 1053 |
{ |
|---|
| 1054 |
EXTEND(sp,1); |
|---|
| 1055 |
#ifdef MACOS_TRADITIONAL |
|---|
| 1056 |
PUSHs(sv_2mortal(newSVuv((UV)seconds))); |
|---|
| 1057 |
#else |
|---|
| 1058 |
PUSHs(sv_2mortal(newSViv((IV)seconds))); |
|---|
| 1059 |
#endif |
|---|
| 1060 |
} |
|---|
| 1061 |
else DATECALC_DATE_RANGE_ERROR; |
|---|
| 1062 |
} |
|---|
| 1063 |
|
|---|
| 1064 |
|
|---|
| 1065 |
void |
|---|
| 1066 |
DateCalc_Time_to_Date(...) |
|---|
| 1067 |
PPCODE: |
|---|
| 1068 |
{ |
|---|
| 1069 |
#ifdef MACOS_TRADITIONAL |
|---|
| 1070 |
double f_seconds; |
|---|
| 1071 |
#endif |
|---|
| 1072 |
time_t seconds; |
|---|
| 1073 |
Z_int year; |
|---|
| 1074 |
& |
|---|