Commit | Line | Data |
---|---|---|
16433e2b | 1 | #ifdef __cplusplus |
c944940b | 2 | extern "C" { |
16433e2b SP |
3 | #endif |
4 | #include "EXTERN.h" | |
5 | #include "perl.h" | |
6 | #include "XSUB.h" | |
7 | #include <time.h> | |
8 | #ifdef __cplusplus | |
9 | } | |
10 | #endif | |
11 | ||
12 | /* XXX struct tm on some systems (SunOS4/BSD) contains extra (non POSIX) | |
d4d72fe6 | 13 | * fields for which we don't have Configure support prior to Perl 5.8.0: |
16433e2b SP |
14 | * char *tm_zone; -- abbreviation of timezone name |
15 | * long tm_gmtoff; -- offset from GMT in seconds | |
16 | * To workaround core dumps from the uninitialised tm_zone we get the | |
17 | * system to give us a reasonable struct to copy. This fix means that | |
18 | * strftime uses the tm_zone and tm_gmtoff values returned by | |
19 | * localtime(time()). That should give the desired result most of the | |
20 | * time. But probably not always! | |
21 | * | |
d4d72fe6 CB |
22 | * This is a vestigial workaround for Perls prior to 5.8.0. We now |
23 | * rely on the initialization (still likely a workaround) in util.c. | |
16433e2b | 24 | */ |
d4d72fe6 CB |
25 | #if !defined(PERL_VERSION) || PERL_VERSION < 8 |
26 | ||
036055ae | 27 | #if defined(HAS_GNULIBC) |
16433e2b SP |
28 | # ifndef STRUCT_TM_HASZONE |
29 | # define STRUCT_TM_HASZONE | |
30 | # else | |
31 | # define USE_TM_GMTOFF | |
32 | # endif | |
33 | #endif | |
34 | ||
d4d72fe6 CB |
35 | #endif /* end of pre-5.8 */ |
36 | ||
16433e2b SP |
37 | #define DAYS_PER_YEAR 365 |
38 | #define DAYS_PER_QYEAR (4*DAYS_PER_YEAR+1) | |
39 | #define DAYS_PER_CENT (25*DAYS_PER_QYEAR-1) | |
40 | #define DAYS_PER_QCENT (4*DAYS_PER_CENT+1) | |
41 | #define SECS_PER_HOUR (60*60) | |
42 | #define SECS_PER_DAY (24*SECS_PER_HOUR) | |
43 | /* parentheses deliberately absent on these two, otherwise they don't work */ | |
44 | #define MONTH_TO_DAYS 153/5 | |
45 | #define DAYS_TO_MONTH 5/153 | |
46 | /* offset to bias by March (month 4) 1st between month/mday & year finding */ | |
47 | #define YEAR_ADJUST (4*MONTH_TO_DAYS+1) | |
48 | /* as used here, the algorithm leaves Sunday as day 1 unless we adjust it */ | |
49 | #define WEEKDAY_BIAS 6 /* (1+6)%7 makes Sunday 0 again */ | |
50 | ||
d4d72fe6 CB |
51 | #if !defined(PERL_VERSION) || PERL_VERSION < 8 |
52 | ||
16433e2b SP |
53 | #ifdef STRUCT_TM_HASZONE |
54 | static void | |
55 | my_init_tm(struct tm *ptm) /* see mktime, strftime and asctime */ | |
56 | { | |
57 | Time_t now; | |
58 | (void)time(&now); | |
59 | Copy(localtime(&now), ptm, 1, struct tm); | |
60 | } | |
61 | ||
62 | #else | |
63 | # define my_init_tm(ptm) | |
64 | #endif | |
65 | ||
d4d72fe6 CB |
66 | #else |
67 | /* use core version from util.c in 5.8.0 and later */ | |
68 | # define my_init_tm init_tm | |
69 | #endif | |
70 | ||
6e073399 SH |
71 | #ifdef WIN32 |
72 | ||
73 | /* | |
74 | * (1) The CRT maintains its own copy of the environment, separate from | |
75 | * the Win32API copy. | |
76 | * | |
77 | * (2) CRT getenv() retrieves from this copy. CRT putenv() updates this | |
78 | * copy, and then calls SetEnvironmentVariableA() to update the Win32API | |
79 | * copy. | |
80 | * | |
81 | * (3) win32_getenv() and win32_putenv() call GetEnvironmentVariableA() and | |
82 | * SetEnvironmentVariableA() directly, bypassing the CRT copy of the | |
83 | * environment. | |
84 | * | |
85 | * (4) The CRT strftime() "%Z" implementation calls __tzset(). That | |
86 | * calls CRT tzset(), but only the first time it is called, and in turn | |
87 | * that uses CRT getenv("TZ") to retrieve the timezone info from the CRT | |
88 | * local copy of the environment and hence gets the original setting as | |
89 | * perl never updates the CRT copy when assigning to $ENV{TZ}. | |
90 | * | |
91 | * Therefore, we need to retrieve the value of $ENV{TZ} and call CRT | |
12016aad SH |
92 | * putenv() to update the CRT copy of the environment (if it is different) |
93 | * whenever we're about to call tzset(). | |
94 | * | |
95 | * In addition to all that, when perl is built with PERL_IMPLICIT_SYS | |
96 | * defined: | |
97 | * | |
98 | * (a) Each interpreter has its own copy of the environment inside the | |
99 | * perlhost structure. That allows applications that host multiple | |
100 | * independent Perl interpreters to isolate environment changes from | |
101 | * each other. (This is similar to how the perlhost mechanism keeps a | |
102 | * separate working directory for each Perl interpreter, so that calling | |
103 | * chdir() will not affect other interpreters.) | |
104 | * | |
105 | * (b) Only the first Perl interpreter instantiated within a process will | |
106 | * "write through" environment changes to the process environment. | |
107 | * | |
108 | * (c) Even the primary Perl interpreter won't update the CRT copy of the | |
109 | * the environment, only the Win32API copy (it calls win32_putenv()). | |
110 | * | |
111 | * As with CPerlHost::Getenv() and CPerlHost::Putenv() themselves, it makes | |
112 | * sense to only update the process environment when inside the main | |
113 | * interpreter, but we don't have access to CPerlHost's m_bTopLevel member | |
114 | * from here so we'll just have to check PL_curinterp instead. | |
115 | * | |
116 | * Therefore, we can simply #undef getenv() and putenv() so that those names | |
117 | * always refer to the CRT functions, and explicitly call win32_getenv() to | |
118 | * access perl's %ENV. | |
119 | * | |
120 | * We also #undef malloc() and free() to be sure we are using the CRT | |
121 | * functions otherwise under PERL_IMPLICIT_SYS they are redefined to calls | |
122 | * into VMem::Malloc() and VMem::Free() and all allocations will be freed | |
123 | * when the Perl interpreter is being destroyed so we'd end up with a pointer | |
124 | * into deallocated memory in environ[] if a program embedding a Perl | |
125 | * interpreter continues to operate even after the main Perl interpreter has | |
126 | * been destroyed. | |
127 | * | |
128 | * Note that we don't free() the malloc()ed memory unless and until we call | |
129 | * malloc() again ourselves because the CRT putenv() function simply puts its | |
130 | * pointer argument into the environ[] arrary (it doesn't make a copy of it) | |
131 | * so this memory must otherwise be leaked. | |
6e073399 SH |
132 | */ |
133 | ||
6e073399 | 134 | #undef getenv |
6e073399 | 135 | #undef putenv |
12016aad SH |
136 | #undef malloc |
137 | #undef free | |
6e073399 SH |
138 | |
139 | static void | |
140 | fix_win32_tzenv(void) | |
141 | { | |
12016aad SH |
142 | static char* oldenv = NULL; |
143 | char* newenv; | |
144 | const char* perl_tz_env = win32_getenv("TZ"); | |
145 | const char* crt_tz_env = getenv("TZ"); | |
146 | if (perl_tz_env == NULL) | |
147 | perl_tz_env = ""; | |
148 | if (crt_tz_env == NULL) | |
149 | crt_tz_env = ""; | |
150 | if (strcmp(perl_tz_env, crt_tz_env) != 0) { | |
151 | newenv = (char*)malloc((strlen(perl_tz_env) + 4) * sizeof(char)); | |
152 | if (newenv != NULL) { | |
153 | sprintf(newenv, "TZ=%s", perl_tz_env); | |
154 | putenv(newenv); | |
155 | if (oldenv != NULL) | |
156 | free(oldenv); | |
157 | oldenv = newenv; | |
158 | } | |
6e073399 | 159 | } |
6e073399 SH |
160 | } |
161 | ||
162 | #endif | |
163 | ||
81ab4c44 SH |
164 | /* |
165 | * my_tzset - wrapper to tzset() with a fix to make it work (better) on Win32. | |
166 | * This code is duplicated in the POSIX module, so any changes made here | |
167 | * should be made there too. | |
168 | */ | |
6e073399 | 169 | static void |
12016aad | 170 | my_tzset(pTHX) |
6e073399 SH |
171 | { |
172 | #ifdef WIN32 | |
12016aad SH |
173 | #if defined(USE_ITHREADS) && defined(PERL_IMPLICIT_SYS) |
174 | if (PL_curinterp == aTHX) | |
175 | #endif | |
176 | fix_win32_tzenv(); | |
6e073399 SH |
177 | #endif |
178 | tzset(); | |
179 | } | |
180 | ||
16433e2b SP |
181 | /* |
182 | * my_mini_mktime - normalise struct tm values without the localtime() | |
124e6c84 RGS |
183 | * semantics (and overhead) of mktime(). Stolen shamelessly from Perl's |
184 | * Perl_mini_mktime() in util.c - for details on the algorithm, see that | |
185 | * file. | |
16433e2b SP |
186 | */ |
187 | static void | |
188 | my_mini_mktime(struct tm *ptm) | |
189 | { | |
190 | int yearday; | |
191 | int secs; | |
192 | int month, mday, year, jday; | |
193 | int odd_cent, odd_year; | |
194 | ||
16433e2b SP |
195 | year = 1900 + ptm->tm_year; |
196 | month = ptm->tm_mon; | |
197 | mday = ptm->tm_mday; | |
198 | /* allow given yday with no month & mday to dominate the result */ | |
199 | if (ptm->tm_yday >= 0 && mday <= 0 && month <= 0) { | |
200 | month = 0; | |
201 | mday = 0; | |
202 | jday = 1 + ptm->tm_yday; | |
203 | } | |
204 | else { | |
205 | jday = 0; | |
206 | } | |
207 | if (month >= 2) | |
208 | month+=2; | |
209 | else | |
210 | month+=14, year--; | |
211 | ||
212 | yearday = DAYS_PER_YEAR * year + year/4 - year/100 + year/400; | |
213 | yearday += month*MONTH_TO_DAYS + mday + jday; | |
214 | /* | |
215 | * Note that we don't know when leap-seconds were or will be, | |
216 | * so we have to trust the user if we get something which looks | |
217 | * like a sensible leap-second. Wild values for seconds will | |
218 | * be rationalised, however. | |
219 | */ | |
220 | if ((unsigned) ptm->tm_sec <= 60) { | |
221 | secs = 0; | |
222 | } | |
223 | else { | |
224 | secs = ptm->tm_sec; | |
225 | ptm->tm_sec = 0; | |
226 | } | |
227 | secs += 60 * ptm->tm_min; | |
228 | secs += SECS_PER_HOUR * ptm->tm_hour; | |
229 | if (secs < 0) { | |
230 | if (secs-(secs/SECS_PER_DAY*SECS_PER_DAY) < 0) { | |
231 | /* got negative remainder, but need positive time */ | |
232 | /* back off an extra day to compensate */ | |
233 | yearday += (secs/SECS_PER_DAY)-1; | |
234 | secs -= SECS_PER_DAY * (secs/SECS_PER_DAY - 1); | |
235 | } | |
236 | else { | |
237 | yearday += (secs/SECS_PER_DAY); | |
238 | secs -= SECS_PER_DAY * (secs/SECS_PER_DAY); | |
239 | } | |
240 | } | |
241 | else if (secs >= SECS_PER_DAY) { | |
242 | yearday += (secs/SECS_PER_DAY); | |
243 | secs %= SECS_PER_DAY; | |
244 | } | |
245 | ptm->tm_hour = secs/SECS_PER_HOUR; | |
246 | secs %= SECS_PER_HOUR; | |
247 | ptm->tm_min = secs/60; | |
248 | secs %= 60; | |
249 | ptm->tm_sec += secs; | |
250 | /* done with time of day effects */ | |
251 | /* | |
252 | * The algorithm for yearday has (so far) left it high by 428. | |
253 | * To avoid mistaking a legitimate Feb 29 as Mar 1, we need to | |
254 | * bias it by 123 while trying to figure out what year it | |
255 | * really represents. Even with this tweak, the reverse | |
256 | * translation fails for years before A.D. 0001. | |
257 | * It would still fail for Feb 29, but we catch that one below. | |
258 | */ | |
259 | jday = yearday; /* save for later fixup vis-a-vis Jan 1 */ | |
260 | yearday -= YEAR_ADJUST; | |
261 | year = (yearday / DAYS_PER_QCENT) * 400; | |
262 | yearday %= DAYS_PER_QCENT; | |
263 | odd_cent = yearday / DAYS_PER_CENT; | |
264 | year += odd_cent * 100; | |
265 | yearday %= DAYS_PER_CENT; | |
266 | year += (yearday / DAYS_PER_QYEAR) * 4; | |
267 | yearday %= DAYS_PER_QYEAR; | |
268 | odd_year = yearday / DAYS_PER_YEAR; | |
269 | year += odd_year; | |
270 | yearday %= DAYS_PER_YEAR; | |
271 | if (!yearday && (odd_cent==4 || odd_year==4)) { /* catch Feb 29 */ | |
272 | month = 1; | |
273 | yearday = 29; | |
274 | } | |
275 | else { | |
276 | yearday += YEAR_ADJUST; /* recover March 1st crock */ | |
277 | month = yearday*DAYS_TO_MONTH; | |
278 | yearday -= month*MONTH_TO_DAYS; | |
279 | /* recover other leap-year adjustment */ | |
280 | if (month > 13) { | |
281 | month-=14; | |
282 | year++; | |
283 | } | |
284 | else { | |
285 | month-=2; | |
286 | } | |
287 | } | |
288 | ptm->tm_year = year - 1900; | |
289 | if (yearday) { | |
290 | ptm->tm_mday = yearday; | |
291 | ptm->tm_mon = month; | |
292 | } | |
293 | else { | |
294 | ptm->tm_mday = 31; | |
295 | ptm->tm_mon = month - 1; | |
296 | } | |
297 | /* re-build yearday based on Jan 1 to get tm_yday */ | |
298 | year--; | |
299 | yearday = year*DAYS_PER_YEAR + year/4 - year/100 + year/400; | |
300 | yearday += 14*MONTH_TO_DAYS + 1; | |
301 | ptm->tm_yday = jday - yearday; | |
302 | /* fix tm_wday if not overridden by caller */ | |
303 | ptm->tm_wday = (jday + WEEKDAY_BIAS) % 7; | |
304 | } | |
305 | ||
12016aad | 306 | # if defined(WIN32) || (defined(__QNX__) && defined(__WATCOMC__)) |
90d55c29 | 307 | # define strncasecmp(x,y,n) strnicmp(x,y,n) |
12016aad | 308 | # endif |
be8a15fc | 309 | |
124e6c84 RGS |
310 | /* strptime copied from freebsd with the following copyright: */ |
311 | /* | |
312 | * Copyright (c) 1994 Powerdog Industries. All rights reserved. | |
313 | * | |
314 | * Redistribution and use in source and binary forms, with or without | |
315 | * modification, are permitted provided that the following conditions | |
316 | * are met: | |
317 | * 1. Redistributions of source code must retain the above copyright | |
318 | * notice, this list of conditions and the following disclaimer. | |
319 | * 2. Redistributions in binary form must reproduce the above copyright | |
320 | * notice, this list of conditions and the following disclaimer | |
321 | * in the documentation and/or other materials provided with the | |
322 | * distribution. | |
323 | * 3. All advertising materials mentioning features or use of this | |
324 | * software must display the following acknowledgement: | |
325 | * This product includes software developed by Powerdog Industries. | |
326 | * 4. The name of Powerdog Industries may not be used to endorse or | |
327 | * promote products derived from this software without specific prior | |
328 | * written permission. | |
329 | * | |
330 | * THIS SOFTWARE IS PROVIDED BY POWERDOG INDUSTRIES ``AS IS'' AND ANY | |
331 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
332 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
333 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE POWERDOG INDUSTRIES BE | |
334 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
335 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
336 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR | |
337 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, | |
338 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE | |
339 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, | |
340 | * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
341 | */ | |
342 | ||
343 | #ifndef lint | |
344 | #ifndef NOID | |
345 | static char copyright[] = | |
346 | "@(#) Copyright (c) 1994 Powerdog Industries. All rights reserved."; | |
347 | static char sccsid[] = "@(#)strptime.c 0.1 (Powerdog) 94/03/27"; | |
348 | #endif /* !defined NOID */ | |
349 | #endif /* not lint */ | |
be8a15fc | 350 | |
16433e2b SP |
351 | #include <time.h> |
352 | #include <ctype.h> | |
353 | #include <string.h> | |
e9f284c9 MB |
354 | static char * _strptime(pTHX_ const char *, const char *, struct tm *, |
355 | int *got_GMT); | |
16433e2b SP |
356 | |
357 | #define asizeof(a) (sizeof (a) / sizeof ((a)[0])) | |
358 | ||
359 | struct lc_time_T { | |
360 | const char * mon[12]; | |
361 | const char * month[12]; | |
362 | const char * wday[7]; | |
363 | const char * weekday[7]; | |
364 | const char * X_fmt; | |
365 | const char * x_fmt; | |
366 | const char * c_fmt; | |
367 | const char * am; | |
368 | const char * pm; | |
369 | const char * date_fmt; | |
370 | const char * alt_month[12]; | |
371 | const char * Ef_fmt; | |
372 | const char * EF_fmt; | |
373 | }; | |
374 | ||
375 | struct lc_time_T _time_localebuf; | |
376 | int _time_using_locale; | |
377 | ||
378 | const struct lc_time_T _C_time_locale = { | |
379 | { | |
380 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", | |
381 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" | |
382 | }, { | |
383 | "January", "February", "March", "April", "May", "June", | |
384 | "July", "August", "September", "October", "November", "December" | |
385 | }, { | |
386 | "Sun", "Mon", "Tue", "Wed", | |
387 | "Thu", "Fri", "Sat" | |
388 | }, { | |
389 | "Sunday", "Monday", "Tuesday", "Wednesday", | |
390 | "Thursday", "Friday", "Saturday" | |
391 | }, | |
392 | ||
393 | /* X_fmt */ | |
394 | "%H:%M:%S", | |
395 | ||
396 | /* | |
397 | ** x_fmt | |
398 | ** Since the C language standard calls for | |
399 | ** "date, using locale's date format," anything goes. | |
400 | ** Using just numbers (as here) makes Quakers happier; | |
401 | ** it's also compatible with SVR4. | |
402 | */ | |
403 | "%m/%d/%y", | |
404 | ||
405 | /* | |
406 | ** c_fmt (ctime-compatible) | |
407 | ** Not used, just compatibility placeholder. | |
408 | */ | |
409 | NULL, | |
410 | ||
411 | /* am */ | |
412 | "AM", | |
413 | ||
414 | /* pm */ | |
415 | "PM", | |
416 | ||
417 | /* date_fmt */ | |
418 | "%a %Ef %X %Z %Y", | |
419 | ||
420 | { | |
421 | "January", "February", "March", "April", "May", "June", | |
422 | "July", "August", "September", "October", "November", "December" | |
423 | }, | |
424 | ||
425 | /* Ef_fmt | |
426 | ** To determine short months / day order | |
427 | */ | |
428 | "%b %e", | |
429 | ||
430 | /* EF_fmt | |
431 | ** To determine long months / day order | |
432 | */ | |
433 | "%B %e" | |
434 | }; | |
435 | ||
436 | #define Locale (&_C_time_locale) | |
437 | ||
438 | static char * | |
e9f284c9 | 439 | _strptime(pTHX_ const char *buf, const char *fmt, struct tm *tm, int *got_GMT) |
16433e2b SP |
440 | { |
441 | char c; | |
442 | const char *ptr; | |
443 | int i, | |
444 | len; | |
445 | int Ealternative, Oalternative; | |
446 | ||
90d55c29 CBW |
447 | /* There seems to be a slightly improved version at |
448 | * http://www.opensource.apple.com/source/Libc/Libc-583/stdtime/strptime-fbsd.c | |
449 | * which we may end up borrowing more from | |
450 | */ | |
16433e2b SP |
451 | ptr = fmt; |
452 | while (*ptr != 0) { | |
453 | if (*buf == 0) | |
454 | break; | |
455 | ||
456 | c = *ptr++; | |
90d55c29 | 457 | |
16433e2b SP |
458 | if (c != '%') { |
459 | if (isspace((unsigned char)c)) | |
460 | while (*buf != 0 && isspace((unsigned char)*buf)) | |
461 | buf++; | |
462 | else if (c != *buf++) | |
463 | return 0; | |
464 | continue; | |
465 | } | |
466 | ||
467 | Ealternative = 0; | |
468 | Oalternative = 0; | |
469 | label: | |
470 | c = *ptr++; | |
471 | switch (c) { | |
472 | case 0: | |
473 | case '%': | |
474 | if (*buf++ != '%') | |
475 | return 0; | |
476 | break; | |
477 | ||
478 | case '+': | |
e9f284c9 | 479 | buf = _strptime(aTHX_ buf, Locale->date_fmt, tm, got_GMT); |
16433e2b SP |
480 | if (buf == 0) |
481 | return 0; | |
482 | break; | |
483 | ||
484 | case 'C': | |
485 | if (!isdigit((unsigned char)*buf)) | |
486 | return 0; | |
487 | ||
488 | /* XXX This will break for 3-digit centuries. */ | |
489 | len = 2; | |
490 | for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { | |
491 | i *= 10; | |
492 | i += *buf - '0'; | |
493 | len--; | |
494 | } | |
495 | if (i < 19) | |
496 | return 0; | |
497 | ||
498 | tm->tm_year = i * 100 - 1900; | |
499 | break; | |
500 | ||
501 | case 'c': | |
502 | /* NOTE: c_fmt is intentionally ignored */ | |
e9f284c9 | 503 | buf = _strptime(aTHX_ buf, "%a %Ef %T %Y", tm, got_GMT); |
16433e2b SP |
504 | if (buf == 0) |
505 | return 0; | |
506 | break; | |
507 | ||
508 | case 'D': | |
e9f284c9 | 509 | buf = _strptime(aTHX_ buf, "%m/%d/%y", tm, got_GMT); |
16433e2b SP |
510 | if (buf == 0) |
511 | return 0; | |
512 | break; | |
513 | ||
514 | case 'E': | |
515 | if (Ealternative || Oalternative) | |
516 | break; | |
517 | Ealternative++; | |
518 | goto label; | |
519 | ||
520 | case 'O': | |
521 | if (Ealternative || Oalternative) | |
522 | break; | |
523 | Oalternative++; | |
524 | goto label; | |
525 | ||
526 | case 'F': | |
527 | case 'f': | |
528 | if (!Ealternative) | |
529 | break; | |
e9f284c9 | 530 | buf = _strptime(aTHX_ buf, (c == 'f') ? Locale->Ef_fmt : Locale->EF_fmt, tm, got_GMT); |
16433e2b SP |
531 | if (buf == 0) |
532 | return 0; | |
533 | break; | |
534 | ||
535 | case 'R': | |
e9f284c9 | 536 | buf = _strptime(aTHX_ buf, "%H:%M", tm, got_GMT); |
16433e2b SP |
537 | if (buf == 0) |
538 | return 0; | |
539 | break; | |
540 | ||
541 | case 'r': | |
e9f284c9 | 542 | buf = _strptime(aTHX_ buf, "%I:%M:%S %p", tm, got_GMT); |
16433e2b SP |
543 | if (buf == 0) |
544 | return 0; | |
545 | break; | |
546 | ||
90d55c29 CBW |
547 | case 'n': /* whitespace */ |
548 | case 't': | |
549 | if (!isspace((unsigned char)*buf)) | |
550 | return 0; | |
551 | while (isspace((unsigned char)*buf)) | |
552 | buf++; | |
553 | break; | |
554 | ||
16433e2b | 555 | case 'T': |
e9f284c9 | 556 | buf = _strptime(aTHX_ buf, "%H:%M:%S", tm, got_GMT); |
16433e2b SP |
557 | if (buf == 0) |
558 | return 0; | |
559 | break; | |
560 | ||
561 | case 'X': | |
e9f284c9 | 562 | buf = _strptime(aTHX_ buf, Locale->X_fmt, tm, got_GMT); |
16433e2b SP |
563 | if (buf == 0) |
564 | return 0; | |
565 | break; | |
566 | ||
567 | case 'x': | |
e9f284c9 | 568 | buf = _strptime(aTHX_ buf, Locale->x_fmt, tm, got_GMT); |
16433e2b SP |
569 | if (buf == 0) |
570 | return 0; | |
571 | break; | |
572 | ||
573 | case 'j': | |
574 | if (!isdigit((unsigned char)*buf)) | |
575 | return 0; | |
576 | ||
577 | len = 3; | |
578 | for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { | |
579 | i *= 10; | |
580 | i += *buf - '0'; | |
581 | len--; | |
582 | } | |
583 | if (i < 1 || i > 366) | |
584 | return 0; | |
585 | ||
586 | tm->tm_yday = i - 1; | |
9bc7f50b | 587 | tm->tm_mday = 0; |
16433e2b SP |
588 | break; |
589 | ||
590 | case 'M': | |
591 | case 'S': | |
592 | if (*buf == 0 || isspace((unsigned char)*buf)) | |
593 | break; | |
594 | ||
595 | if (!isdigit((unsigned char)*buf)) | |
596 | return 0; | |
597 | ||
598 | len = 2; | |
599 | for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { | |
600 | i *= 10; | |
601 | i += *buf - '0'; | |
602 | len--; | |
603 | } | |
604 | ||
605 | if (c == 'M') { | |
606 | if (i > 59) | |
607 | return 0; | |
608 | tm->tm_min = i; | |
609 | } else { | |
610 | if (i > 60) | |
611 | return 0; | |
612 | tm->tm_sec = i; | |
613 | } | |
614 | ||
615 | if (*buf != 0 && isspace((unsigned char)*buf)) | |
616 | while (*ptr != 0 && !isspace((unsigned char)*ptr)) | |
617 | ptr++; | |
618 | break; | |
619 | ||
620 | case 'H': | |
621 | case 'I': | |
622 | case 'k': | |
623 | case 'l': | |
624 | /* | |
625 | * Of these, %l is the only specifier explicitly | |
626 | * documented as not being zero-padded. However, | |
627 | * there is no harm in allowing zero-padding. | |
628 | * | |
629 | * XXX The %l specifier may gobble one too many | |
630 | * digits if used incorrectly. | |
631 | */ | |
90d55c29 | 632 | if (!isdigit((unsigned char)*buf)) |
16433e2b SP |
633 | return 0; |
634 | ||
635 | len = 2; | |
636 | for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { | |
637 | i *= 10; | |
638 | i += *buf - '0'; | |
639 | len--; | |
640 | } | |
641 | if (c == 'H' || c == 'k') { | |
642 | if (i > 23) | |
643 | return 0; | |
644 | } else if (i > 12) | |
645 | return 0; | |
646 | ||
647 | tm->tm_hour = i; | |
648 | ||
649 | if (*buf != 0 && isspace((unsigned char)*buf)) | |
650 | while (*ptr != 0 && !isspace((unsigned char)*ptr)) | |
651 | ptr++; | |
652 | break; | |
653 | ||
654 | case 'p': | |
655 | /* | |
656 | * XXX This is bogus if parsed before hour-related | |
657 | * specifiers. | |
658 | */ | |
90d55c29 | 659 | len = strlen(Locale->am); |
16433e2b SP |
660 | if (strncasecmp(buf, Locale->am, len) == 0) { |
661 | if (tm->tm_hour > 12) | |
662 | return 0; | |
663 | if (tm->tm_hour == 12) | |
664 | tm->tm_hour = 0; | |
665 | buf += len; | |
666 | break; | |
667 | } | |
668 | ||
669 | len = strlen(Locale->pm); | |
670 | if (strncasecmp(buf, Locale->pm, len) == 0) { | |
671 | if (tm->tm_hour > 12) | |
672 | return 0; | |
673 | if (tm->tm_hour != 12) | |
674 | tm->tm_hour += 12; | |
675 | buf += len; | |
676 | break; | |
677 | } | |
678 | ||
679 | return 0; | |
680 | ||
681 | case 'A': | |
682 | case 'a': | |
683 | for (i = 0; i < asizeof(Locale->weekday); i++) { | |
684 | if (c == 'A') { | |
685 | len = strlen(Locale->weekday[i]); | |
686 | if (strncasecmp(buf, | |
687 | Locale->weekday[i], | |
688 | len) == 0) | |
689 | break; | |
690 | } else { | |
691 | len = strlen(Locale->wday[i]); | |
692 | if (strncasecmp(buf, | |
693 | Locale->wday[i], | |
694 | len) == 0) | |
695 | break; | |
696 | } | |
697 | } | |
698 | if (i == asizeof(Locale->weekday)) | |
699 | return 0; | |
700 | ||
701 | tm->tm_wday = i; | |
702 | buf += len; | |
703 | break; | |
704 | ||
705 | case 'U': | |
706 | case 'W': | |
707 | /* | |
708 | * XXX This is bogus, as we can not assume any valid | |
709 | * information present in the tm structure at this | |
710 | * point to calculate a real value, so just check the | |
711 | * range for now. | |
712 | */ | |
90d55c29 | 713 | if (!isdigit((unsigned char)*buf)) |
16433e2b SP |
714 | return 0; |
715 | ||
716 | len = 2; | |
717 | for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { | |
718 | i *= 10; | |
719 | i += *buf - '0'; | |
720 | len--; | |
721 | } | |
722 | if (i > 53) | |
723 | return 0; | |
724 | ||
725 | if (*buf != 0 && isspace((unsigned char)*buf)) | |
726 | while (*ptr != 0 && !isspace((unsigned char)*ptr)) | |
727 | ptr++; | |
728 | break; | |
729 | ||
730 | case 'w': | |
731 | if (!isdigit((unsigned char)*buf)) | |
732 | return 0; | |
733 | ||
734 | i = *buf - '0'; | |
735 | if (i > 6) | |
736 | return 0; | |
737 | ||
738 | tm->tm_wday = i; | |
739 | ||
740 | if (*buf != 0 && isspace((unsigned char)*buf)) | |
741 | while (*ptr != 0 && !isspace((unsigned char)*ptr)) | |
742 | ptr++; | |
743 | break; | |
744 | ||
745 | case 'd': | |
746 | case 'e': | |
747 | /* | |
748 | * The %e specifier is explicitly documented as not | |
749 | * being zero-padded but there is no harm in allowing | |
750 | * such padding. | |
751 | * | |
752 | * XXX The %e specifier may gobble one too many | |
753 | * digits if used incorrectly. | |
754 | */ | |
755 | if (!isdigit((unsigned char)*buf)) | |
756 | return 0; | |
757 | ||
758 | len = 2; | |
759 | for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { | |
760 | i *= 10; | |
761 | i += *buf - '0'; | |
762 | len--; | |
763 | } | |
764 | if (i > 31) | |
765 | return 0; | |
766 | ||
767 | tm->tm_mday = i; | |
768 | ||
769 | if (*buf != 0 && isspace((unsigned char)*buf)) | |
770 | while (*ptr != 0 && !isspace((unsigned char)*ptr)) | |
771 | ptr++; | |
772 | break; | |
773 | ||
774 | case 'B': | |
775 | case 'b': | |
776 | case 'h': | |
777 | for (i = 0; i < asizeof(Locale->month); i++) { | |
778 | if (Oalternative) { | |
779 | if (c == 'B') { | |
780 | len = strlen(Locale->alt_month[i]); | |
781 | if (strncasecmp(buf, | |
782 | Locale->alt_month[i], | |
783 | len) == 0) | |
784 | break; | |
785 | } | |
786 | } else { | |
787 | if (c == 'B') { | |
788 | len = strlen(Locale->month[i]); | |
789 | if (strncasecmp(buf, | |
790 | Locale->month[i], | |
791 | len) == 0) | |
792 | break; | |
793 | } else { | |
794 | len = strlen(Locale->mon[i]); | |
795 | if (strncasecmp(buf, | |
796 | Locale->mon[i], | |
797 | len) == 0) | |
798 | break; | |
799 | } | |
800 | } | |
801 | } | |
802 | if (i == asizeof(Locale->month)) | |
803 | return 0; | |
804 | ||
805 | tm->tm_mon = i; | |
806 | buf += len; | |
807 | break; | |
808 | ||
809 | case 'm': | |
810 | if (!isdigit((unsigned char)*buf)) | |
811 | return 0; | |
812 | ||
813 | len = 2; | |
814 | for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { | |
815 | i *= 10; | |
816 | i += *buf - '0'; | |
817 | len--; | |
818 | } | |
819 | if (i < 1 || i > 12) | |
820 | return 0; | |
821 | ||
822 | tm->tm_mon = i - 1; | |
823 | ||
824 | if (*buf != 0 && isspace((unsigned char)*buf)) | |
825 | while (*ptr != 0 && !isspace((unsigned char)*ptr)) | |
826 | ptr++; | |
827 | break; | |
828 | ||
90d55c29 CBW |
829 | case 's': |
830 | { | |
831 | char *cp; | |
832 | int sverrno; | |
833 | long n; | |
834 | time_t t; | |
835 | struct tm mytm; | |
836 | ||
837 | sverrno = errno; | |
838 | errno = 0; | |
839 | n = strtol(buf, &cp, 10); | |
840 | if (errno == ERANGE || (long)(t = n) != n) { | |
841 | errno = sverrno; | |
842 | return 0; | |
843 | } | |
844 | errno = sverrno; | |
845 | buf = cp; | |
846 | memset(&mytm, 0, sizeof(mytm)); | |
847 | my_init_tm(&mytm); /* XXX workaround - see my_init_tm() above */ | |
848 | mytm = *gmtime(&t); | |
849 | tm->tm_sec = mytm.tm_sec; | |
850 | tm->tm_min = mytm.tm_min; | |
851 | tm->tm_hour = mytm.tm_hour; | |
852 | tm->tm_mday = mytm.tm_mday; | |
853 | tm->tm_mon = mytm.tm_mon; | |
854 | tm->tm_year = mytm.tm_year; | |
855 | tm->tm_wday = mytm.tm_wday; | |
856 | tm->tm_yday = mytm.tm_yday; | |
857 | tm->tm_isdst = mytm.tm_isdst; | |
858 | } | |
859 | break; | |
860 | ||
16433e2b SP |
861 | case 'Y': |
862 | case 'y': | |
863 | if (*buf == 0 || isspace((unsigned char)*buf)) | |
864 | break; | |
865 | ||
866 | if (!isdigit((unsigned char)*buf)) | |
867 | return 0; | |
868 | ||
869 | len = (c == 'Y') ? 4 : 2; | |
870 | for (i = 0; len && *buf != 0 && isdigit((unsigned char)*buf); buf++) { | |
871 | i *= 10; | |
872 | i += *buf - '0'; | |
873 | len--; | |
874 | } | |
875 | if (c == 'Y') | |
876 | i -= 1900; | |
877 | if (c == 'y' && i < 69) | |
878 | i += 100; | |
879 | if (i < 0) | |
880 | return 0; | |
881 | ||
882 | tm->tm_year = i; | |
883 | ||
884 | if (*buf != 0 && isspace((unsigned char)*buf)) | |
885 | while (*ptr != 0 && !isspace((unsigned char)*ptr)) | |
886 | ptr++; | |
887 | break; | |
888 | ||
889 | case 'Z': | |
890 | { | |
891 | const char *cp; | |
892 | char *zonestr; | |
893 | ||
894 | for (cp = buf; *cp && isupper((unsigned char)*cp); ++cp) | |
895 | {/*empty*/} | |
896 | if (cp - buf) { | |
8a0cff69 | 897 | zonestr = (char *)malloc(cp - buf + 1); |
ded2eedc CB |
898 | if (!zonestr) { |
899 | errno = ENOMEM; | |
900 | return 0; | |
901 | } | |
16433e2b SP |
902 | strncpy(zonestr, buf, cp - buf); |
903 | zonestr[cp - buf] = '\0'; | |
12016aad | 904 | my_tzset(aTHX); |
16433e2b | 905 | if (0 == strcmp(zonestr, "GMT")) { |
e9f284c9 | 906 | *got_GMT = 1; |
16433e2b | 907 | } |
ded2eedc | 908 | free(zonestr); |
e9f284c9 | 909 | if (!*got_GMT) return 0; |
16433e2b SP |
910 | buf += cp - buf; |
911 | } | |
912 | } | |
913 | break; | |
90d55c29 CBW |
914 | |
915 | case 'z': | |
916 | { | |
917 | int sign = 1; | |
918 | ||
919 | if (*buf != '+') { | |
920 | if (*buf == '-') | |
921 | sign = -1; | |
922 | else | |
923 | return 0; | |
924 | } | |
925 | ||
926 | buf++; | |
927 | i = 0; | |
928 | for (len = 4; len > 0; len--) { | |
929 | if (isdigit((int)*buf)) { | |
930 | i *= 10; | |
931 | i += *buf - '0'; | |
932 | buf++; | |
933 | } else | |
934 | return 0; | |
935 | } | |
936 | ||
937 | tm->tm_hour -= sign * (i / 100); | |
938 | tm->tm_min -= sign * (i % 100); | |
e9f284c9 | 939 | *got_GMT = 1; |
90d55c29 CBW |
940 | } |
941 | break; | |
16433e2b SP |
942 | } |
943 | } | |
944 | return (char *)buf; | |
945 | } | |
946 | ||
947 | ||
948 | char * | |
90d55c29 | 949 | our_strptime(pTHX_ const char *buf, const char *fmt, struct tm *tm) |
16433e2b SP |
950 | { |
951 | char *ret; | |
e9f284c9 | 952 | int got_GMT = 0; |
16433e2b | 953 | |
e9f284c9 | 954 | return _strptime(aTHX_ buf, fmt, tm, &got_GMT); |
16433e2b SP |
955 | } |
956 | ||
16433e2b SP |
957 | MODULE = Time::Piece PACKAGE = Time::Piece |
958 | ||
959 | PROTOTYPES: ENABLE | |
960 | ||
9331e88f | 961 | void |
16433e2b SP |
962 | _strftime(fmt, sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1) |
963 | char * fmt | |
964 | int sec | |
965 | int min | |
966 | int hour | |
967 | int mday | |
968 | int mon | |
969 | int year | |
970 | int wday | |
971 | int yday | |
972 | int isdst | |
973 | CODE: | |
974 | { | |
975 | char tmpbuf[128]; | |
976 | struct tm mytm; | |
977 | int len; | |
978 | memset(&mytm, 0, sizeof(mytm)); | |
979 | my_init_tm(&mytm); /* XXX workaround - see my_init_tm() above */ | |
980 | mytm.tm_sec = sec; | |
981 | mytm.tm_min = min; | |
982 | mytm.tm_hour = hour; | |
983 | mytm.tm_mday = mday; | |
984 | mytm.tm_mon = mon; | |
985 | mytm.tm_year = year; | |
986 | mytm.tm_wday = wday; | |
987 | mytm.tm_yday = yday; | |
988 | mytm.tm_isdst = isdst; | |
989 | my_mini_mktime(&mytm); | |
990 | len = strftime(tmpbuf, sizeof tmpbuf, fmt, &mytm); | |
991 | /* | |
992 | ** The following is needed to handle to the situation where | |
993 | ** tmpbuf overflows. Basically we want to allocate a buffer | |
994 | ** and try repeatedly. The reason why it is so complicated | |
995 | ** is that getting a return value of 0 from strftime can indicate | |
996 | ** one of the following: | |
997 | ** 1. buffer overflowed, | |
998 | ** 2. illegal conversion specifier, or | |
999 | ** 3. the format string specifies nothing to be returned(not | |
1000 | ** an error). This could be because format is an empty string | |
1001 | ** or it specifies %p that yields an empty string in some locale. | |
1002 | ** If there is a better way to make it portable, go ahead by | |
1003 | ** all means. | |
1004 | */ | |
1005 | if ((len > 0 && len < sizeof(tmpbuf)) || (len == 0 && *fmt == '\0')) | |
1006 | ST(0) = sv_2mortal(newSVpv(tmpbuf, len)); | |
1007 | else { | |
1008 | /* Possibly buf overflowed - try again with a bigger buf */ | |
1009 | int fmtlen = strlen(fmt); | |
1010 | int bufsize = fmtlen + sizeof(tmpbuf); | |
1011 | char* buf; | |
1012 | int buflen; | |
1013 | ||
1014 | New(0, buf, bufsize, char); | |
1015 | while (buf) { | |
1016 | buflen = strftime(buf, bufsize, fmt, &mytm); | |
1017 | if (buflen > 0 && buflen < bufsize) | |
1018 | break; | |
1019 | /* heuristic to prevent out-of-memory errors */ | |
1020 | if (bufsize > 100*fmtlen) { | |
1021 | Safefree(buf); | |
1022 | buf = NULL; | |
1023 | break; | |
1024 | } | |
1025 | bufsize *= 2; | |
1026 | Renew(buf, bufsize, char); | |
1027 | } | |
1028 | if (buf) { | |
1029 | ST(0) = sv_2mortal(newSVpv(buf, buflen)); | |
1030 | Safefree(buf); | |
1031 | } | |
1032 | else | |
1033 | ST(0) = sv_2mortal(newSVpv(tmpbuf, len)); | |
1034 | } | |
1035 | } | |
1036 | ||
1037 | void | |
1038 | _tzset() | |
1039 | PPCODE: | |
12016aad | 1040 | my_tzset(aTHX); |
16433e2b SP |
1041 | |
1042 | ||
1043 | void | |
1044 | _strptime ( string, format ) | |
1045 | char * string | |
1046 | char * format | |
1047 | PREINIT: | |
16433e2b SP |
1048 | struct tm mytm; |
1049 | time_t t; | |
1050 | char * remainder; | |
16433e2b SP |
1051 | PPCODE: |
1052 | t = 0; | |
1053 | mytm = *gmtime(&t); | |
90d55c29 | 1054 | remainder = (char *)our_strptime(aTHX_ string, format, &mytm); |
16433e2b | 1055 | if (remainder == NULL) { |
90d55c29 | 1056 | croak("Error parsing time"); |
16433e2b | 1057 | } |
16433e2b SP |
1058 | if (*remainder != '\0') { |
1059 | warn("garbage at end of string in strptime: %s", remainder); | |
1060 | } | |
1061 | ||
1062 | my_mini_mktime(&mytm); | |
1063 | ||
1064 | /* warn("tm: %d-%d-%d %d:%d:%d\n", mytm.tm_year, mytm.tm_mon, mytm.tm_mday, mytm.tm_hour, mytm.tm_min, mytm.tm_sec); */ | |
1065 | ||
1066 | EXTEND(SP, 11); | |
1067 | PUSHs(sv_2mortal(newSViv(mytm.tm_sec))); | |
1068 | PUSHs(sv_2mortal(newSViv(mytm.tm_min))); | |
1069 | PUSHs(sv_2mortal(newSViv(mytm.tm_hour))); | |
1070 | PUSHs(sv_2mortal(newSViv(mytm.tm_mday))); | |
1071 | PUSHs(sv_2mortal(newSViv(mytm.tm_mon))); | |
1072 | PUSHs(sv_2mortal(newSViv(mytm.tm_year))); | |
1073 | PUSHs(sv_2mortal(newSViv(mytm.tm_wday))); | |
1074 | PUSHs(sv_2mortal(newSViv(mytm.tm_yday))); | |
1075 | /* isdst */ | |
1076 | PUSHs(sv_2mortal(newSViv(0))); | |
1077 | /* epoch */ | |
1078 | PUSHs(sv_2mortal(newSViv(0))); | |
1079 | /* islocal */ | |
1080 | PUSHs(sv_2mortal(newSViv(0))); | |
3df1a9e2 GA |
1081 | |
1082 | void | |
1083 | _mini_mktime(int sec, int min, int hour, int mday, int mon, int year) | |
1084 | PREINIT: | |
1085 | struct tm mytm; | |
1086 | time_t t; | |
1087 | PPCODE: | |
1088 | t = 0; | |
1089 | mytm = *gmtime(&t); | |
1090 | ||
1091 | mytm.tm_sec = sec; | |
1092 | mytm.tm_min = min; | |
1093 | mytm.tm_hour = hour; | |
1094 | mytm.tm_mday = mday; | |
1095 | mytm.tm_mon = mon; | |
1096 | mytm.tm_year = year; | |
1097 | ||
1098 | my_mini_mktime(&mytm); | |
1099 | ||
1100 | EXTEND(SP, 11); | |
1101 | PUSHs(sv_2mortal(newSViv(mytm.tm_sec))); | |
1102 | PUSHs(sv_2mortal(newSViv(mytm.tm_min))); | |
1103 | PUSHs(sv_2mortal(newSViv(mytm.tm_hour))); | |
1104 | PUSHs(sv_2mortal(newSViv(mytm.tm_mday))); | |
1105 | PUSHs(sv_2mortal(newSViv(mytm.tm_mon))); | |
1106 | PUSHs(sv_2mortal(newSViv(mytm.tm_year))); | |
1107 | PUSHs(sv_2mortal(newSViv(mytm.tm_wday))); | |
1108 | PUSHs(sv_2mortal(newSViv(mytm.tm_yday))); | |
1109 | /* isdst */ | |
1110 | PUSHs(sv_2mortal(newSViv(0))); | |
1111 | /* epoch */ | |
1112 | PUSHs(sv_2mortal(newSViv(0))); | |
1113 | /* islocal */ | |
1114 | PUSHs(sv_2mortal(newSViv(0))); | |
90d55c29 CBW |
1115 | |
1116 | void | |
1117 | _crt_localtime(time_t sec) | |
1118 | PREINIT: | |
1119 | struct tm mytm; | |
1120 | PPCODE: | |
1121 | mytm = *localtime(&sec); | |
1122 | /* Need to get: $s,$n,$h,$d,$m,$y */ | |
1123 | ||
1124 | EXTEND(SP, 9); | |
1125 | PUSHs(sv_2mortal(newSViv(mytm.tm_sec))); | |
1126 | PUSHs(sv_2mortal(newSViv(mytm.tm_min))); | |
1127 | PUSHs(sv_2mortal(newSViv(mytm.tm_hour))); | |
1128 | PUSHs(sv_2mortal(newSViv(mytm.tm_mday))); | |
1129 | PUSHs(sv_2mortal(newSViv(mytm.tm_mon))); | |
1130 | PUSHs(sv_2mortal(newSViv(mytm.tm_year))); | |
1131 | PUSHs(sv_2mortal(newSViv(mytm.tm_year))); | |
1132 | PUSHs(sv_2mortal(newSViv(mytm.tm_wday))); | |
1133 | PUSHs(sv_2mortal(newSViv(mytm.tm_yday))); | |
1134 | PUSHs(sv_2mortal(newSViv(mytm.tm_isdst))); | |
1135 | ||
1136 | void | |
1137 | _crt_gmtime(time_t sec) | |
1138 | PREINIT: | |
1139 | struct tm mytm; | |
1140 | PPCODE: | |
1141 | mytm = *gmtime(&sec); | |
1142 | /* Need to get: $s,$n,$h,$d,$m,$y */ | |
1143 | ||
1144 | EXTEND(SP, 9); | |
1145 | PUSHs(sv_2mortal(newSViv(mytm.tm_sec))); | |
1146 | PUSHs(sv_2mortal(newSViv(mytm.tm_min))); | |
1147 | PUSHs(sv_2mortal(newSViv(mytm.tm_hour))); | |
1148 | PUSHs(sv_2mortal(newSViv(mytm.tm_mday))); | |
1149 | PUSHs(sv_2mortal(newSViv(mytm.tm_mon))); | |
1150 | PUSHs(sv_2mortal(newSViv(mytm.tm_year))); | |
1151 | PUSHs(sv_2mortal(newSViv(mytm.tm_wday))); | |
1152 | PUSHs(sv_2mortal(newSViv(mytm.tm_yday))); | |
1153 | PUSHs(sv_2mortal(newSViv(mytm.tm_isdst))); | |
1154 |