mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* time.c (TIME_UTC_P): new macro..
(TIME_SET_UTC): ditto. (TIME_LOCALTIME_P): ditto. (TIME_SET_LOCALTIME): ditto. (time_utc_p): use the above macro. (time_localtime): ditto. (time_localtime): ditto. (time_gmtime): ditto. (time_to_s): ditto. (time_add): ditto. (time_sec): ditto. (time_min): ditto. (time_hour): ditto. (time_mday): ditto. (time_mon): ditto. (time_year): ditto. (time_wday): ditto. (wday_p): ditto. (time_yday): ditto. (time_isdst): ditto. (time_zone): ditto. (time_utc_offset): ditto. (time_to_a): ditto. (strftimev): ditto. (time_strftime): ditto. (time_mdump): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23271 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
df4cd06d49
commit
afbb1ba21b
2 changed files with 75 additions and 63 deletions
29
ChangeLog
29
ChangeLog
|
@ -1,3 +1,32 @@
|
||||||
|
Sat Apr 25 15:21:33 2009 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* time.c (TIME_UTC_P): new macro..
|
||||||
|
(TIME_SET_UTC): ditto.
|
||||||
|
(TIME_LOCALTIME_P): ditto.
|
||||||
|
(TIME_SET_LOCALTIME): ditto.
|
||||||
|
(time_utc_p): use the above macro.
|
||||||
|
(time_localtime): ditto.
|
||||||
|
(time_localtime): ditto.
|
||||||
|
(time_gmtime): ditto.
|
||||||
|
(time_to_s): ditto.
|
||||||
|
(time_add): ditto.
|
||||||
|
(time_sec): ditto.
|
||||||
|
(time_min): ditto.
|
||||||
|
(time_hour): ditto.
|
||||||
|
(time_mday): ditto.
|
||||||
|
(time_mon): ditto.
|
||||||
|
(time_year): ditto.
|
||||||
|
(time_wday): ditto.
|
||||||
|
(wday_p): ditto.
|
||||||
|
(time_yday): ditto.
|
||||||
|
(time_isdst): ditto.
|
||||||
|
(time_zone): ditto.
|
||||||
|
(time_utc_offset): ditto.
|
||||||
|
(time_to_a): ditto.
|
||||||
|
(strftimev): ditto.
|
||||||
|
(time_strftime): ditto.
|
||||||
|
(time_mdump): ditto.
|
||||||
|
|
||||||
Thu Apr 23 01:30:37 2009 Akinori MUSHA <knu@iDaemons.org>
|
Thu Apr 23 01:30:37 2009 Akinori MUSHA <knu@iDaemons.org>
|
||||||
|
|
||||||
* ext/zlib/zlib.c (Zlib::GzipFile#path): New method.
|
* ext/zlib/zlib.c (Zlib::GzipFile#path): New method.
|
||||||
|
|
109
time.c
109
time.c
|
@ -997,6 +997,19 @@ struct time_object {
|
||||||
#define GetTimeval(obj, tobj) \
|
#define GetTimeval(obj, tobj) \
|
||||||
Data_Get_Struct(obj, struct time_object, tobj)
|
Data_Get_Struct(obj, struct time_object, tobj)
|
||||||
|
|
||||||
|
#define TIME_UTC_P(tobj) ((tobj)->gmt == 1)
|
||||||
|
#define TIME_SET_UTC(tobj) ((tobj)->gmt = 1)
|
||||||
|
|
||||||
|
#define TIME_LOCALTIME_P(tobj) ((tobj)->gmt == 0)
|
||||||
|
#define TIME_SET_LOCALTIME(tobj) ((tobj)->gmt = 0)
|
||||||
|
|
||||||
|
#define MAKE_TM(time, tobj) \
|
||||||
|
do { \
|
||||||
|
if ((tobj)->tm_got == 0) { \
|
||||||
|
time_get_tm((time), (tobj)->gmt); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
static void
|
static void
|
||||||
time_mark(void *ptr)
|
time_mark(void *ptr)
|
||||||
{
|
{
|
||||||
|
@ -2127,7 +2140,7 @@ time_utc_p(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->gmt) return Qtrue;
|
if (TIME_UTC_P(tobj)) return Qtrue;
|
||||||
return Qfalse;
|
return Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2193,7 +2206,7 @@ time_localtime(VALUE time)
|
||||||
struct vtm vtm;
|
struct vtm vtm;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (!tobj->gmt) {
|
if (TIME_LOCALTIME_P(tobj)) {
|
||||||
if (tobj->tm_got)
|
if (tobj->tm_got)
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
@ -2206,7 +2219,7 @@ time_localtime(VALUE time)
|
||||||
tobj->vtm = vtm;
|
tobj->vtm = vtm;
|
||||||
|
|
||||||
tobj->tm_got = 1;
|
tobj->tm_got = 1;
|
||||||
tobj->gmt = 0;
|
TIME_SET_LOCALTIME(tobj);
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2235,7 +2248,7 @@ time_gmtime(VALUE time)
|
||||||
struct vtm vtm;
|
struct vtm vtm;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->gmt) {
|
if (TIME_UTC_P(tobj)) {
|
||||||
if (tobj->tm_got)
|
if (tobj->tm_got)
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
@ -2248,7 +2261,7 @@ time_gmtime(VALUE time)
|
||||||
tobj->vtm = vtm;
|
tobj->vtm = vtm;
|
||||||
|
|
||||||
tobj->tm_got = 1;
|
tobj->tm_got = 1;
|
||||||
tobj->gmt = 1;
|
TIME_SET_UTC(tobj);
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2343,7 +2356,7 @@ time_to_s(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->gmt == 1)
|
if (TIME_UTC_P(tobj))
|
||||||
return strftimev("%Y-%m-%d %H:%M:%S UTC", time);
|
return strftimev("%Y-%m-%d %H:%M:%S UTC", time);
|
||||||
else
|
else
|
||||||
return strftimev("%Y-%m-%d %H:%M:%S %z", time);
|
return strftimev("%Y-%m-%d %H:%M:%S %z", time);
|
||||||
|
@ -2358,9 +2371,9 @@ time_add(struct time_object *tobj, VALUE offset, int sign)
|
||||||
result = time_new_timev(rb_cTime, sub(tobj->timev, offset));
|
result = time_new_timev(rb_cTime, sub(tobj->timev, offset));
|
||||||
else
|
else
|
||||||
result = time_new_timev(rb_cTime, add(tobj->timev, offset));
|
result = time_new_timev(rb_cTime, add(tobj->timev, offset));
|
||||||
if (tobj->gmt) {
|
if (TIME_UTC_P(tobj)) {
|
||||||
GetTimeval(result, tobj);
|
GetTimeval(result, tobj);
|
||||||
tobj->gmt = 1;
|
TIME_SET_UTC(tobj);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -2467,9 +2480,7 @@ time_sec(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
return INT2FIX(tobj->vtm.sec);
|
return INT2FIX(tobj->vtm.sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2489,9 +2500,7 @@ time_min(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
return INT2FIX(tobj->vtm.min);
|
return INT2FIX(tobj->vtm.min);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2511,9 +2520,7 @@ time_hour(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
return INT2FIX(tobj->vtm.hour);
|
return INT2FIX(tobj->vtm.hour);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2535,9 +2542,7 @@ time_mday(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
return INT2FIX(tobj->vtm.mday);
|
return INT2FIX(tobj->vtm.mday);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2559,9 +2564,7 @@ time_mon(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
return INT2FIX(tobj->vtm.mon);
|
return INT2FIX(tobj->vtm.mon);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2581,9 +2584,7 @@ time_year(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
return tobj->vtm.year;
|
return tobj->vtm.year;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2611,18 +2612,14 @@ time_wday(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
return INT2FIX(tobj->vtm.wday);
|
return INT2FIX(tobj->vtm.wday);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define wday_p(n) {\
|
#define wday_p(n) {\
|
||||||
struct time_object *tobj;\
|
struct time_object *tobj;\
|
||||||
GetTimeval(time, tobj);\
|
GetTimeval(time, tobj);\
|
||||||
if (tobj->tm_got == 0) {\
|
MAKE_TM(time, tobj);\
|
||||||
time_get_tm(time, tobj->gmt);\
|
|
||||||
}\
|
|
||||||
return (tobj->vtm.wday == (n)) ? Qtrue : Qfalse;\
|
return (tobj->vtm.wday == (n)) ? Qtrue : Qfalse;\
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2754,9 +2751,7 @@ time_yday(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
return INT2FIX(tobj->vtm.yday);
|
return INT2FIX(tobj->vtm.yday);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2791,9 +2786,7 @@ time_isdst(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
return tobj->vtm.isdst ? Qtrue : Qfalse;
|
return tobj->vtm.isdst ? Qtrue : Qfalse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2816,11 +2809,9 @@ time_zone(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tobj->gmt == 1) {
|
if (TIME_UTC_P(tobj)) {
|
||||||
return rb_str_new2("UTC");
|
return rb_str_new2("UTC");
|
||||||
}
|
}
|
||||||
return rb_str_new2(tobj->vtm.zone);
|
return rb_str_new2(tobj->vtm.zone);
|
||||||
|
@ -2847,11 +2838,9 @@ time_utc_offset(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tobj->gmt == 1) {
|
if (TIME_UTC_P(tobj)) {
|
||||||
return INT2FIX(0);
|
return INT2FIX(0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -2880,9 +2869,7 @@ time_to_a(VALUE time)
|
||||||
struct time_object *tobj;
|
struct time_object *tobj;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
return rb_ary_new3(10,
|
return rb_ary_new3(10,
|
||||||
INT2FIX(tobj->vtm.sec),
|
INT2FIX(tobj->vtm.sec),
|
||||||
INT2FIX(tobj->vtm.min),
|
INT2FIX(tobj->vtm.min),
|
||||||
|
@ -2942,9 +2929,7 @@ strftimev(const char *fmt, VALUE time)
|
||||||
VALUE str;
|
VALUE str;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
len = rb_strftime_alloc(&buf, fmt, &tobj->vtm, tobj->timev, tobj->gmt);
|
len = rb_strftime_alloc(&buf, fmt, &tobj->vtm, tobj->timev, tobj->gmt);
|
||||||
str = rb_str_new(buf, len);
|
str = rb_str_new(buf, len);
|
||||||
if (buf != buffer) xfree(buf);
|
if (buf != buffer) xfree(buf);
|
||||||
|
@ -3011,9 +2996,7 @@ time_strftime(VALUE time, VALUE format)
|
||||||
VALUE str;
|
VALUE str;
|
||||||
|
|
||||||
GetTimeval(time, tobj);
|
GetTimeval(time, tobj);
|
||||||
if (tobj->tm_got == 0) {
|
MAKE_TM(time, tobj);
|
||||||
time_get_tm(time, tobj->gmt);
|
|
||||||
}
|
|
||||||
StringValue(format);
|
StringValue(format);
|
||||||
if (!rb_enc_str_asciicompat_p(format)) {
|
if (!rb_enc_str_asciicompat_p(format)) {
|
||||||
rb_raise(rb_eArgError, "format should have ASCII compatible encoding");
|
rb_raise(rb_eArgError, "format should have ASCII compatible encoding");
|
||||||
|
@ -3091,14 +3074,14 @@ time_mdump(VALUE time)
|
||||||
usec = nsec / 1000;
|
usec = nsec / 1000;
|
||||||
nsec = nsec % 1000;
|
nsec = nsec % 1000;
|
||||||
|
|
||||||
p = 0x1UL << 31 | /* 1 */
|
p = 0x1UL << 31 | /* 1 */
|
||||||
tobj->gmt << 30 | /* 1 */
|
TIME_UTC_P(tobj) << 30 | /* 1 */
|
||||||
(year-1900) << 14 | /* 16 */
|
(year-1900) << 14 | /* 16 */
|
||||||
(vtm.mon-1) << 10 | /* 4 */
|
(vtm.mon-1) << 10 | /* 4 */
|
||||||
vtm.mday << 5 | /* 5 */
|
vtm.mday << 5 | /* 5 */
|
||||||
vtm.hour; /* 5 */
|
vtm.hour; /* 5 */
|
||||||
s = vtm.min << 26 | /* 6 */
|
s = vtm.min << 26 | /* 6 */
|
||||||
vtm.sec << 20 | /* 6 */
|
vtm.sec << 20 | /* 6 */
|
||||||
usec; /* 20 */
|
usec; /* 20 */
|
||||||
|
|
||||||
for (i=0; i<4; i++) {
|
for (i=0; i<4; i++) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue