retry committing ChangeLog and time.c
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@5486 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4e880080a7
commit
058fd78390
@ -1,3 +1,10 @@
|
||||
Sun Jan 18 12:07:24 2004 Siena. <siena@faculty.chiba-u.jp>
|
||||
|
||||
* test/ruby/test_time.rb: new test case to test Time#[+-].
|
||||
|
||||
* time.c (time_plus, time_minus): fix RangeError for a negative
|
||||
argument in environments whose time_t is unsigned. [ruby-dev:22608]
|
||||
|
||||
Sun Jan 18 02:33:26 2004 WATANABE Hirofumi <eban@ruby-lang.org>
|
||||
|
||||
* defines.h (_WIN32): undef _WIN32 on Cygwin before defining DOSISH.
|
||||
|
22
time.c
22
time.c
@ -1183,6 +1183,7 @@ time_plus(time1, time2)
|
||||
struct time_object *tobj;
|
||||
time_t sec, usec;
|
||||
double f, d, v;
|
||||
int sign;
|
||||
|
||||
GetTimeval(time1, tobj);
|
||||
|
||||
@ -1191,21 +1192,23 @@ time_plus(time1, time2)
|
||||
}
|
||||
v = NUM2DBL(time2);
|
||||
d = modf(v, &f);
|
||||
sign = ( f < 0 ? -1 : 1 );
|
||||
f *= sign;
|
||||
sec = (time_t)f;
|
||||
if (f != (double)sec) {
|
||||
rb_raise(rb_eRangeError, "time + %f out of Time range", v);
|
||||
}
|
||||
#ifndef NEGATIVE_TIME_T
|
||||
if (f < 0 && -f >= tobj->tv.tv_sec) {
|
||||
if (sign < 0 && f >= tobj->tv.tv_sec) {
|
||||
rb_raise(rb_eArgError, "time must be positive");
|
||||
}
|
||||
#endif
|
||||
usec = tobj->tv.tv_usec + (time_t)(d*1e6);
|
||||
sec = tobj->tv.tv_sec + (time_t)f;
|
||||
sec = ( sign > 0 ? tobj->tv.tv_sec + sec : tobj->tv.tv_sec - sec );
|
||||
|
||||
#ifdef NEGATIVE_TIME_T
|
||||
if ((tobj->tv.tv_sec >= 0 && f >= 0 && sec < 0) ||
|
||||
(tobj->tv.tv_sec <= 0 && f <= 0 && sec > 0)) {
|
||||
if ((tobj->tv.tv_sec >= 0 && sign >= 0 && sec < 0) ||
|
||||
(tobj->tv.tv_sec <= 0 && sign <= 0 && sec > 0)) {
|
||||
rb_raise(rb_eRangeError, "time + %f out of Time range", v);
|
||||
}
|
||||
#endif
|
||||
@ -1239,6 +1242,7 @@ time_minus(time1, time2)
|
||||
struct time_object *tobj;
|
||||
time_t sec, usec;
|
||||
double f, d, v;
|
||||
int sign;
|
||||
|
||||
GetTimeval(time1, tobj);
|
||||
if (TYPE(time2) == T_DATA && RDATA(time2)->dfree == time_free) {
|
||||
@ -1253,20 +1257,22 @@ time_minus(time1, time2)
|
||||
}
|
||||
v = NUM2DBL(time2);
|
||||
d = modf(v, &f);
|
||||
sign = ( f < 0 ? -1 : 1 );
|
||||
f *= sign;
|
||||
sec = (time_t)f;
|
||||
if (f != (double)sec) {
|
||||
rb_raise(rb_eRangeError, "time - %f out of Time range", v);
|
||||
}
|
||||
#ifndef NEGATIVE_TIME_T
|
||||
if (f > 0 && f >= tobj->tv.tv_sec) {
|
||||
if (sign > 0 && f >= tobj->tv.tv_sec) {
|
||||
rb_raise(rb_eArgError, "time must be positive");
|
||||
}
|
||||
#endif
|
||||
usec = tobj->tv.tv_usec - (time_t)(d*1e6);
|
||||
sec = tobj->tv.tv_sec - (time_t)f;
|
||||
sec = ( sign > 0 ? tobj->tv.tv_sec - sec : tobj->tv.tv_sec + sec );
|
||||
#ifdef NEGATIVE_TIME_T
|
||||
if ((tobj->tv.tv_sec <= 0 && f >= 0 && sec > 0) ||
|
||||
(tobj->tv.tv_sec >= 0 && f <= 0 && sec < 0)) {
|
||||
if ((tobj->tv.tv_sec <= 0 && sign >= 0 && sec > 0) ||
|
||||
(tobj->tv.tv_sec >= 0 && sign <= 0 && sec < 0)) {
|
||||
rb_raise(rb_eRangeError, "time - %f out of Time range", v);
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user