Project

General

Profile

Actions

Bug #5226

closed

Encoding of Time#to_s

Added by tenderlovemaking (Aaron Patterson) about 13 years ago. Updated about 13 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.4dev (2011-08-25 trunk 33051) [x86_64-darwin11.1.0]
Backport:
[ruby-core:39092]

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

time_enc.patch (1.32 KB) time_enc.patch tenderlovemaking (Aaron Patterson), 08/25/2011 06:02 AM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0