Project

General

Profile

Actions

Bug #5232

closed

Encoding of Date#to_s

Added by tenderlovemaking (Aaron Patterson) over 12 years ago. Updated over 12 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.4dev (2011-08-26 trunk 33073) [x86_64-darwin11.1.0]
Backport:
[ruby-core:39116]

Description

The encoding of Date#to_s should respect Encoding.default_internal.

Here is the behavior today:

irb(main):001:0> require 'date'
=> true
irb(main):002:0> Date.today.to_s.encoding
=> #Encoding:US-ASCII
irb(main):003:0> Encoding.default_internal = Encoding::UTF_8
=> #Encoding:UTF-8
irb(main):004:0> Date.today.to_s.encoding
=> #Encoding:US-ASCII
irb(main):005:0>

Here is the behavior I expect:

irb(main):001:0> require 'date'
=> true
irb(main):002:0> Date.today.to_s.encoding
=> #Encoding:US-ASCII
irb(main):003:0> Encoding.default_internal = Encoding::UTF_8
=> #Encoding:UTF-8
irb(main):004:0> Date.today.to_s.encoding
=> #Encoding:UTF-8
irb(main):005:0>

I've attached a patch that fixes this.


Files

date_enc.patch (1.24 KB) date_enc.patch tenderlovemaking (Aaron Patterson), 08/26/2011 11:17 AM

Updated by naruse (Yui NARUSE) over 12 years ago

I doubt that it must be default internal encoding.

When Encoding.default_internal is set, strings should be ASCII-8BIT (its content is binary), US-ASCII,
or default internal encoding.

Is there a reason why you think it should be default internal encoding?

Updated by tenderlovemaking (Aaron Patterson) over 12 years ago

I thought that is what default_internal was used for? If default_internal is set, then strings should be automatically transcoded to that encoding.

It seems strange that if I (as a ruby programmer) request that strings be UTF-8 (by setting default internal), they are returned as another encoding.

Updated by tenderlovemaking (Aaron Patterson) over 12 years ago

I think what I'm trying to say is: why does US-ASCII play a role?

It seems if someone sets default_internal, then strings should either be ASCII-8BIT or default_internal.

Updated by naruse (Yui NARUSE) over 12 years ago

US-ASCII is used for ASCII only strings.
It means pure string in some means.

default internal encoding is used for non ASCII non BINARY strings.

The basis of these is that ASCII is special.

Updated by tadf (tadayoshi funaba) over 12 years ago

  • Status changed from Open to Rejected

why date?

Encoding.default_internal = Encoding::UTF_8
#=> #Encoding:UTF-8
99e99.to_s.encoding
#=> #Encoding:US-ASCII

what's the difference?
this is not a matter of date, anyway.

Updated by naruse (Yui NARUSE) over 12 years ago

tadayoshi funaba wrote:

why date?

Encoding.default_internal = Encoding::UTF_8
#=> #Encoding:UTF-8
99e99.to_s.encoding
#=> #Encoding:US-ASCII

what's the difference?
this is not a matter of date, anyway.

Yeah, even if Aaron's suggest is reasonable, it is the whale Ruby's issue;
This is not correct ticket about it.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0