summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--NEWS5
-rw-r--r--test/ruby/test_time.rb16
-rw-r--r--time.c2
4 files changed, 29 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index e058d861dd..e25b8ec650 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/NEWS b/NEWS
index d16e73971c..56a25f31d8 100644
--- a/NEWS
+++ b/NEWS
@@ -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)
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index 1f07a8249c..32d3b976d0 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 ebe0ab9bd9..fbd0ecf198 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;
}