diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-02-18 01:56:47 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-02-18 01:56:47 +0000 |
commit | a9662810df18371af7492dd8298cc0cccc13c7c7 (patch) | |
tree | 5a1131ad0ca461f67177e1c7282eacc92356f864 /time.c | |
parent | 14aa2e8dda852b6b9277a8a7e16a78654edf1767 (diff) |
1.1b8pre1
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@76 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 80 |
1 files changed, 47 insertions, 33 deletions
@@ -50,13 +50,13 @@ 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, 0, tobj); tobj->tm_got=0; if (gettimeofday(&(tobj->tv), 0) == -1) { @@ -67,14 +67,14 @@ time_s_now(class) } 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); + obj = Data_Make_Struct(klass, struct time_object, 0, 0, tobj); tobj->tm_got = 0; tobj->tv.tv_sec = sec; tobj->tv.tv_usec = usec; @@ -135,13 +135,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); + return time_new_internal(klass, tv.tv_sec, tv.tv_usec); } static char *months [12] = { @@ -158,7 +158,17 @@ 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]); if (args[0] < 70) args[0] += 100; @@ -183,7 +193,7 @@ time_arg(argc, argv, args) } } else { - args[1] = NUM2INT(v[1]); + args[1] = NUM2INT(v[1]) - 1; } if (v[2] == Qnil) { args[2] = 1; @@ -211,11 +221,11 @@ time_arg(argc, argv, args) } 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; @@ -250,28 +260,28 @@ 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); + return time_new_internal(klass, guess, 0); error: ArgError("gmtime/localtime error"); } 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 @@ -576,6 +586,7 @@ time_mon(time) if (tobj->tm_got == 0) { time_localtime(time); } + Warning("Time#month now start from 1 for January"); return INT2FIX(tobj->tm.tm_mon+1); } @@ -589,6 +600,7 @@ time_year(time) if (tobj->tm_got == 0) { time_localtime(time); } + Warning("Time#year now returns 19xx"); return INT2FIX(tobj->tm.tm_year+1900); } @@ -628,7 +640,8 @@ time_isdst(time) if (tobj->tm_got == 0) { time_localtime(time); } - return INT2FIX(tobj->tm.tm_isdst); + Warning("Time#isdst now returns boolean value"); + return tobj->tm.tm_isdst?TRUE:FALSE; } static VALUE @@ -659,17 +672,18 @@ time_to_a(time) 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+1), - INT2FIX(tobj->tm.tm_year+1900), - INT2FIX(tobj->tm.tm_wday), - INT2FIX(tobj->tm.tm_yday), - INT2FIX(tobj->tm.tm_isdst)); - return ary; + Warning("Time#to_a's return values are now changed"); + return 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?TRUE:FALSE, + time_zone(time)); } #define SMALLBUF 100 @@ -728,7 +742,7 @@ time_strftime(time, format) } len = rb_strftime(&buf, RSTRING(format)->ptr, &(tobj->tm)); str = str_new(buf, len); - if (len > SMALLBUF) free(buf); + if (buf != buffer) free(buf); return str; } |