diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index 1f07a82..32d3b97 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -15,6 +15,22 @@ class TestTime < Test::Unit::TestCase $VERBOSE = @verbose end + def test_to_s_default_encoding + before = Encoding.default_internal + Encoding.default_internal = nil + assert_equal Encoding::US_ASCII, Time.now.to_s.encoding + ensure + Encoding.default_internal = before + end + + def test_to_s_transcoding + before = Encoding.default_internal + Encoding.default_internal = Encoding::UTF_8 + assert_equal Encoding::UTF_8, Time.now.to_s.encoding + ensure + Encoding.default_internal = before + end + def test_new assert_equal(Time.utc(2000,2,10), Time.new(2000,2,10, 11,0,0, 3600*11)) assert_equal(Time.utc(2000,2,10), Time.new(2000,2,9, 13,0,0, -3600*11)) diff --git a/time.c b/time.c index 6817c75..a091dcd 100644 --- a/time.c +++ b/time.c @@ -4347,6 +4347,8 @@ strftimev(const char *fmt, VALUE time) MAKE_TM(time, tobj); len = rb_strftime_alloc(&buf, fmt, &tobj->vtm, tobj->timew, TIME_UTC_P(tobj)); str = rb_str_new(buf, len); + rb_enc_associate_index(str, rb_usascii_encindex()); + str = rb_str_export_to_enc(str, rb_default_internal_encoding()); if (buf != buffer) xfree(buf); return str; }