summaryrefslogtreecommitdiff
path: root/time.c
diff options
context:
space:
mode:
Diffstat (limited to 'time.c')
-rw-r--r--time.c405
1 files changed, 252 insertions, 153 deletions
diff --git a/time.c b/time.c
index 1749c32319..fc14d8e5b6 100644
--- a/time.c
+++ b/time.c
@@ -6,13 +6,18 @@
$Date$
created at: Tue Dec 28 14:31:59 JST 1993
- Copyright (C) 1993-1996 Yukihiro Matsumoto
+ Copyright (C) 1993-1998 Yukihiro Matsumoto
************************************************/
#include "ruby.h"
#include <sys/types.h>
+#ifdef USE_CWGUSI
+int gettimeofday(struct timeval*, struct timezone*);
+int strcasecmp(char*, char*);
+#endif
+
#include <time.h>
#ifndef NT
#ifdef HAVE_SYS_TIME_H
@@ -30,11 +35,10 @@ struct timeval {
#endif
#include <math.h>
-static VALUE cTime;
+VALUE rb_cTime;
#if defined(HAVE_TIMES) || defined(NT)
static VALUE S_Tms;
#endif
-extern VALUE mComparable;
struct time_object {
struct timeval tv;
@@ -50,31 +54,34 @@ struct time_object {
}
static VALUE
-time_s_now(class)
- VALUE class;
+time_s_now(klass)
+ VALUE klass;
{
VALUE obj;
struct time_object *tobj;
- obj = Data_Make_Struct(class, struct time_object, 0, 0, tobj);
+ obj = Data_Make_Struct(klass, struct time_object, 0, free, tobj);
tobj->tm_got=0;
if (gettimeofday(&(tobj->tv), 0) == -1) {
rb_sys_fail("gettimeofday");
}
+ rb_obj_call_init(obj);
return obj;
}
static VALUE
-time_new_internal(class, sec, usec)
- VALUE class;
+time_new_internal(klass, sec, usec)
+ VALUE klass;
int sec, usec;
{
VALUE obj;
struct time_object *tobj;
- obj = Data_Make_Struct(class, struct time_object, 0, 0, tobj);
+ if (sec < 0 || (sec == 0 && usec < 0))
+ rb_raise(rb_eArgError, "time must be positive");
+ obj = Data_Make_Struct(klass, struct time_object, 0, free, tobj);
tobj->tm_got = 0;
tobj->tv.tv_sec = sec;
tobj->tv.tv_usec = usec;
@@ -83,14 +90,14 @@ time_new_internal(class, sec, usec)
}
VALUE
-time_new(sec, usec)
+rb_time_new(sec, usec)
int sec, usec;
{
- return time_new_internal(cTime, sec, usec);
+ return time_new_internal(rb_cTime, sec, usec);
}
struct timeval
-time_timeval(time)
+rb_time_timeval(time)
VALUE time;
{
struct time_object *tobj;
@@ -98,34 +105,30 @@ time_timeval(time)
switch (TYPE(time)) {
case T_FIXNUM:
- t.tv_sec = FIX2UINT(time);
+ t.tv_sec = FIX2INT(time);
if (t.tv_sec < 0)
- ArgError("time must be positive");
+ rb_raise(rb_eArgError, "time must be positive");
t.tv_usec = 0;
break;
case T_FLOAT:
- {
- double seconds, microseconds;
-
- if (RFLOAT(time)->value < 0.0)
- ArgError("time must be positive");
- seconds = floor(RFLOAT(time)->value);
- microseconds = (RFLOAT(time)->value - seconds) * 1000000.0;
- t.tv_sec = seconds;
- t.tv_usec = microseconds;
- }
+ if (RFLOAT(time)->value < 0.0)
+ rb_raise(rb_eArgError, "time must be positive");
+ t.tv_sec = (long)floor(RFLOAT(time)->value);
+ t.tv_usec = (long)((RFLOAT(time)->value - t.tv_sec) * 1000000.0);
break;
case T_BIGNUM:
t.tv_sec = NUM2INT(time);
+ if (t.tv_sec < 0)
+ rb_raise(rb_eArgError, "time must be positive");
t.tv_usec = 0;
break;
default:
- if (!obj_is_kind_of(time, cTime)) {
- TypeError("Can't convert %s into Time",
- rb_class2name(CLASS_OF(time)));
+ if (!rb_obj_is_kind_of(time, rb_cTime)) {
+ rb_raise(rb_eTypeError, "Can't convert %s into Time",
+ rb_class2name(CLASS_OF(time)));
}
GetTimeval(time, tobj);
t = tobj->tv;
@@ -135,13 +138,13 @@ time_timeval(time)
}
static VALUE
-time_s_at(class, time)
- VALUE class, time;
+time_s_at(klass, time)
+ VALUE klass, time;
{
struct timeval tv;
- tv = time_timeval(time);
- return time_new_internal(class, tv.tv_sec, tv.tv_usec);
+ tv = rb_time_timeval(time);
+ return time_new_internal(klass, tv.tv_sec, tv.tv_usec);
}
static char *months [12] = {
@@ -149,6 +152,17 @@ static char *months [12] = {
"jul", "aug", "sep", "oct", "nov", "dec",
};
+static int
+obj2int(obj)
+ VALUE obj;
+{
+ if (TYPE(obj) == T_STRING) {
+ obj = rb_str2inum(RSTRING(obj)->ptr, 10);
+ }
+
+ return NUM2INT(obj);
+}
+
static void
time_arg(argc, argv, args)
int argc;
@@ -158,12 +172,22 @@ time_arg(argc, argv, args)
VALUE v[6];
int i;
- rb_scan_args(argc, argv, "15", &v[0], &v[1], &v[2], &v[3], &v[4], &v[5]);
+ if (argc == 10) {
+ v[0] = argv[5];
+ v[1] = argv[4];
+ v[2] = argv[3];
+ v[3] = argv[2];
+ v[4] = argv[1];
+ v[5] = argv[0];
+ }
+ else {
+ rb_scan_args(argc, argv, "15", &v[0],&v[1],&v[2],&v[3],&v[4],&v[5]);
+ }
- args[0] = NUM2INT(v[0]);
+ args[0] = obj2int(v[0]);
if (args[0] < 70) args[0] += 100;
if (args[0] > 1900) args[0] -= 1900;
- if (v[1] == Qnil) {
+ if (NIL_P(v[1])) {
args[1] = 0;
}
else if (TYPE(v[1]) == T_STRING) {
@@ -178,44 +202,46 @@ time_arg(argc, argv, args)
char c = RSTRING(v[1])->ptr[0];
if ('0' <= c && c <= '9') {
- args[1] = NUM2INT(v[1])-1;
+ args[1] = obj2int(v[1])-1;
}
}
}
else {
- args[1] = NUM2INT(v[1]);
+ args[1] = obj2int(v[1]) - 1;
}
- if (v[2] == Qnil) {
+ if (NIL_P(v[2])) {
args[2] = 1;
}
else {
- args[2] = NUM2INT(v[2]);
+ args[2] = obj2int(v[2]);
}
for (i=3;i<6;i++) {
- if (v[i] == Qnil) {
+ if (NIL_P(v[i])) {
args[i] = 0;
}
else {
- args[i] = NUM2INT(v[i]);
+ args[i] = obj2int(v[i]);
}
}
/* value validation */
- if ( args[0] < 70|| args[1] > 137
+ if ( args[0] < 70|| args[0] > 137
|| args[1] < 0 || args[1] > 11
|| args[2] < 1 || args[2] > 31
|| args[3] < 0 || args[3] > 23
- || args[4] < 0 || args[4] > 60
- || args[5] < 0 || args[5] > 61)
- ArgError("argument out of range");
+ || args[4] < 0 || args[4] > 59
+ || args[5] < 0 || args[5] > 60)
+ rb_raise(rb_eArgError, "argument out of range");
}
+static VALUE time_gmtime _((VALUE));
+static VALUE time_localtime _((VALUE));
static VALUE
-time_gm_or_local(argc, argv, gm_or_local, class)
+time_gm_or_local(argc, argv, gm_or_local, klass)
int argc;
VALUE *argv;
int gm_or_local;
- VALUE class;
+ VALUE klass;
{
int args[6];
struct timeval tv;
@@ -223,6 +249,7 @@ time_gm_or_local(argc, argv, gm_or_local, class)
time_t guess, t;
int diff;
struct tm *(*fn)();
+ VALUE time;
fn = (gm_or_local) ? gmtime : localtime;
time_arg(argc, argv, args);
@@ -233,9 +260,9 @@ time_gm_or_local(argc, argv, gm_or_local, class)
tm = (*fn)(&guess);
if (!tm) goto error;
t = args[0];
- while (diff = t - tm->tm_year) {
+ while (diff = t - (tm->tm_year)) {
guess += diff * 364 * 24 * 3600;
- if (guess < 0) ArgError("too far future");
+ if (guess < 0) rb_raise(rb_eArgError, "too far future");
tm = (*fn)(&guess);
if (!tm) goto error;
}
@@ -250,28 +277,31 @@ time_gm_or_local(argc, argv, gm_or_local, class)
guess += (args[4] - tm->tm_min) * 60;
guess += args[5] - tm->tm_sec;
- return time_new_internal(class, guess, 0);
+ time = time_new_internal(klass, guess, 0);
+ if (gm_or_local) return time_gmtime(time);
+ return time_localtime(time);
error:
- ArgError("gmtime error");
+ rb_raise(rb_eArgError, "gmtime/localtime error");
+ return Qnil; /* not reached */
}
static VALUE
-time_s_timegm(argc, argv, class)
+time_s_timegm(argc, argv, klass)
int argc;
VALUE *argv;
- VALUE class;
+ VALUE klass;
{
- return time_gm_or_local(argc, argv, 1, class);
+ return time_gm_or_local(argc, argv, 1, klass);
}
static VALUE
-time_s_timelocal(argc, argv, class)
+time_s_timelocal(argc, argv, klass)
int argc;
VALUE *argv;
- VALUE class;
+ VALUE klass;
{
- return time_gm_or_local(argc, argv, 0, class);
+ return time_gm_or_local(argc, argv, 0, klass);
}
static VALUE
@@ -281,7 +311,7 @@ time_to_i(time)
struct time_object *tobj;
GetTimeval(time, tobj);
- return int2inum(tobj->tv.tv_sec);
+ return rb_int2inum(tobj->tv.tv_sec);
}
static VALUE
@@ -291,7 +321,7 @@ time_to_f(time)
struct time_object *tobj;
GetTimeval(time, tobj);
- return float_new((double)tobj->tv.tv_sec+(double)tobj->tv.tv_usec/1000000);
+ return rb_float_new((double)tobj->tv.tv_sec+(double)tobj->tv.tv_usec/1000000);
}
static VALUE
@@ -331,7 +361,7 @@ time_cmp(time1, time2)
}
}
- if (obj_is_instance_of(time2, cTime)) {
+ if (rb_obj_is_instance_of(time2, rb_cTime)) {
GetTimeval(time2, tobj2);
if (tobj1->tv.tv_sec == tobj2->tv.tv_sec) {
if (tobj1->tv.tv_usec == tobj2->tv.tv_usec) return INT2FIX(0);
@@ -354,13 +384,13 @@ time_eql(time1, time2)
struct time_object *tobj1, *tobj2;
GetTimeval(time1, tobj1);
- if (obj_is_instance_of(time2, cTime)) {
+ if (rb_obj_is_instance_of(time2, rb_cTime)) {
GetTimeval(time2, tobj2);
if (tobj1->tv.tv_sec == tobj2->tv.tv_sec) {
- if (tobj1->tv.tv_usec == tobj2->tv.tv_usec) return TRUE;
+ if (tobj1->tv.tv_usec == tobj2->tv.tv_usec) return Qtrue;
}
}
- return FALSE;
+ return Qfalse;
}
static VALUE
@@ -414,6 +444,23 @@ time_asctime(time)
VALUE time;
{
struct time_object *tobj;
+ char *s;
+
+ GetTimeval(time, tobj);
+ if (tobj->tm_got == 0) {
+ time_localtime(time);
+ }
+ s = asctime(&(tobj->tm));
+ if (s[24] == '\n') s[24] = '\0';
+
+ return rb_str_new2(s);
+}
+
+static VALUE
+time_to_s(time)
+ VALUE time;
+{
+ struct time_object *tobj;
char buf[64];
int len;
@@ -430,7 +477,7 @@ time_asctime(time)
{
len = strftime(buf, 64, "%a %b %d %H:%M:%S %Z %Y", &(tobj->tm));
}
- return str_new(buf, len);
+ return rb_str_new(buf, len);
}
static VALUE
@@ -438,15 +485,15 @@ time_plus(time1, time2)
VALUE time1, time2;
{
struct time_object *tobj1, *tobj2;
- int sec, usec;
+ long sec, usec;
GetTimeval(time1, tobj1);
if (TYPE(time2) == T_FLOAT) {
unsigned int nsec = (unsigned int)RFLOAT(time2)->value;
sec = tobj1->tv.tv_sec + nsec;
- usec = tobj1->tv.tv_usec + (RFLOAT(time2)->value - (double)nsec)*1e6;
+ usec = tobj1->tv.tv_usec + (long)(RFLOAT(time2)->value-(double)nsec)*1e6;
}
- else if (obj_is_instance_of(time2, cTime)) {
+ else if (rb_obj_is_instance_of(time2, rb_cTime)) {
GetTimeval(time2, tobj2);
sec = tobj1->tv.tv_sec + tobj2->tv.tv_sec;
usec = tobj1->tv.tv_usec + tobj2->tv.tv_usec;
@@ -460,7 +507,7 @@ time_plus(time1, time2)
sec++;
usec -= 1000000;
}
- return time_new(sec, usec);
+ return rb_time_new(sec, usec);
}
static VALUE
@@ -471,7 +518,7 @@ time_minus(time1, time2)
int sec, usec;
GetTimeval(time1, tobj1);
- if (obj_is_instance_of(time2, cTime)) {
+ if (rb_obj_is_instance_of(time2, rb_cTime)) {
double f;
GetTimeval(time2, tobj2);
@@ -479,7 +526,7 @@ time_minus(time1, time2)
f += (tobj1->tv.tv_usec - tobj2->tv.tv_usec)*1e-6;
- return float_new(f);
+ return rb_float_new(f);
}
else if (TYPE(time2) == T_FLOAT) {
sec = tobj1->tv.tv_sec - (int)RFLOAT(time2)->value;
@@ -494,7 +541,7 @@ time_minus(time1, time2)
sec--;
usec += 1000000;
}
- return time_new(sec, usec);
+ return rb_time_new(sec, usec);
}
static VALUE
@@ -559,7 +606,7 @@ time_mon(time)
if (tobj->tm_got == 0) {
time_localtime(time);
}
- return INT2FIX(tobj->tm.tm_mon);
+ return INT2FIX(tobj->tm.tm_mon+1);
}
static VALUE
@@ -572,7 +619,7 @@ time_year(time)
if (tobj->tm_got == 0) {
time_localtime(time);
}
- return INT2FIX(tobj->tm.tm_year);
+ return INT2FIX(tobj->tm.tm_year+1900);
}
static VALUE
@@ -611,7 +658,7 @@ time_isdst(time)
if (tobj->tm_got == 0) {
time_localtime(time);
}
- return INT2FIX(tobj->tm.tm_isdst);
+ return tobj->tm.tm_isdst?Qtrue:Qfalse;
}
static VALUE
@@ -628,7 +675,7 @@ time_zone(time)
}
len = strftime(buf, 10, "%Z", &(tobj->tm));
- return str_new(buf, len);
+ return rb_str_new(buf, len);
}
static VALUE
@@ -636,23 +683,22 @@ time_to_a(time)
VALUE time;
{
struct time_object *tobj;
- VALUE ary;
GetTimeval(time, tobj);
if (tobj->tm_got == 0) {
time_localtime(time);
}
- ary = ary_new3(9,
- INT2FIX(tobj->tm.tm_sec),
- INT2FIX(tobj->tm.tm_min),
- INT2FIX(tobj->tm.tm_hour),
- INT2FIX(tobj->tm.tm_mday),
- INT2FIX(tobj->tm.tm_mon),
- INT2FIX(tobj->tm.tm_year),
- INT2FIX(tobj->tm.tm_wday),
- INT2FIX(tobj->tm.tm_yday),
- INT2FIX(tobj->tm.tm_isdst));
- return ary;
+ return rb_ary_new3(10,
+ INT2FIX(tobj->tm.tm_sec),
+ INT2FIX(tobj->tm.tm_min),
+ INT2FIX(tobj->tm.tm_hour),
+ INT2FIX(tobj->tm.tm_mday),
+ INT2FIX(tobj->tm.tm_mon+1),
+ INT2FIX(tobj->tm.tm_year+1900),
+ INT2FIX(tobj->tm.tm_wday),
+ INT2FIX(tobj->tm.tm_yday),
+ tobj->tm.tm_isdst?Qtrue:Qfalse,
+ time_zone(time));
}
#define SMALLBUF 100
@@ -677,7 +723,8 @@ rb_strftime(buf, format, time)
return len;
}
- ArgError("bad strftime format or result too long");
+ rb_raise(rb_eArgError, "bad strftime format or result too long");
+ return Qnil; /* not reached */
}
static VALUE
@@ -686,32 +733,32 @@ time_strftime(time, format)
{
struct time_object *tobj;
char buffer[SMALLBUF];
+ char *fmt;
char *buf = buffer;
int len;
VALUE str;
- Check_Type(format, T_STRING);
GetTimeval(time, tobj);
if (tobj->tm_got == 0) {
time_localtime(time);
}
- if (strlen(RSTRING(format)->ptr) < RSTRING(format)->len) {
+ fmt = str2cstr(format, &len);
+ if (strlen(fmt) < len) {
/* Ruby string may contain \0's. */
- int l;
- char *p = RSTRING(format)->ptr, *pe = p + RSTRING(format)->len;
+ char *p = fmt, *pe = fmt + len;
- str = str_new(0, 0);
+ str = rb_str_new(0, 0);
while (p < pe) {
len = rb_strftime(&buf, p, &(tobj->tm));
- str_cat(str, buf, len);
+ rb_str_cat(str, buf, len);
p += strlen(p) + 1;
if (len > SMALLBUF) free(buf);
}
return str;
}
len = rb_strftime(&buf, RSTRING(format)->ptr, &(tobj->tm));
- str = str_new(buf, len);
- if (len > SMALLBUF) free(buf);
+ str = rb_str_new(buf, len);
+ if (buf != buffer) free(buf);
return str;
}
@@ -726,11 +773,11 @@ time_s_times(obj)
struct tms buf;
if (times(&buf) == -1) rb_sys_fail(0);
- return struct_new(S_Tms,
- float_new((double)buf.tms_utime / HZ),
- float_new((double)buf.tms_stime / HZ),
- float_new((double)buf.tms_cutime / HZ),
- float_new((double)buf.tms_cstime / HZ));
+ return rb_struct_new(S_Tms,
+ rb_float_new((double)buf.tms_utime / HZ),
+ rb_float_new((double)buf.tms_stime / HZ),
+ rb_float_new((double)buf.tms_cutime / HZ),
+ rb_float_new((double)buf.tms_cstime / HZ));
#else
#ifdef NT
FILETIME create, exit, kernel, user;
@@ -738,69 +785,121 @@ time_s_times(obj)
hProc = GetCurrentProcess();
GetProcessTimes(hProc,&create, &exit, &kernel, &user);
- return struct_new(S_Tms,
- float_new((double)(kernel.dwHighDateTime*2e32+kernel.dwLowDateTime)/2e6),
- float_new((double)(user.dwHighDateTime*2e32+user.dwLowDateTime)/2e6),
- float_new((double)0),
- float_new((double)0));
+ return rb_struct_new(S_Tms,
+ rb_float_new((double)(kernel.dwHighDateTime*2e32+kernel.dwLowDateTime)/2e6),
+ rb_float_new((double)(user.dwHighDateTime*2e32+user.dwLowDateTime)/2e6),
+ rb_float_new((double)0),
+ rb_float_new((double)0));
#else
rb_notimplement();
#endif
#endif
}
+static VALUE
+time_dump(time, limit)
+ VALUE time, limit;
+{
+ struct time_object *tobj;
+ int sec, usec;
+ unsigned char buf[8];
+ int i;
+
+ GetTimeval(time, tobj);
+ sec = tobj->tv.tv_sec;
+ usec = tobj->tv.tv_usec;
+
+ for (i=0; i<4; i++) {
+ buf[i] = sec & 0xff;
+ sec = RSHIFT(sec, 8);
+ }
+ for (i=4; i<8; i++) {
+ buf[i] = usec & 0xff;
+ usec = RSHIFT(usec, 8);
+ }
+ return rb_str_new(buf, 8);
+}
+
+static VALUE
+time_load(klass, str)
+ VALUE klass, str;
+{
+ int sec, usec;
+ unsigned char *buf;
+ int i;
+
+ buf = str2cstr(str, &i);
+ if (i != 8) {
+ rb_raise(rb_eTypeError, "marshaled time format differ");
+ }
+
+ sec = usec = 0;
+ for (i=0; i<4; i++) {
+ sec |= buf[i]<<(8*i);
+ }
+ for (i=4; i<8; i++) {
+ usec |= buf[i]<<(8*(i-4));
+ }
+
+ return time_new_internal(klass, sec, usec);
+}
+
void
Init_Time()
{
- cTime = rb_define_class("Time", cObject);
- rb_include_module(cTime, mComparable);
-
- rb_define_singleton_method(cTime, "now", time_s_now, 0);
- rb_define_singleton_method(cTime, "new", time_s_now, 0);
- rb_define_singleton_method(cTime, "at", time_s_at, 1);
- rb_define_singleton_method(cTime, "gm", time_s_timegm, -1);
- rb_define_singleton_method(cTime, "local", time_s_timelocal, -1);
- rb_define_singleton_method(cTime, "mktime", time_s_timelocal, -1);
-
- rb_define_singleton_method(cTime, "times", time_s_times, 0);
-
- rb_define_method(cTime, "to_i", time_to_i, 0);
- rb_define_method(cTime, "to_f", time_to_f, 0);
- rb_define_method(cTime, "<=>", time_cmp, 1);
- rb_define_method(cTime, "eql?", time_eql, 0);
- rb_define_method(cTime, "hash", time_hash, 0);
-
- rb_define_method(cTime, "localtime", time_localtime, 0);
- rb_define_method(cTime, "gmtime", time_gmtime, 0);
- rb_define_method(cTime, "ctime", time_asctime, 0);
- rb_define_method(cTime, "asctime", time_asctime, 0);
- rb_define_method(cTime, "to_s", time_asctime, 0);
- rb_define_method(cTime, "inspect", time_asctime, 0);
- rb_define_method(cTime, "to_a", time_to_a, 0);
-
- rb_define_method(cTime, "+", time_plus, 1);
- rb_define_method(cTime, "-", time_minus, 1);
-
- rb_define_method(cTime, "sec", time_sec, 0);
- rb_define_method(cTime, "min", time_min, 0);
- rb_define_method(cTime, "hour", time_hour, 0);
- rb_define_method(cTime, "mday", time_mday, 0);
- rb_define_method(cTime, "day", time_mday, 0);
- rb_define_method(cTime, "mon", time_mon, 0);
- rb_define_method(cTime, "month", time_mon, 0);
- rb_define_method(cTime, "year", time_year, 0);
- rb_define_method(cTime, "wday", time_wday, 0);
- rb_define_method(cTime, "yday", time_yday, 0);
- rb_define_method(cTime, "isdst", time_isdst, 0);
- rb_define_method(cTime, "zone", time_zone, 0);
-
- rb_define_method(cTime, "tv_sec", time_to_i, 0);
- rb_define_method(cTime, "tv_usec", time_usec, 0);
- rb_define_method(cTime, "usec", time_usec, 0);
-
- rb_define_method(cTime, "strftime", time_strftime, 1);
+ rb_cTime = rb_define_class("Time", rb_cObject);
+ rb_include_module(rb_cTime, rb_mComparable);
+
+ rb_define_singleton_method(rb_cTime, "now", time_s_now, 0);
+ rb_define_singleton_method(rb_cTime, "new", time_s_now, 0);
+ rb_define_singleton_method(rb_cTime, "at", time_s_at, 1);
+ rb_define_singleton_method(rb_cTime, "gm", time_s_timegm, -1);
+ rb_define_singleton_method(rb_cTime, "local", time_s_timelocal, -1);
+ rb_define_singleton_method(rb_cTime, "mktime", time_s_timelocal, -1);
+
+ rb_define_singleton_method(rb_cTime, "times", time_s_times, 0);
+
+ rb_define_method(rb_cTime, "to_i", time_to_i, 0);
+ rb_define_method(rb_cTime, "to_f", time_to_f, 0);
+ rb_define_method(rb_cTime, "<=>", time_cmp, 1);
+ rb_define_method(rb_cTime, "eql?", time_eql, 1);
+ rb_define_method(rb_cTime, "hash", time_hash, 0);
+
+ rb_define_method(rb_cTime, "localtime", time_localtime, 0);
+ rb_define_method(rb_cTime, "gmtime", time_gmtime, 0);
+ rb_define_method(rb_cTime, "ctime", time_asctime, 0);
+ rb_define_method(rb_cTime, "asctime", time_asctime, 0);
+ rb_define_method(rb_cTime, "to_s", time_to_s, 0);
+ rb_define_method(rb_cTime, "inspect", time_to_s, 0);
+ rb_define_method(rb_cTime, "to_a", time_to_a, 0);
+
+ rb_define_method(rb_cTime, "+", time_plus, 1);
+ rb_define_method(rb_cTime, "-", time_minus, 1);
+
+ rb_define_method(rb_cTime, "sec", time_sec, 0);
+ rb_define_method(rb_cTime, "min", time_min, 0);
+ rb_define_method(rb_cTime, "hour", time_hour, 0);
+ rb_define_method(rb_cTime, "mday", time_mday, 0);
+ rb_define_method(rb_cTime, "day", time_mday, 0);
+ rb_define_method(rb_cTime, "mon", time_mon, 0);
+ rb_define_method(rb_cTime, "month", time_mon, 0);
+ rb_define_method(rb_cTime, "year", time_year, 0);
+ rb_define_method(rb_cTime, "wday", time_wday, 0);
+ rb_define_method(rb_cTime, "yday", time_yday, 0);
+ rb_define_method(rb_cTime, "isdst", time_isdst, 0);
+ rb_define_method(rb_cTime, "zone", time_zone, 0);
+
+ rb_define_method(rb_cTime, "tv_sec", time_to_i, 0);
+ rb_define_method(rb_cTime, "tv_usec", time_usec, 0);
+ rb_define_method(rb_cTime, "usec", time_usec, 0);
+
+ rb_define_method(rb_cTime, "strftime", time_strftime, 1);
#if defined(HAVE_TIMES) || defined(NT)
- S_Tms = struct_define("Tms", "utime", "stime", "cutime", "cstime", 0);
+ S_Tms = rb_struct_define("Tms", "utime", "stime", "cutime", "cstime", 0);
#endif
+
+ /* methods for marshaling */
+ rb_define_singleton_method(rb_cTime, "_load", time_load, 1);
+ rb_define_method(rb_cTime, "_dump", time_dump, 1);
}