1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* ext/date/date_{core,strftime}.c: use struct tmx instead of vtm.

* ext/date/date_tmx.h: new.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31299 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tadf 2011-04-16 15:22:47 +00:00
parent 531dfb40e0
commit 2b6ab9bf1e
5 changed files with 140 additions and 141 deletions

View file

@ -1,3 +1,8 @@
Sun Apr 17 00:20:14 2011 Tadayoshi Funaba <tadf@dotrb.org>
* ext/date/date_{core,strftime}.c: use struct tmx instead of vtm.
* ext/date/date_tmx.h: new.
Sat Apr 16 22:23:52 2011 Tadayoshi Funaba <tadf@dotrb.org> Sat Apr 16 22:23:52 2011 Tadayoshi Funaba <tadf@dotrb.org>
* ext/date/date_strftime.c (date_strftime_wo_timespec): changed * ext/date/date_strftime.c (date_strftime_wo_timespec): changed

View file

@ -2402,16 +2402,16 @@ d_lite_inspect(VALUE self)
} }
#include <errno.h> #include <errno.h>
#include "timev.h" #include "date_tmx.h"
size_t size_t
date_strftime(char *s, size_t maxsize, const char *format, date_strftime(char *s, size_t maxsize, const char *format,
const struct vtm *vtm, VALUE timev); const struct tmx *tmx);
#define SMALLBUF 100 #define SMALLBUF 100
static size_t static size_t
date_strftime_alloc(char **buf, const char *format, date_strftime_alloc(char **buf, const char *format,
struct vtm *vtm, VALUE timev) struct tmx *tmx)
{ {
size_t size, len, flen; size_t size, len, flen;
@ -2421,12 +2421,12 @@ date_strftime_alloc(char **buf, const char *format,
return 0; return 0;
} }
errno = 0; errno = 0;
len = date_strftime(*buf, SMALLBUF, format, vtm, timev); len = date_strftime(*buf, SMALLBUF, format, tmx);
if (len != 0 || (**buf == '\0' && errno != ERANGE)) return len; if (len != 0 || (**buf == '\0' && errno != ERANGE)) return len;
for (size=1024; ; size*=2) { for (size=1024; ; size*=2) {
*buf = xmalloc(size); *buf = xmalloc(size);
(*buf)[0] = '\0'; (*buf)[0] = '\0';
len = date_strftime(*buf, size, format, vtm, timev); len = date_strftime(*buf, size, format, tmx);
/* /*
* buflen can be zero EITHER because there's not enough * buflen can be zero EITHER because there's not enough
* room in the string, or because the control command * room in the string, or because the control command
@ -2441,52 +2441,49 @@ date_strftime_alloc(char **buf, const char *format,
} }
static void static void
d_lite_set_vtm_and_timev(VALUE self, struct vtm *vtm, VALUE *timev) d_lite_set_tmx(VALUE self, struct tmx *tmx)
{ {
get_d1(self); get_d1(self);
if (!light_mode_p(dat)) { if (!light_mode_p(dat)) {
vtm->year = iforward0("year_r"); tmx->year = iforward0("year_r");
vtm->mon = FIX2INT(iforward0("mon_r")); tmx->yday = FIX2INT(iforward0("yday_r"));
vtm->mday = FIX2INT(iforward0("mday_r")); tmx->mon = FIX2INT(iforward0("mon_r"));
vtm->hour = FIX2INT(iforward0("hour_r")); tmx->mday = FIX2INT(iforward0("mday_r"));
vtm->min = FIX2INT(iforward0("min_r")); tmx->hour = FIX2INT(iforward0("hour_r"));
vtm->sec = FIX2INT(iforward0("sec_r")); tmx->min = FIX2INT(iforward0("min_r"));
vtm->subsecx = iforward0("sec_fraction_r"); tmx->sec = FIX2INT(iforward0("sec_r"));
vtm->utc_offset = INT2FIX(0); tmx->wday = FIX2INT(iforward0("wday_r"));
vtm->wday = FIX2INT(iforward0("wday_r")); tmx->offset = INT2FIX(0);
vtm->yday = FIX2INT(iforward0("yday_r")); tmx->zone = RSTRING_PTR(iforward0("zone_r"));
vtm->isdst = 0; tmx->timev = f_mul(f_sub(dat->r.ajd,
vtm->zone = RSTRING_PTR(iforward0("zone_r")); rb_rational_new2(INT2FIX(4881175),
*timev = f_mul(f_sub(dat->r.ajd, INT2FIX(2))),
rb_rational_new2(INT2FIX(4881175), INT2FIX(2))), INT2FIX(86400));
INT2FIX(86400));
} }
else { else {
get_d_jd(dat); get_d_jd(dat);
get_d_civil(dat); get_d_civil(dat);
vtm->year = LONG2NUM(dat->l.year); tmx->year = LONG2NUM(dat->l.year);
vtm->mon = dat->l.mon; tmx->yday = civil_to_yday(dat->l.year, dat->l.mon, dat->l.mday);
vtm->mday = dat->l.mday; tmx->mon = dat->l.mon;
vtm->hour = 0; tmx->mday = dat->l.mday;
vtm->min = 0; tmx->hour = 0;
vtm->sec = 0; tmx->min = 0;
vtm->subsecx = INT2FIX(0); tmx->sec = 0;
vtm->utc_offset = INT2FIX(0); tmx->wday = jd_to_wday(dat->l.jd);
vtm->wday = jd_to_wday(dat->l.jd); tmx->offset = INT2FIX(0);
vtm->yday = civil_to_yday(dat->l.year, dat->l.mon, dat->l.mday); tmx->zone = "+00:00";
vtm->isdst = 0; tmx->timev = f_mul(INT2FIX(dat->l.jd - 2440588),
vtm->zone = "+00:00"; INT2FIX(86400));
*timev = f_mul(INT2FIX(dat->l.jd - 2440588),
INT2FIX(86400));
} }
} }
static VALUE static VALUE
date_strftime_internal(int argc, VALUE *argv, VALUE self, date_strftime_internal(int argc, VALUE *argv, VALUE self,
const char *default_fmt, const char *default_fmt,
void (*func)(VALUE, struct vtm *, VALUE *)) void (*func)(VALUE, struct tmx *))
{ {
get_d1(self); get_d1(self);
{ {
@ -2494,8 +2491,7 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
const char *fmt; const char *fmt;
long len; long len;
char buffer[SMALLBUF], *buf = buffer; char buffer[SMALLBUF], *buf = buffer;
struct vtm vtm; struct tmx tmx;
VALUE timev;
VALUE str; VALUE str;
rb_scan_args(argc, argv, "01", &vfmt); rb_scan_args(argc, argv, "01", &vfmt);
@ -2511,14 +2507,14 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
} }
fmt = RSTRING_PTR(vfmt); fmt = RSTRING_PTR(vfmt);
len = RSTRING_LEN(vfmt); len = RSTRING_LEN(vfmt);
(*func)(self, &vtm, &timev); (*func)(self, &tmx);
if (memchr(fmt, '\0', len)) { if (memchr(fmt, '\0', len)) {
/* Ruby string may contain \0's. */ /* Ruby string may contain \0's. */
const char *p = fmt, *pe = fmt + len; const char *p = fmt, *pe = fmt + len;
str = rb_str_new(0, 0); str = rb_str_new(0, 0);
while (p < pe) { while (p < pe) {
len = date_strftime_alloc(&buf, p, &vtm, timev); len = date_strftime_alloc(&buf, p, &tmx);
rb_str_cat(str, buf, len); rb_str_cat(str, buf, len);
p += strlen(p); p += strlen(p);
if (buf != buffer) { if (buf != buffer) {
@ -2531,7 +2527,7 @@ date_strftime_internal(int argc, VALUE *argv, VALUE self,
return str; return str;
} }
else else
len = date_strftime_alloc(&buf, fmt, &vtm, timev); len = date_strftime_alloc(&buf, fmt, &tmx);
str = rb_str_new(buf, len); str = rb_str_new(buf, len);
if (buf != buffer) xfree(buf); if (buf != buffer) xfree(buf);
@ -2550,7 +2546,7 @@ static VALUE
d_lite_strftime(int argc, VALUE *argv, VALUE self) d_lite_strftime(int argc, VALUE *argv, VALUE self)
{ {
return date_strftime_internal(argc, argv, self, return date_strftime_internal(argc, argv, self,
"%F", d_lite_set_vtm_and_timev); "%F", d_lite_set_tmx);
} }
/* /*
@ -4046,47 +4042,45 @@ dt_lite_inspect(VALUE self)
} }
static void static void
dt_lite_set_vtm_and_timev(VALUE self, struct vtm *vtm, VALUE *timev) dt_lite_set_tmx(VALUE self, struct tmx *tmx)
{ {
get_dt1(self); get_dt1(self);
if (!light_mode_p(dat)) { if (!light_mode_p(dat)) {
vtm->year = iforward0("year_r"); tmx->year = iforward0("year_r");
vtm->mon = FIX2INT(iforward0("mon_r")); tmx->yday = FIX2INT(iforward0("yday_r"));
vtm->mday = FIX2INT(iforward0("mday_r")); tmx->mon = FIX2INT(iforward0("mon_r"));
vtm->hour = FIX2INT(iforward0("hour_r")); tmx->mday = FIX2INT(iforward0("mday_r"));
vtm->min = FIX2INT(iforward0("min_r")); tmx->hour = FIX2INT(iforward0("hour_r"));
vtm->sec = FIX2INT(iforward0("sec_r")); tmx->min = FIX2INT(iforward0("min_r"));
vtm->subsecx = iforward0("sec_fraction_r"); tmx->sec = FIX2INT(iforward0("sec_r"));
vtm->utc_offset = INT2FIX(0); tmx->wday = FIX2INT(iforward0("wday_r"));
vtm->wday = FIX2INT(iforward0("wday_r")); tmx->offset = INT2FIX(0);
vtm->yday = FIX2INT(iforward0("yday_r")); tmx->zone = RSTRING_PTR(iforward0("zone_r"));
vtm->isdst = 0; tmx->timev = f_mul(f_sub(dat->r.ajd,
vtm->zone = RSTRING_PTR(iforward0("zone_r")); rb_rational_new2(INT2FIX(4881175),
*timev = f_mul(f_sub(dat->r.ajd, INT2FIX(2))),
rb_rational_new2(INT2FIX(4881175), INT2FIX(2))), INT2FIX(86400));
INT2FIX(86400));
} }
else { else {
get_dt_jd(dat); get_dt_jd(dat);
get_dt_civil(dat); get_dt_civil(dat);
get_dt_time(dat); get_dt_time(dat);
vtm->year = LONG2NUM(dat->l.year); tmx->year = LONG2NUM(dat->l.year);
vtm->mon = dat->l.mon; tmx->yday = civil_to_yday(dat->l.year, dat->l.mon, dat->l.mday);
vtm->mday = dat->l.mday; tmx->mon = dat->l.mon;
vtm->hour = dat->l.hour; tmx->mday = dat->l.mday;
vtm->min = dat->l.min; tmx->hour = dat->l.hour;
vtm->sec = dat->l.sec; tmx->min = dat->l.min;
vtm->subsecx = LONG2NUM(dat->l.sf); tmx->sec = dat->l.sec;
vtm->utc_offset = INT2FIX(dat->l.of); tmx->wday = jd_to_wday(local_jd(dat));
vtm->wday = jd_to_wday(local_jd(dat)); tmx->offset = INT2FIX(dat->l.of);
vtm->yday = civil_to_yday(dat->l.year, dat->l.mon, dat->l.mday); tmx->zone = RSTRING_PTR(dt_lite_zone(self));
vtm->isdst = 0; tmx->timev = f_mul(f_sub(dt_lite_ajd(self),
vtm->zone = RSTRING_PTR(dt_lite_zone(self)); rb_rational_new2(INT2FIX(4881175),
*timev = f_mul(f_sub(dt_lite_ajd(self), INT2FIX(2))),
rb_rational_new2(INT2FIX(4881175), INT2FIX(2))), INT2FIX(86400));
INT2FIX(86400));
} }
} }
@ -4100,7 +4094,7 @@ static VALUE
dt_lite_strftime(int argc, VALUE *argv, VALUE self) dt_lite_strftime(int argc, VALUE *argv, VALUE self)
{ {
return date_strftime_internal(argc, argv, self, return date_strftime_internal(argc, argv, self,
"%FT%T%:z", dt_lite_set_vtm_and_timev); "%FT%T%:z", dt_lite_set_tmx);
} }
/* /*

View file

@ -48,7 +48,7 @@
*/ */
#include "ruby/ruby.h" #include "ruby/ruby.h"
#include "timev.h" #include "date_tmx.h"
#ifndef GAWK #ifndef GAWK
#include <stdio.h> #include <stdio.h>
@ -106,8 +106,8 @@ adddecl(static int iso8601wknum_v();)
#else #else
static int weeknumber(const struct tm *timeptr, int firstweekday); static int weeknumber(const struct tm *timeptr, int firstweekday);
adddecl(static int iso8601wknum(const struct tm *timeptr);) adddecl(static int iso8601wknum(const struct tm *timeptr);)
static int weeknumber_v(const struct vtm *vtm, int firstweekday); static int weeknumber_v(const struct tmx *tmx, int firstweekday);
adddecl(static int iso8601wknum_v(const struct vtm *vtm);) adddecl(static int iso8601wknum_v(const struct tmx *tmx);)
#endif #endif
#ifdef STDC_HEADERS #ifdef STDC_HEADERS
@ -168,8 +168,8 @@ max(int a, int b)
/* strftime --- produce formatted time */ /* strftime --- produce formatted time */
static size_t static size_t
date_strftime_wo_timespec(char *s, size_t maxsize, const char *format, date_strftime_with_tmx(char *s, size_t maxsize, const char *format,
const struct vtm *vtm, VALUE timev) const struct tmx *tmx)
{ {
char *endp = s + maxsize; char *endp = s + maxsize;
char *start = s; char *start = s;
@ -196,7 +196,7 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
}; };
static const char ampm[][3] = { "AM", "PM", }; static const char ampm[][3] = { "AM", "PM", };
if (s == NULL || format == NULL || vtm == NULL || maxsize == 0) if (s == NULL || format == NULL || tmx == NULL || maxsize == 0)
return 0; return 0;
/* quick check if we even need to bother */ /* quick check if we even need to bother */
@ -235,7 +235,7 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
} while (0) } while (0)
#define STRFTIME(fmt) \ #define STRFTIME(fmt) \
do { \ do { \
i = date_strftime_wo_timespec(s, endp - s, (fmt), vtm, timev); \ i = date_strftime_with_tmx(s, endp - s, (fmt), tmx); \
if (!i) return 0; \ if (!i) return 0; \
if (precision > i) {\ if (precision > i) {\
if (start + maxsize < s + precision) { \ if (start + maxsize < s + precision) { \
@ -298,10 +298,10 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE)); flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE));
flags |= BIT_OF(UPPER); flags |= BIT_OF(UPPER);
} }
if (vtm->wday < 0 || vtm->wday > 6) if (tmx->wday < 0 || tmx->wday > 6)
i = 1, tp = "?"; i = 1, tp = "?";
else else
i = 3, tp = days_l[vtm->wday]; i = 3, tp = days_l[tmx->wday];
break; break;
case 'A': /* full weekday name */ case 'A': /* full weekday name */
@ -309,10 +309,10 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE)); flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE));
flags |= BIT_OF(UPPER); flags |= BIT_OF(UPPER);
} }
if (vtm->wday < 0 || vtm->wday > 6) if (tmx->wday < 0 || tmx->wday > 6)
i = 1, tp = "?"; i = 1, tp = "?";
else else
i = strlen(tp = days_l[vtm->wday]); i = strlen(tp = days_l[tmx->wday]);
break; break;
#ifdef SYSV_EXT #ifdef SYSV_EXT
@ -323,10 +323,10 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE)); flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE));
flags |= BIT_OF(UPPER); flags |= BIT_OF(UPPER);
} }
if (vtm->mon < 1 || vtm->mon > 12) if (tmx->mon < 1 || tmx->mon > 12)
i = 1, tp = "?"; i = 1, tp = "?";
else else
i = 3, tp = months_l[vtm->mon-1]; i = 3, tp = months_l[tmx->mon-1];
break; break;
case 'B': /* full month name */ case 'B': /* full month name */
@ -334,10 +334,10 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE)); flags &= ~(BIT_OF(LOWER)|BIT_OF(CHCASE));
flags |= BIT_OF(UPPER); flags |= BIT_OF(UPPER);
} }
if (vtm->mon < 1 || vtm->mon > 12) if (tmx->mon < 1 || tmx->mon > 12)
i = 1, tp = "?"; i = 1, tp = "?";
else else
i = strlen(tp = months_l[vtm->mon-1]); i = strlen(tp = months_l[tmx->mon-1]);
break; break;
case 'c': /* appropriate date and time representation */ case 'c': /* appropriate date and time representation */
@ -345,17 +345,17 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
continue; continue;
case 'd': /* day of the month, 01 - 31 */ case 'd': /* day of the month, 01 - 31 */
i = range(1, vtm->mday, 31); i = range(1, tmx->mday, 31);
FMT('0', 2, "d", (int)i); FMT('0', 2, "d", (int)i);
continue; continue;
case 'H': /* hour, 24-hour clock, 00 - 23 */ case 'H': /* hour, 24-hour clock, 00 - 23 */
i = range(0, vtm->hour, 23); i = range(0, tmx->hour, 23);
FMT('0', 2, "d", (int)i); FMT('0', 2, "d", (int)i);
continue; continue;
case 'I': /* hour, 12-hour clock, 01 - 12 */ case 'I': /* hour, 12-hour clock, 01 - 12 */
i = range(0, vtm->hour, 23); i = range(0, tmx->hour, 23);
if (i == 0) if (i == 0)
i = 12; i = 12;
else if (i > 12) else if (i > 12)
@ -364,16 +364,16 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
continue; continue;
case 'j': /* day of the year, 001 - 366 */ case 'j': /* day of the year, 001 - 366 */
FMT('0', 3, "d", vtm->yday); FMT('0', 3, "d", tmx->yday);
continue; continue;
case 'm': /* month, 01 - 12 */ case 'm': /* month, 01 - 12 */
i = range(1, vtm->mon, 12); i = range(1, tmx->mon, 12);
FMT('0', 2, "d", (int)i); FMT('0', 2, "d", (int)i);
continue; continue;
case 'M': /* minute, 00 - 59 */ case 'M': /* minute, 00 - 59 */
i = range(0, vtm->min, 59); i = range(0, tmx->min, 59);
FMT('0', 2, "d", (int)i); FMT('0', 2, "d", (int)i);
continue; continue;
@ -384,7 +384,7 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
flags &= ~(BIT_OF(UPPER)|BIT_OF(CHCASE)); flags &= ~(BIT_OF(UPPER)|BIT_OF(CHCASE));
flags |= BIT_OF(LOWER); flags |= BIT_OF(LOWER);
} }
i = range(0, vtm->hour, 23); i = range(0, tmx->hour, 23);
if (i < 12) if (i < 12)
tp = ampm[0]; tp = ampm[0];
else else
@ -394,14 +394,14 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
case 's': case 's':
{ {
VALUE sec = div(timev, INT2FIX(1)); VALUE sec = div(tmx->timev, INT2FIX(1));
FMTV('0', 1, "d", sec); FMTV('0', 1, "d", sec);
} }
continue; continue;
case 'Q': case 'Q':
{ {
VALUE sec = div(timev, VALUE sec = div(tmx->timev,
rb_rational_new2(INT2FIX(1), rb_rational_new2(INT2FIX(1),
INT2FIX(1000))); INT2FIX(1000)));
FMTV('0', 1, "d", sec); FMTV('0', 1, "d", sec);
@ -409,21 +409,21 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
continue; continue;
case 'S': /* second, 00 - 60 */ case 'S': /* second, 00 - 60 */
i = range(0, vtm->sec, 60); i = range(0, tmx->sec, 60);
FMT('0', 2, "d", (int)i); FMT('0', 2, "d", (int)i);
continue; continue;
case 'U': /* week of year, Sunday is first day of week */ case 'U': /* week of year, Sunday is first day of week */
FMT('0', 2, "d", weeknumber_v(vtm, 0)); FMT('0', 2, "d", weeknumber_v(tmx, 0));
continue; continue;
case 'w': /* weekday, Sunday == 0, 0 - 6 */ case 'w': /* weekday, Sunday == 0, 0 - 6 */
i = range(0, vtm->wday, 6); i = range(0, tmx->wday, 6);
FMT('0', 1, "d", (int)i); FMT('0', 1, "d", (int)i);
continue; continue;
case 'W': /* week of year, Monday is first day of week */ case 'W': /* week of year, Monday is first day of week */
FMT('0', 2, "d", weeknumber_v(vtm, 1)); FMT('0', 2, "d", weeknumber_v(tmx, 1));
continue; continue;
case 'x': /* appropriate date representation */ case 'x': /* appropriate date representation */
@ -435,17 +435,17 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
continue; continue;
case 'y': /* year without a century, 00 - 99 */ case 'y': /* year without a century, 00 - 99 */
i = NUM2INT(mod(vtm->year, INT2FIX(100))); i = NUM2INT(mod(tmx->year, INT2FIX(100)));
FMT('0', 2, "d", (int)i); FMT('0', 2, "d", (int)i);
continue; continue;
case 'Y': /* year with century */ case 'Y': /* year with century */
if (FIXNUM_P(vtm->year)) { if (FIXNUM_P(tmx->year)) {
long y = FIX2LONG(vtm->year); long y = FIX2LONG(tmx->year);
FMT('0', 0 <= y ? 4 : 5, "ld", y); FMT('0', 0 <= y ? 4 : 5, "ld", y);
} }
else { else {
FMTV('0', 4, "d", vtm->year); FMTV('0', 4, "d", tmx->year);
} }
continue; continue;
@ -455,7 +455,7 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
long aoff; long aoff;
int hl, hw; int hl, hw;
off = NUM2LONG(rb_funcall(vtm->utc_offset, rb_intern("round"), 0)); off = NUM2LONG(rb_funcall(tmx->offset, rb_intern("round"), 0));
aoff = off; aoff = off;
if (aoff < 0) if (aoff < 0)
@ -547,10 +547,10 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
flags &= ~(BIT_OF(UPPER)|BIT_OF(CHCASE)); flags &= ~(BIT_OF(UPPER)|BIT_OF(CHCASE));
flags |= BIT_OF(LOWER); flags |= BIT_OF(LOWER);
} }
if (vtm->zone == NULL) if (tmx->zone == NULL)
tp = ""; tp = "";
else else
tp = vtm->zone; tp = tmx->zone;
i = strlen(tp); i = strlen(tp);
break; break;
@ -570,7 +570,7 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
continue; continue;
case 'e': /* day of month, blank padded */ case 'e': /* day of month, blank padded */
FMT(' ', 2, "d", range(1, vtm->mday, 31)); FMT(' ', 2, "d", range(1, tmx->mday, 31));
continue; continue;
case 'r': /* time as %I:%M:%S %p */ case 'r': /* time as %I:%M:%S %p */
@ -588,12 +588,12 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
#ifdef SUNOS_EXT #ifdef SUNOS_EXT
case 'k': /* hour, 24-hour clock, blank pad */ case 'k': /* hour, 24-hour clock, blank pad */
i = range(0, vtm->hour, 23); i = range(0, tmx->hour, 23);
FMT(' ', 2, "d", (int)i); FMT(' ', 2, "d", (int)i);
continue; continue;
case 'l': /* hour, 12-hour clock, 1 - 12, blank pad */ case 'l': /* hour, 12-hour clock, 1 - 12, blank pad */
i = range(0, vtm->hour, 23); i = range(0, tmx->hour, 23);
if (i == 0) if (i == 0)
i = 12; i = 12;
else if (i > 12) else if (i > 12)
@ -612,7 +612,7 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
#ifdef POSIX2_DATE #ifdef POSIX2_DATE
case 'C': case 'C':
FMTV('0', 2, "d", div(vtm->year, INT2FIX(100))); FMTV('0', 2, "d", div(tmx->year, INT2FIX(100)));
continue; continue;
case 'E': case 'E':
@ -629,12 +629,12 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
goto again; goto again;
goto unknown; goto unknown;
case 'V': /* week of year according ISO 8601 */ case 'V': /* week of year according ISO 8601 */
FMT('0', 2, "d", iso8601wknum_v(vtm)); FMT('0', 2, "d", iso8601wknum_v(tmx));
continue; continue;
case 'u': case 'u':
/* ISO 8601: Weekday as a decimal number [1 (Monday) - 7] */ /* ISO 8601: Weekday as a decimal number [1 (Monday) - 7] */
FMT('0', 1, "d", vtm->wday == 0 ? 7 : vtm->wday); FMT('0', 1, "d", tmx->wday == 0 ? 7 : tmx->wday);
continue; continue;
#endif /* POSIX2_DATE */ #endif /* POSIX2_DATE */
@ -651,11 +651,11 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
* Otherwise, it's this year. * Otherwise, it's this year.
*/ */
{ {
VALUE yv = vtm->year; VALUE yv = tmx->year;
w = iso8601wknum_v(vtm); w = iso8601wknum_v(tmx);
if (vtm->mon == 12 && w == 1) if (tmx->mon == 12 && w == 1)
yv = add(yv, INT2FIX(1)); yv = add(yv, INT2FIX(1));
else if (vtm->mon == 1 && w >= 52) else if (tmx->mon == 1 && w >= 52)
yv = sub(yv, INT2FIX(1)); yv = sub(yv, INT2FIX(1));
if (*format == 'G') { if (*format == 'G') {
@ -699,7 +699,7 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
NEEDS(precision); NEEDS(precision);
{ {
VALUE subsec = mod(timev, INT2FIX(1)); VALUE subsec = mod(tmx->timev, INT2FIX(1));
int ww; int ww;
long n; long n;
@ -816,9 +816,10 @@ date_strftime_wo_timespec(char *s, size_t maxsize, const char *format,
} }
size_t size_t
date_strftime(char *s, size_t maxsize, const char *format, const struct vtm *vtm, VALUE timev) date_strftime(char *s, size_t maxsize, const char *format,
const struct tmx *tmx)
{ {
return date_strftime_wo_timespec(s, maxsize, format, vtm, timev); return date_strftime_with_tmx(s, maxsize, format, tmx);
} }
/* isleap --- is a year a leap year? */ /* isleap --- is a year a leap year? */
@ -837,26 +838,26 @@ isleap(long year)
static void static void
vtm2tm_noyear(const struct vtm *vtm, struct tm *result) tmx2tm_noyear(const struct tmx *tmx, struct tm *result)
{ {
struct tm tm; struct tm tm;
/* for isleap() in iso8601wknum. +100 is -1900 (mod 400). */ /* for isleap() in iso8601wknum. +100 is -1900 (mod 400). */
tm.tm_year = FIX2INT(mod(vtm->year, INT2FIX(400))) + 100; tm.tm_year = FIX2INT(mod(tmx->year, INT2FIX(400))) + 100;
tm.tm_mon = vtm->mon-1; tm.tm_mon = tmx->mon-1;
tm.tm_mday = vtm->mday; tm.tm_mday = tmx->mday;
tm.tm_hour = vtm->hour; tm.tm_hour = tmx->hour;
tm.tm_min = vtm->min; tm.tm_min = tmx->min;
tm.tm_sec = vtm->sec; tm.tm_sec = tmx->sec;
tm.tm_wday = vtm->wday; tm.tm_wday = tmx->wday;
tm.tm_yday = vtm->yday-1; tm.tm_yday = tmx->yday-1;
tm.tm_isdst = vtm->isdst; tm.tm_isdst = 0;
#if defined(HAVE_STRUCT_TM_TM_GMTOFF) #if defined(HAVE_STRUCT_TM_TM_GMTOFF)
tm.tm_gmtoff = NUM2LONG(vtm->utc_offset); tm.tm_gmtoff = NUM2LONG(tmx->offset);
#endif #endif
#if defined(HAVE_TM_ZONE) #if defined(HAVE_TM_ZONE)
tm.tm_zone = (char *)vtm->zone; tm.tm_zone = (char *)tmx->zone;
#endif #endif
*result = tm; *result = tm;
} }
@ -978,10 +979,10 @@ iso8601wknum(const struct tm *timeptr)
} }
static int static int
iso8601wknum_v(const struct vtm *vtm) iso8601wknum_v(const struct tmx *tmx)
{ {
struct tm tm; struct tm tm;
vtm2tm_noyear(vtm, &tm); tmx2tm_noyear(tmx, &tm);
return iso8601wknum(&tm); return iso8601wknum(&tm);
} }
@ -1017,10 +1018,10 @@ weeknumber(const struct tm *timeptr, int firstweekday)
} }
static int static int
weeknumber_v(const struct vtm *vtm, int firstweekday) weeknumber_v(const struct tmx *tmx, int firstweekday)
{ {
struct tm tm; struct tm tm;
vtm2tm_noyear(vtm, &tm); tmx2tm_noyear(tmx, &tm);
return weeknumber(&tm, firstweekday); return weeknumber(&tm, firstweekday);
} }

View file

@ -1,2 +1,2 @@
date_core.o: $(top_srcdir)/timev.h date_core.o: date_tmx.h
date_strftime.o: $(top_srcdir)/timev.h date_strftime.o: date_tmx.h

View file

@ -1,3 +1,2 @@
require 'mkmf' require 'mkmf'
$INCFLAGS << " -I$(top_srcdir)"
create_makefile('date_core') create_makefile('date_core')