Ruby 2.7.0p0(2019-12-25revision647ee6f091eafcce70ffb75ddf7e121e192ab217)

strftime.c
Go to the documentation of this file.
1 /* -*- c-file-style: "linux" -*- */
2
3 /*
4 * strftime.c
5 *
6 * Public-domain implementation of ANSI C library routine.
7 *
8 * It's written in old-style C for maximal portability.
9 * However, since I'm used to prototypes, I've included them too.
10 *
11 * If you want stuff in the System V ascftime routine, add the SYSV_EXT define.
12 * For extensions from SunOS, add SUNOS_EXT.
13 * For stuff needed to implement the P1003.2 date command, add POSIX2_DATE.
14 * For VMS dates, add VMS_EXT.
15 * For a an RFC822 time format, add MAILHEADER_EXT.
16 * For ISO week years, add ISO_DATE_EXT.
17 * For complete POSIX semantics, add POSIX_SEMANTICS.
18 *
19 * The code for %c, %x, and %X now follows the 1003.2 specification for
20 * the POSIX locale.
21 * This version ignores LOCALE information.
22 * It also doesn't worry about multi-byte characters.
23 * So there.
24 *
25 * This file is also shipped with GAWK (GNU Awk), gawk specific bits of
26 * code are included if GAWK is defined.
27 *
28 * Arnold Robbins
29 * January, February, March, 1991
30 * Updated March, April 1992
31 * Updated April, 1993
32 * Updated February, 1994
33 * Updated May, 1994
34 * Updated January, 1995
35 * Updated September, 1995
36 * Updated January, 1996
37 *
38 * Fixes from ado@elsie.nci.nih.gov
39 * February 1991, May 1992
40 * Fixes from Tor Lillqvist tml@tik.vtt.fi
41 * May, 1993
42 * Further fixes from ado@elsie.nci.nih.gov
43 * February 1994
44 * %z code from chip@chinacat.unicom.com
45 * Applied September 1995
46 * %V code fixed (again) and %G, %g added,
47 * January 1996
48 */
49
50 #include "ruby/ruby.h"
51 #include "ruby/encoding.h"
52 #include "timev.h"
53 #include "internal.h"
54
55 #ifndef GAWK
56 #include <stdio.h>
57 #include <ctype.h>
58 #include <string.h>
59 #include <time.h>
60 #include <sys/types.h>
61 #include <errno.h>
62 #endif
63 #if defined(TM_IN_SYS_TIME) || !defined(GAWK)
64 #include <sys/types.h>
65 #if HAVE_SYS_TIME_H
66 #include <sys/time.h>
67 #endif
68 #endif
69 #include <math.h>
70
71 /* defaults: season to taste */
72 #define SYSV_EXT 1 /* stuff in System V ascftime routine */
73 #define SUNOS_EXT 1 /* stuff in SunOS strftime routine */
74 #define POSIX2_DATE 1 /* stuff in Posix 1003.2 date command */
75 #define VMS_EXT 1 /* include %v for VMS date format */
76 #define MAILHEADER_EXT 1 /* add %z for HHMM format */
77 #define ISO_DATE_EXT 1 /* %G and %g for year of ISO week */
78
79 #if defined(ISO_DATE_EXT)
80 #if ! defined(POSIX2_DATE)
81 #define POSIX2_DATE 1
82 #endif
83 #endif
84
85 #if defined(POSIX2_DATE)
86 #if ! defined(SYSV_EXT)
87 #define SYSV_EXT 1
88 #endif
89 #if ! defined(SUNOS_EXT)
90 #define SUNOS_EXT 1
91 #endif
92 #endif
93
94 #if defined(POSIX2_DATE)
95 #define adddecl(stuff) stuff
96 #else
97 #define adddecl(stuff)
98 #endif
99
100 #undef strchr /* avoid AIX weirdness */
101
102 #if !defined __STDC__ && !defined _WIN32
103 #define const
104 static int weeknumber();
105 adddecl(static int iso8601wknum();)
106 static int weeknumber_v();
107 adddecl(static int iso8601wknum_v();)
108 #else
109 static int weeknumber(const struct tm *timeptr, int firstweekday);
110 adddecl(static int iso8601wknum(const struct tm *timeptr);)
111 static int weeknumber_v(const struct vtm *vtm, int firstweekday);
112 adddecl(static int iso8601wknum_v(const struct vtm *vtm);)
113 #endif
114
115 #ifdef STDC_HEADERS
116 #include <stdlib.h>
117 #include <string.h>
118 #else
119 extern void *malloc();
120 extern void *realloc();
121 extern char *getenv();
122 extern char *strchr();
123 #endif
124
125 #define range(low, item, hi) max((low), min((item), (hi)))
126
127 #undef min /* just in case */
128
129 /* min --- return minimum of two numbers */
130
131 static inline int
132 min(int a, int b)
133 {
134 return (a < b ? a : b);
135 }
136
137 #undef max /* also, just in case */
138
139 /* max --- return maximum of two numbers */
140
141 static inline int
142 max(int a, int b)
143 {
144 return (a > b ? a : b);
145 }
146
147 #ifdef NO_STRING_LITERAL_CONCATENATION
148 #error No string literal concatenation
149 #endif
150
151 #define add(x,y) (rb_funcall((x), '+', 1, (y)))
152 #define sub(x,y) (rb_funcall((x), '-', 1, (y)))
153 #define mul(x,y) (rb_funcall((x), '*', 1, (y)))
154 #define quo(x,y) (rb_funcall((x), rb_intern("quo"), 1, (y)))
155 #define div(x,y) (rb_funcall((x), rb_intern("div"), 1, (y)))
156 #define mod(x,y) (rb_funcall((x), '%', 1, (y)))
157
158 /* strftime --- produce formatted time */
159
160 enum {LEFT, CHCASE, LOWER, UPPER};
161 #define BIT_OF(n) (1U<<(n))
162
163 static char *
164 resize_buffer(VALUE ftime, char *s, const char **start, const char **endp,
165 ptrdiff_t n, size_t maxsize)
166 {
167 size_t len = s - *start;
168 size_t nlen = len + n * 2;
169
170 if (nlen < len || nlen > maxsize) {
171 return 0;
172 }
173 rb_str_set_len(ftime, len);
174 rb_str_modify_expand(ftime, nlen-len);
175 s = RSTRING_PTR(ftime);
176 *endp = s + nlen;
177 *start = s;
178 return s += len;
179 }
180
181 static void
182 buffer_size_check(const char *s,
183 const char *format_end, size_t format_len,
184 rb_encoding *enc)
185 {
186 if (!s) {
187 const char *format = format_end-format_len;
188 VALUE fmt = rb_enc_str_new(format, format_len, enc);
189 rb_syserr_fail_str(ERANGE, fmt);
190 }
191 }
192
193 static char *
194 case_conv(char *s, ptrdiff_t i, int flags)
195 {
196 switch (flags & (BIT_OF(UPPER)|BIT_OF(LOWER))) {
197 case BIT_OF(UPPER):
198 do {
199 if (ISLOWER(*s)) *s = TOUPPER(*s);
200 } while (s++, --i);
201 break;
202 case BIT_OF(LOWER):
203 do {
204 if (ISUPPER(*s)) *s = TOLOWER(*s);
205 } while (s++, --i);
206 break;
207 default:
208 s += i;
209 break;
210 }
211 return s;
212 }
213
214 static VALUE
215 format_value(VALUE val, int base)
216 {
217 if (!RB_TYPE_P(val, T_BIGNUM))
218 val = rb_Integer(val);
219 return rb_big2str(val, base);
220 }
221
222 /*
223 * enc is the encoding of the format. It is used as the encoding of resulted
224 * string, but the name of the month and weekday are always US-ASCII. So it
225 * is only used for the timezone name on Windows.
226 */
227 static VALUE
228 rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len,
229 rb_encoding *enc, VALUE time, const struct vtm *vtm,
230 VALUE timev, struct timespec *ts, int gmt, size_t maxsize)
231 {
232 size_t len = RSTRING_LEN(ftime);
233 char *s = RSTRING_PTR(ftime);
234 const char *start = s;
235 const char *endp = start + rb_str_capacity(ftime);
236 const char *const format_end = format + format_len;
237 const char *sp, *tp;
238 #define TBUFSIZE 100
239 auto char tbuf[TBUFSIZE];
240 long off;
241 ptrdiff_t i;
242 int w;
243 long y;
244 int precision, flags, colons;
245 char padding;
246 #ifdef MAILHEADER_EXT
247 int sign;
248 #endif
249 VALUE zone = Qnil;
250
251 /* various tables, useful in North America */
252 static const char days_l[][10] = {
253 "Sunday", "Monday", "Tuesday", "Wednesday",
254 "Thursday", "Friday", "Saturday",
255 };
256 static const char months_l[][10] = {
257 "January", "February", "March", "April",
258 "May", "June", "July", "August", "September",
259 "October", "November", "December",
260 };
261 static const char ampm[][3] = { "AM", "PM", };
262
263 if (format == NULL || format_len == 0 || vtm == NULL) {
264 err:
265 return 0;
266 }
267
268 if (enc &&
269 (enc == rb_usascii_encoding() ||
270 enc == rb_ascii8bit_encoding() ||
271 enc == rb_locale_encoding())) {
272 enc = NULL;
273 }
274
275 s += len;
276 for (; format < format_end; format++) {
277 #define FLAG_FOUND() do { \
278 if (precision > 0) \
279 goto unknown; \
280 } while (0)
281 #define NEEDS(n) do { \
282 if (s >= endp || (n) >= endp - s - 1) { \
283 s = resize_buffer(ftime, s, &start, &endp, (n), maxsize); \
284 buffer_size_check(s, format_end, format_len, enc); \
285 } \
286 } while (0)
287 #define FILL_PADDING(i) do { \
288 if (!(flags & BIT_OF(LEFT)) && precision > (i)) { \
289 NEEDS(precision); \
290 memset(s, padding ? padding : ' ', precision - (i)); \
291 s += precision - (i); \
292 } \
293 else { \
294 NEEDS(i); \
295 } \
296 } while (0);
297 #define FMT_PADDING(fmt, def_pad) \
298 (&"%*"fmt"\0""%0*"fmt[\
299 (padding == '0' || (!padding && (def_pad) == '0')) ? \
300 rb_strlen_lit("%*"fmt)+1 : 0])
301 #define FMT_PRECISION(def_prec) \
302 ((flags & BIT_OF(LEFT)) ? (1) : \
303 (precision <= 0) ? (def_prec) : (precision))
304 #define FMT(def_pad, def_prec, fmt, val) \
305 do { \
306 precision = FMT_PRECISION(def_prec); \
307 len = s - start; \
308 NEEDS(precision); \
309 rb_str_set_len(ftime, len); \
310 rb_str_catf(ftime, FMT_PADDING(fmt, def_pad), \
311 precision, (val)); \
312 RSTRING_GETMEM(ftime, s, len); \
313 endp = (start = s) + rb_str_capacity(ftime); \
314 s += len; \
315 } while (0)
316 #define STRFTIME(fmt) \
317 do { \
318 len = s - start; \
319 rb_str_set_len(ftime, len); \
320 if (!rb_strftime_with_timespec(ftime, (fmt), rb_strlen_lit(fmt), \
321 enc, time, vtm, timev, ts, gmt, maxsize)) \
322 return 0; \
323 s = RSTRING_PTR(ftime); \
324 i = RSTRING_LEN(ftime) - len; \
325 endp = (start = s) + rb_str_capacity(ftime); \
326 s += len; \
327 if (i > 0) case_conv(s, i, flags); \
328 if (precision > i) {\
329 NEEDS(precision); \
330 memmove(s + precision - i, s, i);\
331 memset(s, padding ? padding : ' ', precision - i); \
332 s += precision; \
333 } \
334 else s += i; \
335 } while (0)
336 #define FMTV(def_pad, def_prec, fmt, val) \
337 do { \
338 VALUE tmp = (val); \
339 if (FIXNUM_P(tmp)) { \
340 FMT((def_pad), (def_prec), "l"fmt, FIX2LONG(tmp)); \
341 } \
342 else { \
343 const int base = ((fmt[0] == 'x') ? 16 : \
344 (fmt[0] == 'o') ? 8 : \
345 10); \
346 precision = FMT_PRECISION(def_prec); \
347 if (!padding) padding = (def_pad); \
348 tmp = format_value(tmp, base); \
349 i = RSTRING_LEN(tmp); \
350 FILL_PADDING(i); \
351 rb_str_set_len(ftime, s-start); \
352 rb_str_append(ftime, tmp); \
353 RSTRING_GETMEM(ftime, s, len); \
354 endp = (start = s) + rb_str_capacity(ftime); \
355 s += len; \
356 } \
357 } while (0)
358
359 tp = memchr(format, '%', format_end - format);
360 if (!tp) tp = format_end;
361 NEEDS(tp - format);
362 memcpy(s, format, tp - format);
363 s += tp - format;
364 format = tp;
365 if (format == format_end) break;
366
367 tp = tbuf;
368 sp = format;
369 precision = -1;
370 flags = 0;
371 padding = 0;
372 colons = 0;
373 again:
374 if (++format >= format_end) goto unknown;
375 switch (*format) {
376 case '%':
377 FILL_PADDING(1);
378 *s++ = '%';
379 continue;
380
381 case 'a': /* abbreviated weekday name */
382 if (flags & BIT_OF(CHCASE)) {
383 flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE));
384 flags |= BIT_OF(UPPER);
385 }
386 if (vtm->wday < 0 || vtm->wday > 6)
387 i = 1, tp = "?";
388 else
389 i = 3, tp = days_l[vtm->wday];
390 break;
391
392 case 'A': /* full weekday name */
393 if (flags & BIT_OF(CHCASE)) {
394 flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE));
395 flags |= BIT_OF(UPPER);
396 }
397 if (vtm->wday < 0 || vtm->wday > 6)
398 i = 1, tp = "?";
399 else
400 i = strlen(tp = days_l[vtm->wday]);
401 break;
402
403 #ifdef SYSV_EXT
404 case 'h': /* abbreviated month name */
405 #endif
406 case 'b': /* abbreviated month name */
407 if (flags & BIT_OF(CHCASE)) {
408 flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE));
409 flags |= BIT_OF(UPPER);
410 }
411 if (vtm->mon < 1 || vtm->mon > 12)
412 i = 1, tp = "?";
413 else
414 i = 3, tp = months_l[vtm->mon-1];
415 break;
416
417 case 'B': /* full month name */
418 if (flags & BIT_OF(CHCASE)) {
419 flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE));
420 flags |= BIT_OF(UPPER);
421 }
422 if (vtm->mon < 1 || vtm->mon > 12)
423 i = 1, tp = "?";
424 else
425 i = strlen(tp = months_l[vtm->mon-1]);
426 break;
427
428 case 'c': /* appropriate date and time representation */
429 STRFTIME("%a %b %e %H:%M:%S %Y");
430 continue;
431
432 case 'd': /* day of the month, 01 - 31 */
433 i = range(1, vtm->mday, 31);
434 FMT('0', 2, "d", (int)i);
435 continue;
436
437 case 'H': /* hour, 24-hour clock, 00 - 23 */
438 i = range(0, vtm->hour, 23);
439 FMT('0', 2, "d", (int)i);
440 continue;
441
442 case 'I': /* hour, 12-hour clock, 01 - 12 */
443 i = range(0, vtm->hour, 23);
444 if (i == 0)
445 i = 12;
446 else if (i > 12)
447 i -= 12;
448 FMT('0', 2, "d", (int)i);
449 continue;
450
451 case 'j': /* day of the year, 001 - 366 */
452 i = range(1, vtm->yday, 366);
453 FMT('0', 3, "d", (int)i);
454 continue;
455
456 case 'm': /* month, 01 - 12 */
457 i = range(1, vtm->mon, 12);
458 FMT('0', 2, "d", (int)i);
459 continue;
460
461 case 'M': /* minute, 00 - 59 */
462 i = range(0, vtm->min, 59);
463 FMT('0', 2, "d", (int)i);
464 continue;
465
466 case 'p': /* AM or PM based on 12-hour clock */
467 case 'P': /* am or pm based on 12-hour clock */
468 if ((*format == 'p' && (flags & BIT_OF(CHCASE))) ||
469 (*format == 'P' && !(flags & (BIT_OF(CHCASE)|BIT_OF(UPPER))))) {
470 flags &= ~(BIT_OF(UPPER)|BIT_OF(CHCASE));
471 flags |= BIT_OF(LOWER);
472 }
473 i = range(0, vtm->hour, 23);
474 if (i < 12)
475 tp = ampm[0];
476 else
477 tp = ampm[1];
478 i = 2;
479 break;
480
481 case 's':
482 if (ts) {
483 time_t sec = ts->tv_sec;
484 if (~(time_t)0 <= 0)
485 FMT('0', 1, PRI_TIMET_PREFIX"d", sec);
486 else
487 FMT('0', 1, PRI_TIMET_PREFIX"u", sec);
488 }
489 else {
490 VALUE sec = div(timev, INT2FIX(1));
491 FMTV('0', 1, "d", sec);
492 }
493 continue;
494
495 case 'S': /* second, 00 - 60 */
496 i = range(0, vtm->sec, 60);
497 FMT('0', 2, "d", (int)i);
498 continue;
499
500 case 'U': /* week of year, Sunday is first day of week */
501 FMT('0', 2, "d", weeknumber_v(vtm, 0));
502 continue;
503
504 case 'w': /* weekday, Sunday == 0, 0 - 6 */
505 i = range(0, vtm->wday, 6);
506 FMT('0', 1, "d", (int)i);
507 continue;
508
509 case 'W': /* week of year, Monday is first day of week */
510 FMT('0', 2, "d", weeknumber_v(vtm, 1));
511 continue;
512
513 case 'x': /* appropriate date representation */
514 STRFTIME("%m/%d/%y");
515 continue;
516
517 case 'X': /* appropriate time representation */
518 STRFTIME("%H:%M:%S");
519 continue;
520
521 case 'y': /* year without a century, 00 - 99 */
522 i = NUM2INT(mod(vtm->year, INT2FIX(100)));
523 FMT('0', 2, "d", (int)i);
524 continue;
525
526 case 'Y': /* year with century */
527 if (FIXNUM_P(vtm->year)) {
528 long y = FIX2LONG(vtm->year);
529 FMT('0', 0 <= y ? 4 : 5, "ld", y);
530 }
531 else {
532 FMTV('0', 4, "d", vtm->year);
533 }
534 continue;
535
536 #ifdef MAILHEADER_EXT
537 case 'z': /* time zone offset east of GMT e.g. -0600 */
538 if (gmt) {
539 off = 0;
540 }
541 else {
542 off = NUM2LONG(rb_funcall(vtm->utc_offset, rb_intern("round"), 0));
543 }
544 if (off < 0) {
545 off = -off;
546 sign = -1;
547 }
548 else {
549 sign = +1;
550 }
551 switch (colons) {
552 case 0: /* %z -> +hhmm */
553 precision = precision <= 5 ? 2 : precision-3;
554 NEEDS(precision + 3);
555 break;
556
557 case 1: /* %:z -> +hh:mm */
558 precision = precision <= 6 ? 2 : precision-4;
559 NEEDS(precision + 4);
560 break;
561
562 case 2: /* %::z -> +hh:mm:ss */
563 precision = precision <= 9 ? 2 : precision-7;
564 NEEDS(precision + 7);
565 break;
566
567 case 3: /* %:::z -> +hh[:mm[:ss]] */
568 if (off % 3600 == 0) {
569 precision = precision <= 3 ? 2 : precision-1;
570 NEEDS(precision + 3);
571 }
572 else if (off % 60 == 0) {
573 precision = precision <= 6 ? 2 : precision-4;
574 NEEDS(precision + 4);
575 }
576 else {
577 precision = precision <= 9 ? 2 : precision-7;
578 NEEDS(precision + 9);
579 }
580 break;
581
582 default:
583 format--;
584 goto unknown;
585 }
586 i = snprintf(s, endp - s, (padding == ' ' ? "%+*ld" : "%+.*ld"),
587 precision + (padding == ' '), sign * (off / 3600));
588 if (i < 0) goto err;
589 if (sign < 0 && off < 3600) {
590 *(padding == ' ' ? s + i - 2 : s) = '-';
591 }
592 s += i;
593 off = off % 3600;
594 if (colons == 3 && off == 0)
595 continue;
596 if (1 <= colons)
597 *s++ = ':';
598 i = snprintf(s, endp - s, "%02d", (int)(off / 60));
599 if (i < 0) goto err;
600 s += i;
601 off = off % 60;
602 if (colons == 3 && off == 0)
603 continue;
604 if (2 <= colons) {
605 *s++ = ':';
606 i = snprintf(s, endp - s, "%02d", (int)off);
607 if (i < 0) goto err;
608 s += i;
609 }
610 continue;
611 #endif /* MAILHEADER_EXT */
612
613 case 'Z': /* time zone name or abbreviation */
614 if (flags & BIT_OF(CHCASE)) {
615 flags &= ~(BIT_OF(UPPER)|BIT_OF(CHCASE));
616 flags |= BIT_OF(LOWER);
617 }
618 if (gmt) {
619 i = 3;
620 tp = "UTC";
621 break;
622 }
623 if (NIL_P(vtm->zone)) {
624 i = 0;
625 }
626 else {
627 if (NIL_P(zone)) {
628 zone = rb_time_zone_abbreviation(vtm->zone, time);
629 }
630 tp = RSTRING_PTR(zone);
631 if (enc) {
632 for (i = 0; i < TBUFSIZE && tp[i]; i++) {
633 if ((unsigned char)tp[i] > 0x7F) {
634 VALUE str = rb_str_conv_enc_opts(rb_str_new_cstr(tp), rb_locale_encoding(), enc, ECONV_UNDEF_REPLACE|ECONV_INVALID_REPLACE, Qnil);
635 i = strlcpy(tbuf, RSTRING_PTR(str), TBUFSIZE);
636 tp = tbuf;
637 break;
638 }
639 }
640 }
641 else
642 i = strlen(tp);
643 }
644 break;
645
646 #ifdef SYSV_EXT
647 case 'n': /* same as \n */
648 FILL_PADDING(1);
649 *s++ = '\n';
650 continue;
651
652 case 't': /* same as \t */
653 FILL_PADDING(1);
654 *s++ = '\t';
655 continue;
656
657 case 'D': /* date as %m/%d/%y */
658 STRFTIME("%m/%d/%y");
659 continue;
660
661 case 'e': /* day of month, blank padded */
662 FMT(' ', 2, "d", range(1, vtm->mday, 31));
663 continue;
664
665 case 'r': /* time as %I:%M:%S %p */
666 STRFTIME("%I:%M:%S %p");
667 continue;
668
669 case 'R': /* time as %H:%M */
670 STRFTIME("%H:%M");
671 continue;
672
673 case 'T': /* time as %H:%M:%S */
674 STRFTIME("%H:%M:%S");
675 continue;
676 #endif
677
678 #ifdef SUNOS_EXT
679 case 'k': /* hour, 24-hour clock, blank pad */
680 i = range(0, vtm->hour, 23);
681 FMT(' ', 2, "d", (int)i);
682 continue;
683
684 case 'l': /* hour, 12-hour clock, 1 - 12, blank pad */
685 i = range(0, vtm->hour, 23);
686 if (i == 0)
687 i = 12;
688 else if (i > 12)
689 i -= 12;
690 FMT(' ', 2, "d", (int)i);
691 continue;
692 #endif
693
694
695 #ifdef VMS_EXT
696 case 'v': /* date as dd-bbb-YYYY */
697 STRFTIME("%e-%^b-%4Y");
698 continue;
699 #endif
700
701
702 #ifdef POSIX2_DATE
703 case 'C':
704 FMTV('0', 2, "d", div(vtm->year, INT2FIX(100)));
705 continue;
706
707 case 'E':
708 /* POSIX locale extensions, ignored for now */
709 if (!format[1] || !strchr("cCxXyY", format[1]))
710 goto unknown;
711 goto again;
712 case 'O':
713 /* POSIX locale extensions, ignored for now */
714 if (!format[1] || !strchr("deHkIlmMSuUVwWy", format[1]))
715 goto unknown;
716 goto again;
717
718 case 'V': /* week of year according ISO 8601 */
719 FMT('0', 2, "d", iso8601wknum_v(vtm));
720 continue;
721
722 case 'u':
723 /* ISO 8601: Weekday as a decimal number [1 (Monday) - 7] */
724 FMT('0', 1, "d", vtm->wday == 0 ? 7 : vtm->wday);
725 continue;
726 #endif /* POSIX2_DATE */
727
728 #ifdef ISO_DATE_EXT
729 case 'G':
730 case 'g':
731 /*
732 * Year of ISO week.
733 *
734 * If it's December but the ISO week number is one,
735 * that week is in next year.
736 * If it's January but the ISO week number is 52 or
737 * 53, that week is in last year.
738 * Otherwise, it's this year.
739 */
740 {
741 VALUE yv = vtm->year;
742 w = iso8601wknum_v(vtm);
743 if (vtm->mon == 12 && w == 1)
744 yv = add(yv, INT2FIX(1));
745 else if (vtm->mon == 1 && w >= 52)
746 yv = sub(yv, INT2FIX(1));
747
748 if (*format == 'G') {
749 if (FIXNUM_P(yv)) {
750 const long y = FIX2LONG(yv);
751 FMT('0', 0 <= y ? 4 : 5, "ld", y);
752 }
753 else {
754 FMTV('0', 4, "d", yv);
755 }
756 }
757 else {
758 yv = mod(yv, INT2FIX(100));
759 y = FIX2LONG(yv);
760 FMT('0', 2, "ld", y);
761 }
762 continue;
763 }
764
765 #endif /* ISO_DATE_EXT */
766
767
768 case 'L':
769 w = 3;
770 goto subsec;
771
772 case 'N':
773 /*
774 * fractional second digits. default is 9 digits
775 * (nanosecond).
776 *
777 * %3N millisecond (3 digits)
778 * %6N microsecond (6 digits)
779 * %9N nanosecond (9 digits)
780 */
781 w = 9;
782 subsec:
783 if (precision <= 0) {
784 precision = w;
785 }
786 NEEDS(precision);
787
788 if (ts) {
789 long subsec = ts->tv_nsec;
790 if (9 < precision) {
791 snprintf(s, endp - s, "%09ld", subsec);
792 memset(s+9, '0', precision-9);
793 s += precision;
794 }
795 else {
796 int i;
797 for (i = 0; i < 9-precision; i++)
798 subsec /= 10;
799 snprintf(s, endp - s, "%0*ld", precision, subsec);
800 s += precision;
801 }
802 }
803 else {
804 VALUE subsec = mod(timev, INT2FIX(1));
805 int ww;
806 long n;
807
808 ww = precision;
809 while (9 <= ww) {
810 subsec = mul(subsec, INT2FIX(1000000000));
811 ww -= 9;
812 }
813 n = 1;
814 for (; 0 < ww; ww--)
815 n *= 10;
816 if (n != 1)
817 subsec = mul(subsec, INT2FIX(n));
818 subsec = div(subsec, INT2FIX(1));
819
820 if (FIXNUM_P(subsec)) {
821 (void)snprintf(s, endp - s, "%0*ld", precision, FIX2LONG(subsec));
822 s += precision;
823 }
824 else {
825 VALUE args[2], result;
826 args[0] = INT2FIX(precision);
827 args[1] = subsec;
828 result = rb_str_format(2, args,
829 rb_fstring_lit("%0*d"));
830 (void)strlcpy(s, StringValueCStr(result), endp-s);
831 s += precision;
832 }
833 }
834 continue;
835
836 case 'F': /* Equivalent to %Y-%m-%d */
837 STRFTIME("%Y-%m-%d");
838 continue;
839
840 case '-':
841 FLAG_FOUND();
842 flags |= BIT_OF(LEFT);
843 padding = precision = 0;
844 goto again;
845
846 case '^':
847 FLAG_FOUND();
848 flags |= BIT_OF(UPPER);
849 goto again;
850
851 case '#':
852 FLAG_FOUND();
853 flags |= BIT_OF(CHCASE);
854 goto again;
855
856 case '_':
857 FLAG_FOUND();
858 padding = ' ';
859 goto again;
860
861 case ':':
862 for (colons = 1; colons <= 3; ++colons) {
863 if (format+colons >= format_end) goto unknown;
864 if (format[colons] == 'z') break;
865 if (format[colons] != ':') goto unknown;
866 }
867 format += colons - 1;
868 goto again;
869
870 case '0':
871 padding = '0';
872 case '1': case '2': case '3': case '4':
873 case '5': case '6': case '7': case '8': case '9':
874 {
875 size_t n;
876 int ov;
877 unsigned long u = ruby_scan_digits(format, format_end-format, 10, &n, &ov);
878 if (ov || u > INT_MAX) goto unknown;
879 precision = (int)u;
880 format += n - 1;
881 goto again;
882 }
883
884 default:
885 unknown:
886 i = format - sp + 1;
887 tp = sp;
888 precision = -1;
889 flags = 0;
890 padding = 0;
891 colons = 0;
892 break;
893 }
894 if (i) {
895 FILL_PADDING(i);
896 memcpy(s, tp, i);
897 s = case_conv(s, i, flags);
898 }
899 }
900 if (format != format_end) {
901 return 0;
902 }
903 len = s - start;
904 rb_str_set_len(ftime, len);
905 rb_str_resize(ftime, len);
906 return ftime;
907 }
908
909 static size_t
910 strftime_size_limit(size_t format_len)
911 {
912 size_t limit = format_len * (1*1024*1024);
913 if (limit < format_len) limit = format_len;
914 else if (limit < 1024) limit = 1024;
915 return limit;
916 }
917
918 VALUE
919 rb_strftime(const char *format, size_t format_len, rb_encoding *enc,
920 VALUE time, const struct vtm *vtm, VALUE timev, int gmt)
921 {
922 VALUE result = rb_enc_str_new(0, 0, enc);
923 return rb_strftime_with_timespec(result, format, format_len, enc,
924 time, vtm, timev, NULL, gmt,
925 strftime_size_limit(format_len));
926 }
927
928 VALUE
929 rb_strftime_timespec(const char *format, size_t format_len, rb_encoding *enc,
930 VALUE time, const struct vtm *vtm, struct timespec *ts, int gmt)
931 {
932 VALUE result = rb_enc_str_new(0, 0, enc);
933 return rb_strftime_with_timespec(result, format, format_len, enc,
934 time, vtm, Qnil, ts, gmt,
935 strftime_size_limit(format_len));
936 }
937
938 #if 0
939 VALUE
940 rb_strftime_limit(const char *format, size_t format_len, rb_encoding *enc,
941 VALUE time, const struct vtm *vtm, struct timespec *ts,
942 int gmt, size_t maxsize)
943 {
944 VALUE result = rb_enc_str_new(0, 0, enc);
945 return rb_strftime_with_timespec(result, format, format_len, enc,
946 time, vtm, Qnil, ts, gmt, maxsize);
947 }
948 #endif
949
950 /* isleap --- is a year a leap year? */
951
952 static int
953 isleap(long year)
954 {
955 return ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0);
956 }
957
958
959 static void
960 vtm2tm_noyear(const struct vtm *vtm, struct tm *result)
961 {
962 struct tm tm;
963
964 /* for isleap() in iso8601wknum. +100 is -1900 (mod 400). */
965 tm.tm_year = FIX2INT(mod(vtm->year, INT2FIX(400))) + 100;
966
967 tm.tm_mon = vtm->mon-1;
968 tm.tm_mday = vtm->mday;
969 tm.tm_hour = vtm->hour;
970 tm.tm_min = vtm->min;
971 tm.tm_sec = vtm->sec;
972 tm.tm_wday = vtm->wday;
973 tm.tm_yday = vtm->yday-1;
974 tm.tm_isdst = vtm->isdst;
975 #if defined(HAVE_STRUCT_TM_TM_GMTOFF)
976 tm.tm_gmtoff = NUM2LONG(vtm->utc_offset);
977 #endif
978 #if defined(HAVE_TM_ZONE)
979 tm.tm_zone = (char *)vtm->zone;
980 #endif
981 *result = tm;
982 }
983
984 #ifdef POSIX2_DATE
985 /* iso8601wknum --- compute week number according to ISO 8601 */
986
987 static int
988 iso8601wknum(const struct tm *timeptr)
989 {
990 /*
991 * From 1003.2:
992 * If the week (Monday to Sunday) containing January 1
993 * has four or more days in the new year, then it is week 1;
994 * otherwise it is the highest numbered week of the previous
995 * year (52 or 53), and the next week is week 1.
996 *
997 * ADR: This means if Jan 1 was Monday through Thursday,
998 * it was week 1, otherwise week 52 or 53.
999 *
1000 * XPG4 erroneously included POSIX.2 rationale text in the
1001 * main body of the standard. Thus it requires week 53.
1002 */
1003
1004 int weeknum, jan1day;
1005
1006 /* get week number, Monday as first day of the week */
1007 weeknum = weeknumber(timeptr, 1);
1008
1009 /*
1010 * With thanks and tip of the hatlo to tml@tik.vtt.fi
1011 *
1012 * What day of the week does January 1 fall on?
1013 * We know that
1014 * (timeptr->tm_yday - jan1.tm_yday) MOD 7 ==
1015 * (timeptr->tm_wday - jan1.tm_wday) MOD 7
1016 * and that
1017 * jan1.tm_yday == 0
1018 * and that
1019 * timeptr->tm_wday MOD 7 == timeptr->tm_wday
1020 * from which it follows that. . .
1021 */
1022 jan1day = timeptr->tm_wday - (timeptr->tm_yday % 7);
1023 if (jan1day < 0)
1024 jan1day += 7;
1025
1026 /*
1027 * If Jan 1 was a Monday through Thursday, it was in
1028 * week 1. Otherwise it was last year's highest week, which is
1029 * this year's week 0.
1030 *
1031 * What does that mean?
1032 * If Jan 1 was Monday, the week number is exactly right, it can
1033 * never be 0.
1034 * If it was Tuesday through Thursday, the weeknumber is one
1035 * less than it should be, so we add one.
1036 * Otherwise, Friday, Saturday or Sunday, the week number is
1037 * OK, but if it is 0, it needs to be 52 or 53.
1038 */
1039 switch (jan1day) {
1040 case 1: /* Monday */
1041 break;
1042 case 2: /* Tuesday */
1043 case 3: /* Wednesday */
1044 case 4: /* Thursday */
1045 weeknum++;
1046 break;
1047 case 5: /* Friday */
1048 case 6: /* Saturday */
1049 case 0: /* Sunday */
1050 if (weeknum == 0) {
1051 #ifdef USE_BROKEN_XPG4
1052 /* XPG4 (as of March 1994) says 53 unconditionally */
1053 weeknum = 53;
1054 #else
1055 /* get week number of last week of last year */
1056 struct tm dec31ly; /* 12/31 last year */
1057 dec31ly = *timeptr;
1058 dec31ly.tm_year--;
1059 dec31ly.tm_mon = 11;
1060 dec31ly.tm_mday = 31;
1061 dec31ly.tm_wday = (jan1day == 0) ? 6 : jan1day - 1;
1062 dec31ly.tm_yday = 364 + isleap(dec31ly.tm_year + 1900L);
1063 weeknum = iso8601wknum(& dec31ly);
1064 #endif
1065 }
1066 break;
1067 }
1068
1069 if (timeptr->tm_mon == 11) {
1070 /*
1071 * The last week of the year
1072 * can be in week 1 of next year.
1073 * Sigh.
1074 *
1075 * This can only happen if
1076 * M T W
1077 * 29 30 31
1078 * 30 31
1079 * 31
1080 */
1081 int wday, mday;
1082
1083 wday = timeptr->tm_wday;
1084 mday = timeptr->tm_mday;
1085 if ( (wday == 1 && (mday >= 29 && mday <= 31))
1086 || (wday == 2 && (mday == 30 || mday == 31))
1087 || (wday == 3 && mday == 31))
1088 weeknum = 1;
1089 }
1090
1091 return weeknum;
1092 }
1093
1094 static int
1095 iso8601wknum_v(const struct vtm *vtm)
1096 {
1097 struct tm tm;
1098 vtm2tm_noyear(vtm, &tm);
1099 return iso8601wknum(&tm);
1100 }
1101
1102 #endif
1103
1104 /* weeknumber --- figure how many weeks into the year */
1105
1106 /* With thanks and tip of the hatlo to ado@elsie.nci.nih.gov */
1107
1108 static int
1109 weeknumber(const struct tm *timeptr, int firstweekday)
1110 {
1111 int wday = timeptr->tm_wday;
1112 int ret;
1113
1114 if (firstweekday == 1) {
1115 if (wday == 0) /* sunday */
1116 wday = 6;
1117 else
1118 wday--;
1119 }
1120 ret = ((timeptr->tm_yday + 7 - wday) / 7);
1121 if (ret < 0)
1122 ret = 0;
1123 return ret;
1124 }
1125
1126 static int
1127 weeknumber_v(const struct vtm *vtm, int firstweekday)
1128 {
1129 struct tm tm;
1130 vtm2tm_noyear(vtm, &tm);
1131 return weeknumber(&tm, firstweekday);
1132 }
1133
1134 #if 0
1135 /* ADR --- I'm loathe to mess with ado's code ... */
1136
1137 Date: Wed, 24 Apr 91 20:54:08 MDT
1138 From: Michal Jaegermann <audfax!emory!vm.ucs.UAlberta.CA!NTOMCZAK>
1139 To: arnold@audiofax.com
1140
1141 Hi Arnold,
1142 in a process of fixing of strftime() in libraries on Atari ST I grabbed
1143 some pieces of code from your own strftime. When doing that it came
1144 to mind that your weeknumber() function compiles a little bit nicer
1145 in the following form:
1146 /*
1147 * firstweekday is 0 if starting in Sunday, non-zero if in Monday
1148 */
1149 {
1150 return (timeptr->tm_yday - timeptr->tm_wday +
1151 (firstweekday ? (timeptr->tm_wday ? 8 : 1) : 7)) / 7;
1152 }
1153 How nicer it depends on a compiler, of course, but always a tiny bit.
1154
1155 Cheers,
1156 Michal
1157 ntomczak@vm.ucs.ualberta.ca
1158 #endif
1159
1160 #ifdef TEST_STRFTIME
1161
1162 /*
1163 * NAME:
1164 * tst
1165 *
1166 * SYNOPSIS:
1167 * tst
1168 *
1169 * DESCRIPTION:
1170 * "tst" is a test driver for the function "strftime".
1171 *
1172 * OPTIONS:
1173 * None.
1174 *
1175 * AUTHOR:
1176 * Karl Vogel
1177 * Control Data Systems, Inc.
1178 * vogelke@c-17igp.wpafb.af.mil
1179 *
1180 * BUGS:
1181 * None noticed yet.
1182 *
1183 * COMPILE:
1184 * cc -o tst -DTEST_STRFTIME strftime.c
1185 */
1186
1187 /* ADR: I reformatted this to my liking, and deleted some unneeded code. */
1188
1189 #ifndef NULL
1190 #include <stdio.h>
1191 #endif
1192 #include <sys/time.h>
1193 #include <string.h>
1194
1195 #define MAXTIME 132
1196
1197 /*
1198 * Array of time formats.
1199 */
1200
1201 static char *array[] =
1202 {
1203 "(%%A) full weekday name, var length (Sunday..Saturday) %A",
1204 "(%%B) full month name, var length (January..December) %B",
1205 "(%%C) Century %C",
1206 "(%%D) date (%%m/%%d/%%y) %D",
1207 "(%%E) Locale extensions (ignored) %E",
1208 "(%%H) hour (24-hour clock, 00..23) %H",
1209 "(%%I) hour (12-hour clock, 01..12) %I",
1210 "(%%M) minute (00..59) %M",
1211 "(%%O) Locale extensions (ignored) %O",
1212 "(%%R) time, 24-hour (%%H:%%M) %R",
1213 "(%%S) second (00..60) %S",
1214 "(%%T) time, 24-hour (%%H:%%M:%%S) %T",
1215 "(%%U) week of year, Sunday as first day of week (00..53) %U",
1216 "(%%V) week of year according to ISO 8601 %V",
1217 "(%%W) week of year, Monday as first day of week (00..53) %W",
1218 "(%%X) appropriate locale time representation (%H:%M:%S) %X",
1219 "(%%Y) year with century (1970...) %Y",
1220 "(%%Z) timezone (EDT), or blank if timezone not determinable %Z",
1221 "(%%a) locale's abbreviated weekday name (Sun..Sat) %a",
1222 "(%%b) locale's abbreviated month name (Jan..Dec) %b",
1223 "(%%c) full date (Sat Nov 4 12:02:33 1989)%n%t%t%t %c",
1224 "(%%d) day of the month (01..31) %d",
1225 "(%%e) day of the month, blank-padded ( 1..31) %e",
1226 "(%%h) should be same as (%%b) %h",
1227 "(%%j) day of the year (001..366) %j",
1228 "(%%k) hour, 24-hour clock, blank pad ( 0..23) %k",
1229 "(%%l) hour, 12-hour clock, blank pad ( 1..12) %l",
1230 "(%%m) month (01..12) %m",
1231 "(%%p) locale's AM or PM based on 12-hour clock %p",
1232 "(%%r) time, 12-hour (same as %%I:%%M:%%S %%p) %r",
1233 "(%%u) ISO 8601: Weekday as decimal number [1 (Monday) - 7] %u",
1234 "(%%v) VMS date (dd-bbb-YYYY) %v",
1235 "(%%w) day of week (0..6, Sunday == 0) %w",
1236 "(%%x) appropriate locale date representation %x",
1237 "(%%y) last two digits of year (00..99) %y",
1238 "(%%z) timezone offset east of GMT as HHMM (e.g. -0500) %z",
1239 (char *) NULL
1240 };
1241
1242 /* main routine. */
1243
1244 int
1245 main(int argc, char **argv)
1246 {
1247 long time();
1248
1249 char *next;
1250 char string[MAXTIME];
1251
1252 int k;
1253 int length;
1254
1255 struct tm *tm;
1256
1257 long clock;
1258
1259 /* Call the function. */
1260
1261 clock = time((long *) 0);
1262 tm = localtime(&clock);
1263
1264 for (k = 0; next = array[k]; k++) {
1265 length = strftime(string, MAXTIME, next, tm);
1266 printf("%s\n", string);
1267 }
1268
1269 exit(0);
1270 }
1271 #endif /* TEST_STRFTIME */
FLAG_FOUND
#define FLAG_FOUND()
void
void
Definition: rb_mjit_min_header-2.7.0.h:13273
time_t
long time_t
Definition: rb_mjit_min_header-2.7.0.h:1236
BIT_OF
#define BIT_OF(n)
Definition: strftime.c:161
FIX2INT
#define FIX2INT(x)
Definition: ruby.h:717
mod
#define mod(x, y)
Definition: strftime.c:156
tm::tm_min
int tm_min
Definition: rb_mjit_min_header-2.7.0.h:1935
memset
void * memset(void *, int, size_t)
INT2FIX
#define INT2FIX(i)
Definition: ruby.h:263
snprintf
int snprintf(char *__restrict, size_t, const char *__restrict,...) __attribute__((__format__(__printf__
strchr
char * strchr(char *, char)
localtime
struct tm * localtime(const time_t *_timer)
FILL_PADDING
#define FILL_PADDING(i)
RSTRING_PTR
#define RSTRING_PTR(str)
Definition: ruby.h:1009
time
time_t time(time_t *_timer)
NUM2LONG
#define NUM2LONG(x)
Definition: ruby.h:679
rb_locale_encoding
rb_encoding * rb_locale_encoding(void)
Definition: encoding.c:1372
tm::tm_wday
int tm_wday
Definition: rb_mjit_min_header-2.7.0.h:1940
VALUE
unsigned long VALUE
Definition: ruby.h:102
encoding.h
rb_intern
#define rb_intern(str)
malloc
void * malloc(size_t) __attribute__((__malloc__)) __attribute__((__warn_unused_result__)) __attribute__((__alloc_size__(1)))
RB_TYPE_P
#define RB_TYPE_P(obj, type)
Definition: ruby.h:560
ERANGE
#define ERANGE
Definition: rb_mjit_min_header-2.7.0.h:10971
ECONV_UNDEF_REPLACE
#define ECONV_UNDEF_REPLACE
Definition: encoding.h:396
UPPER
@ UPPER
Definition: strftime.c:160
int
__inline__ int
Definition: rb_mjit_min_header-2.7.0.h:2839
STRFTIME
#define STRFTIME(fmt)
zone
Definition: zonetab.h:35
getenv
#define getenv(name)
Definition: win32.c:73
tm::tm_sec
int tm_sec
Definition: rb_mjit_min_header-2.7.0.h:1934
CHCASE
@ CHCASE
Definition: strftime.c:160
div
#define div(x, y)
Definition: strftime.c:155
rb_Integer
VALUE rb_Integer(VALUE)
Equivalent to Kernel#Integer in Ruby.
Definition: object.c:3106
clock
clock_t clock(void)
printf
int int int printf(const char *__restrict,...) __attribute__((__format__(__printf__
NULL
#define NULL
Definition: _sdbm.c:101
exit
void exit(int __status) __attribute__((__noreturn__))
tm::tm_mon
int tm_mon
Definition: rb_mjit_min_header-2.7.0.h:1938
ruby_scan_digits
RUBY_EXTERN unsigned long ruby_scan_digits(const char *str, ssize_t len, int base, size_t *retlen, int *overflow)
Definition: util.c:97
FMT
#define FMT(def_pad, def_prec, fmt, val)
tm::tm_mday
int tm_mday
Definition: rb_mjit_min_header-2.7.0.h:1937
FIX2LONG
#define FIX2LONG(x)
Definition: ruby.h:394
ruby.h
strlen
size_t strlen(const char *)
LEFT
@ LEFT
Definition: strftime.c:160
tm::tm_hour
int tm_hour
Definition: rb_mjit_min_header-2.7.0.h:1936
L
#define L(x)
Definition: asm.h:125
timespec::tv_nsec
long tv_nsec
Definition: missing.h:62
rb_str_capacity
size_t rb_str_capacity(VALUE str)
Definition: string.c:712
rb_str_resize
VALUE rb_str_resize(VALUE, long)
Definition: string.c:2709
TOUPPER
#define TOUPPER(c)
Definition: ruby.h:2318
rb_str_conv_enc_opts
VALUE rb_str_conv_enc_opts(VALUE str, rb_encoding *from, rb_encoding *to, int ecflags, VALUE ecopts)
Definition: string.c:914
timev.h
adddecl
#define adddecl(stuff)
Definition: strftime.c:95
rb_str_format
VALUE rb_str_format(int, const VALUE *, VALUE)
Definition: sprintf.c:204
realloc
void * realloc(void *, size_t) __attribute__((__warn_unused_result__)) __attribute__((__alloc_size__(2)))
memcpy
void * memcpy(void *__restrict, const void *__restrict, size_t)
tm::tm_isdst
int tm_isdst
Definition: rb_mjit_min_header-2.7.0.h:1942
FMTV
#define FMTV(def_pad, def_prec, fmt, val)
rb_ascii8bit_encoding
rb_encoding * rb_ascii8bit_encoding(void)
Definition: encoding.c:1316
timespec::tv_sec
time_t tv_sec
Definition: missing.h:61
rb_encoding
const typedef OnigEncodingType rb_encoding
Definition: encoding.h:115
ISUPPER
#define ISUPPER(c)
Definition: ruby.h:2308
LOWER
@ LOWER
Definition: strftime.c:160
strftime
size_t strftime(char *__restrict _s, size_t _maxsize, const char *__restrict _fmt, const struct tm *__restrict _t)
PRI_TIMET_PREFIX
#define PRI_TIMET_PREFIX
Definition: ruby.h:174
TBUFSIZE
#define TBUFSIZE
i
uint32_t i
Definition: rb_mjit_min_header-2.7.0.h:5464
INT_MAX
#define INT_MAX
Definition: rb_mjit_min_header-2.7.0.h:4052
NEEDS
#define NEEDS(n)
strlcpy
RUBY_EXTERN size_t strlcpy(char *, const char *, size_t)
Definition: strlcpy.c:29
rb_str_set_len
void rb_str_set_len(VALUE, long)
Definition: string.c:2692
FIXNUM_P
#define FIXNUM_P(f)
Definition: ruby.h:396
ISLOWER
#define ISLOWER(c)
Definition: ruby.h:2309
rb_str_new_cstr
#define rb_str_new_cstr(str)
Definition: rb_mjit_min_header-2.7.0.h:6117
mul
#define mul(x, y)
Definition: strftime.c:153
StringValueCStr
#define StringValueCStr(v)
Definition: ruby.h:604
STDC_HEADERS
#define STDC_HEADERS
Definition: fficonfig.h:22
I
#define I(x, y, z)
range
#define range(low, item, hi)
fmt
const VALUE int int int int int int VALUE char * fmt
Definition: rb_mjit_min_header-2.7.0.h:6462
add
#define add(x, y)
Definition: strftime.c:151
n
const char size_t n
Definition: rb_mjit_min_header-2.7.0.h:5456
T_BIGNUM
#define T_BIGNUM
Definition: ruby.h:533
rb_funcall
#define rb_funcall(recv, mid, argc,...)
Definition: rb_mjit_min_header-2.7.0.h:6585
internal.h
argv
char ** argv
Definition: ruby.c:223
rb_strftime
VALUE rb_strftime(const char *format, size_t format_len, rb_encoding *enc, VALUE time, const struct vtm *vtm, VALUE timev, int gmt)
Definition: strftime.c:919
str
char str[HTML_ESCAPE_MAX_LEN+1]
Definition: escape.c:18
rb_time_zone_abbreviation
VALUE rb_time_zone_abbreviation(VALUE zone, VALUE time)
Definition: time.c:5650
NIL_P
#define NIL_P(v)
Definition: ruby.h:482
rb_str_modify_expand
void rb_str_modify_expand(VALUE, long)
Definition: string.c:2122
argc
int argc
Definition: ruby.c:222
rb_big2str
VALUE rb_big2str(VALUE x, int base)
Definition: bignum.c:5091
rb_strftime_timespec
VALUE rb_strftime_timespec(const char *format, size_t format_len, rb_encoding *enc, VALUE time, const struct vtm *vtm, struct timespec *ts, int gmt)
Definition: strftime.c:929
err
int err
Definition: win32.c:135
tm
Definition: rb_mjit_min_header-2.7.0.h:1932
tm::tm_year
int tm_year
Definition: rb_mjit_min_header-2.7.0.h:1939
len
uint8_t len
Definition: escape.c:17
tm::tm_yday
int tm_yday
Definition: rb_mjit_min_header-2.7.0.h:1941
TOLOWER
#define TOLOWER(c)
Definition: ruby.h:2319
timespec
Definition: missing.h:60
ECONV_INVALID_REPLACE
#define ECONV_INVALID_REPLACE
Definition: encoding.h:394
NUM2INT
#define NUM2INT(x)
Definition: ruby.h:715
Qnil
#define Qnil
Definition: ruby.h:469
rb_fstring_lit
#define rb_fstring_lit(str)
Definition: internal.h:2123
tm::tm_gmtoff
long tm_gmtoff
Definition: rb_mjit_min_header-2.7.0.h:1943
sub
#define sub(x, y)
Definition: strftime.c:152
RSTRING_LEN
#define RSTRING_LEN(str)
Definition: ruby.h:1005
ptrdiff_t
long int ptrdiff_t
Definition: rb_mjit_min_header-2.7.0.h:802
tm::tm_zone
const char * tm_zone
Definition: rb_mjit_min_header-2.7.0.h:1944
rb_enc_str_new
VALUE rb_enc_str_new(const char *, long, rb_encoding *)
Definition: string.c:796
main
int main(void)
Definition: closure_fn0.c:49
rb_usascii_encoding
rb_encoding * rb_usascii_encoding(void)
Definition: encoding.c:1340
rb_syserr_fail_str
void rb_syserr_fail_str(int e, VALUE mesg)
Definition: error.c:2787
memchr
void * memchr(const void *, int, size_t)