mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
strftime.c: Bignum conversion
* strftime.c (format_value): convert from Bignum to String, instead of rb_str_format. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@54253 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
2460214780
commit
dc54e38041
2 changed files with 20 additions and 9 deletions
20
strftime.c
20
strftime.c
|
@ -196,14 +196,11 @@ case_conv(char *s, ptrdiff_t i, int flags)
|
|||
}
|
||||
|
||||
static VALUE
|
||||
format_value(const char *fmt, VALUE val, int precision)
|
||||
format_value(VALUE val, int base)
|
||||
{
|
||||
struct RString fmtv;
|
||||
VALUE str = rb_setup_fake_str(&fmtv, fmt, strlen(fmt), 0);
|
||||
VALUE args[2];
|
||||
args[0] = INT2FIX(precision);
|
||||
args[1] = val;
|
||||
return rb_str_format(2, args, str);
|
||||
if (!RB_TYPE_P(val, T_BIGNUM))
|
||||
val = rb_Integer(val);
|
||||
return rb_big2str(val, base);
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -323,9 +320,14 @@ rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len,
|
|||
FMT((def_pad), (def_prec), "l"fmt, FIX2LONG(tmp)); \
|
||||
} \
|
||||
else { \
|
||||
const char *fmts = FMT_PADDING(fmt, def_pad); \
|
||||
const int base = ((fmt[0] == 'x') ? 16 : \
|
||||
(fmt[0] == 'o') ? 8 : \
|
||||
10); \
|
||||
precision = FMT_PRECISION(def_prec); \
|
||||
tmp = format_value(fmts, tmp, precision); \
|
||||
if (!padding) padding = (def_pad); \
|
||||
tmp = format_value(tmp, base); \
|
||||
i = RSTRING_LEN(tmp); \
|
||||
FILL_PADDING(i); \
|
||||
rb_str_set_len(ftime, s-start); \
|
||||
rb_str_append(ftime, tmp); \
|
||||
RSTRING_GETMEM(ftime, s, len); \
|
||||
|
|
|
@ -680,6 +680,12 @@ class TestTime < Test::Unit::TestCase
|
|||
t = Time.at(946684800, 123456.789)
|
||||
assert_equal("946684800", t.strftime("%s"))
|
||||
assert_equal("946684800", t.utc.strftime("%s"))
|
||||
|
||||
t = Time.at(10000000000000000000000)
|
||||
assert_equal("<<10000000000000000000000>>", t.strftime("<<%s>>"))
|
||||
assert_equal("<<010000000000000000000000>>", t.strftime("<<%24s>>"))
|
||||
assert_equal("<<010000000000000000000000>>", t.strftime("<<%024s>>"))
|
||||
assert_equal("<< 10000000000000000000000>>", t.strftime("<<%_24s>>"))
|
||||
end
|
||||
|
||||
def test_strftime_zone
|
||||
|
@ -759,6 +765,9 @@ class TestTime < Test::Unit::TestCase
|
|||
|
||||
t = Time.utc(10000000000000000000000,1,1)
|
||||
assert_equal("<<10000000000000000000000>>", t.strftime("<<%Y>>"))
|
||||
assert_equal("<<010000000000000000000000>>", t.strftime("<<%24Y>>"))
|
||||
assert_equal("<<010000000000000000000000>>", t.strftime("<<%024Y>>"))
|
||||
assert_equal("<< 10000000000000000000000>>", t.strftime("<<%_24Y>>"))
|
||||
end
|
||||
|
||||
def test_strftime_weeknum
|
||||
|
|
Loading…
Reference in a new issue