Project

General

Profile

Actions

Bug #5226

closed

Encoding of Time#to_s

Added by tenderlovemaking (Aaron Patterson) over 13 years ago. Updated over 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

Updated by shyouhei (Shyouhei Urabe) over 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) over 13 years ago

OK. I will apply this patch.

Actions #3

Updated by naruse (Yui NARUSE) over 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.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0