Bug #5226
closedEncoding of Time#to_s
Description
I think the encoding of Time#to_s should default to US-ASCII, but respect Encoding.default_internal. Today it always returns a binary string:
irb(main):001:0> Time.now.to_s.encoding
=> #Encoding:ASCII-8BIT
irb(main):002:0> Encoding.default_internal = Encoding::UTF_8
=> #Encoding:UTF-8
irb(main):003:0> Time.now.to_s.encoding
=> #Encoding:ASCII-8BIT
irb(main):004:0>
I've attached a patch to make Time#to_s respect Encoding.default_internal. The result is:
irb(main):001:0> Encoding.default_internal
=> nil
irb(main):002:0> Time.now.to_s.encoding
=> #Encoding:US-ASCII
irb(main):003:0> Encoding.default_internal = Encoding::UTF_8
=> #Encoding:UTF-8
irb(main):004:0> Time.now.to_s.encoding
=> #Encoding:UTF-8
irb(main):005:0>
Files
Updated by shyouhei (Shyouhei Urabe) about 13 years ago
- Category set to M17N
+1.
As of 1.9.4dev it seems there exists no chance for Time#to_s to produce M17N-problematic result.
Updated by tenderlovemaking (Aaron Patterson) about 13 years ago
OK. I will apply this patch.
Updated by naruse (Yui NARUSE) about 13 years ago
- Status changed from Open to Closed
- % Done changed from 0 to 100
This issue was solved with changeset r33094.
Aaron, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.
-
strftime.c (rb_strftime_with_timespec): get enc argument to specify
the encoding of the format. On Windows (at least Japanese Windows),
Time#strftime("%Z") includes non ASCII in locale encoding (CP932).
So convert locale to default internal. [ruby-core:39092] [Bug #5226] -
strftime.c (rb_strftime): ditto.
-
strftime.c (rb_strftime_timespec): ditto.
-
internal.h (rb_strftime_timespec): follow above.
-
time.c (rb_strftime_alloc): ditto.
-
time.c (strftimev): ditto.
-
time.c (time_strftime): ditto.
-
time.c (time_to_s): the resulted string of Time#to_s is always
ascii only, so this should be US-ASCII. -
time.c (time_asctime): ditto.