1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* time.c (strftimev): Make Time#to_s default to US-ASCII encoding but

respect Encoding.default_internal. [ruby-core:39092]
* test/ruby/test_time.rb (class TestTime): Corresponding test.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33073 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tenderlove 2011-08-25 23:24:33 +00:00
parent a6e30a8714
commit 4544b3824c
4 changed files with 29 additions and 0 deletions

View file

@ -1,3 +1,9 @@
Fri Aug 26 08:21:10 2011 Aaron Patterson <aaron@tenderlovemaking.com>
* time.c (strftimev): Make Time#to_s default to US-ASCII encoding but
respect Encoding.default_internal. [ruby-core:39092]
* test/ruby/test_time.rb (class TestTime): Corresponding test.
Thu Aug 25 09:43:16 2011 Eric Hodel <drbrain@segment7.net>
* ext/openssl/lib/openssl/bn.rb: Hide copyright info from RDoc.

5
NEWS
View file

@ -24,6 +24,11 @@ with all sufficient information, see the ChangeLog file.
* Signal.trap raises ArgumentError when :SEGV, :BUS, :ILL, :FPE, :VTALRM
are specified.
* Time
* change return value:
* Time#to_s returned encoding defaults to US-ASCII but automatically
transcodes to Encoding.default_internal if it is set.
=== Language changes
=== Compatibility issues (excluding feature bug fixes)

View file

@ -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))

2
time.c
View file

@ -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;
}