diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-12-03 10:06:39 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2001-12-03 10:06:39 +0000 |
commit | 553634322c31c4f3bd18b77c83e22426e6976b14 (patch) | |
tree | bc659264a05e4068d749b1e2167f39bd7526d241 /time.c | |
parent | 7ff058e9f2c78956faf73dbeccef8cec63488d22 (diff) |
* time.c (time_new_internal): round usec overflow and underflow
here.
* time.c (time_plus): remove overflow/underflow check.
* time.c (time_minus): ditto.
* time.c (time_cmp): should consider tv_usec too.
* time.c (time_gmtime): time_modify() should be called even if tm
struct is not calculated yet.
* string.c (rb_str_equal): object with to_str must be treated as a
string.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1879 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'time.c')
-rw-r--r-- | time.c | 46 |
1 files changed, 25 insertions, 21 deletions
@@ -87,6 +87,14 @@ time_new_internal(klass, sec, usec) VALUE obj; struct time_object *tobj; + if (usec >= 1000000) { /* usec overflow */ + sec += usec / 1000000; + usec %= 1000000; + } + if (usec < 0) { /* usec underflow */ + sec -= (-usec) / 1000000; + usec %= 1000000; + } if (sec < 0 || (sec == 0 && usec < 0)) rb_raise(rb_eArgError, "time must be positive"); @@ -459,7 +467,13 @@ time_cmp(time1, time2) switch (TYPE(time2)) { case T_FIXNUM: i = FIX2LONG(time2); - if (tobj1->tv.tv_sec == i) return INT2FIX(0); + if (tobj1->tv.tv_sec == i) { + if (tobj1->tv.tv_usec == 0) + return INT2FIX(0); + if (tobj1->tv.tv_usec > 0) + return INT2FIX(1); + return INT2FIX(-1); + } if (tobj1->tv.tv_sec > i) return INT2FIX(1); return INT2FIX(-1); @@ -564,8 +578,11 @@ time_localtime(time) time_t t; GetTimeval(time, tobj); - if (tobj->tm_got) { - if (!tobj->gmt) return time; + if (!tobj->gmt) { + if (tobj->tm_got) + return time; + } + else { time_modify(time); } t = tobj->tv.tv_sec; @@ -585,8 +602,11 @@ time_gmtime(time) time_t t; GetTimeval(time, tobj); - if (tobj->tm_got) { - if (tobj->gmt) return time; + if (tobj->gmt) { + if (tobj->tm_got) + return time; + } + else { time_modify(time); } t = tobj->tv.tv_sec; @@ -662,14 +682,6 @@ time_plus(time1, time2) usec = tobj->tv.tv_usec + (time_t)((f - (double)sec)*1e6); sec = tobj->tv.tv_sec + sec; - if (usec >= 1000000) { /* usec overflow */ - sec++; - usec -= 1000000; - } - if (usec < 0) { /* usec underflow */ - sec--; - usec += 1000000; - } time2 = rb_time_new(sec, usec); if (tobj->gmt) { GetTimeval(time2, tobj); @@ -703,14 +715,6 @@ time_minus(time1, time2) sec = tobj->tv.tv_sec - sec; } - if (usec >= 1000000) { /* usec overflow */ - sec++; - usec -= 1000000; - } - if (usec < 0) { /* usec underflow */ - sec--; - usec += 1000000; - } time2 = rb_time_new(sec, usec); if (tobj->gmt) { GetTimeval(time2, tobj); |