diff options
author | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-06 11:31:46 +0000 |
---|---|---|
committer | naruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-06 11:31:46 +0000 |
commit | 401168aa138d847009ec98cbd8d4120498691b2a (patch) | |
tree | 62fbf14ca3774a1c65436e1b226be59abff18c0d /ext/date | |
parent | ad837e5a1286ea79e563d3fb928695b171badb83 (diff) |
merge revision(s) 34072,34075,34082:
* ext/date/date_core.c: [ruby-dev:45008].
* ext/date/date_core.c (wholenum): fix the type of the return value.
* ext/date/date_core.c: uses to_integer instead.
* test/date/test_switch_hitter.rb: added a test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_3@34439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/date')
-rw-r--r-- | ext/date/date_core.c | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/ext/date/date_core.c b/ext/date/date_core.c index 251d025b12..e4ecadf700 100644 --- a/ext/date/date_core.c +++ b/ext/date/date_core.c @@ -39,6 +39,7 @@ static double positive_inf, negative_inf; #define f_truncate(x) rb_funcall(x, rb_intern("truncate"), 0) #define f_round(x) rb_funcall(x, rb_intern("round"), 0) +#define f_to_i(x) rb_funcall(x, rb_intern("to_i"), 0) #define f_to_r(x) rb_funcall(x, rb_intern("to_r"), 0) #define f_to_s(x) rb_funcall(x, rb_intern("to_s"), 0) #define f_inspect(x) rb_funcall(x, rb_intern("inspect"), 0) @@ -1324,8 +1325,10 @@ encode_year(VALUE nth, int y, double style, static void decode_jd(VALUE jd, VALUE *nth, int *rjd) { + assert(FIXNUM_P(jd) || RB_TYPE_P(jd, T_BIGNUM)); *nth = f_idiv(jd, INT2FIX(CM_PERIOD)); if (f_zero_p(*nth)) { + assert(FIXNUM_P(jd)); *rjd = FIX2INT(jd); return; } @@ -3095,14 +3098,23 @@ wholenum_p(VALUE x) } inline static VALUE +to_integer(VALUE x) +{ + if (FIXNUM_P(x) || RB_TYPE_P(x, T_BIGNUM)) + return x; + return f_to_i(x); +} + +inline static VALUE d_trunc(VALUE d, VALUE *fr) { VALUE rd; if (wholenum_p(d)) { - rd = d; + rd = to_integer(d); *fr = INT2FIX(0); - } else { + } + else { rd = f_idiv(d, INT2FIX(1)); *fr = f_mod(d, INT2FIX(1)); } @@ -3118,9 +3130,10 @@ h_trunc(VALUE h, VALUE *fr) VALUE rh; if (wholenum_p(h)) { - rh = h; + rh = to_integer(h); *fr = INT2FIX(0); - } else { + } + else { rh = f_idiv(h, INT2FIX(1)); *fr = f_mod(h, INT2FIX(1)); *fr = f_quo(*fr, INT2FIX(24)); @@ -3134,9 +3147,10 @@ min_trunc(VALUE min, VALUE *fr) VALUE rmin; if (wholenum_p(min)) { - rmin = min; + rmin = to_integer(min); *fr = INT2FIX(0); - } else { + } + else { rmin = f_idiv(min, INT2FIX(1)); *fr = f_mod(min, INT2FIX(1)); *fr = f_quo(*fr, INT2FIX(1440)); @@ -3150,9 +3164,10 @@ s_trunc(VALUE s, VALUE *fr) VALUE rs; if (wholenum_p(s)) { - rs = s; + rs = to_integer(s); *fr = INT2FIX(0); - } else { + } + else { rs = f_idiv(s, INT2FIX(1)); *fr = f_mod(s, INT2FIX(1)); *fr = f_quo(*fr, INT2FIX(86400)); |