mirror of
https://github.com/ruby/ruby.git
synced 2025-09-20 11:03:58 +02:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33094 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
4d033a11c5
commit
23b2808693
5 changed files with 90 additions and 49 deletions
|
@ -15,22 +15,6 @@ 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))
|
||||
|
@ -433,15 +417,21 @@ class TestTime < Test::Unit::TestCase
|
|||
|
||||
def test_asctime
|
||||
assert_equal("Sat Jan 1 00:00:00 2000", T2000.asctime)
|
||||
assert_equal(Encoding::US_ASCII, T2000.asctime.encoding)
|
||||
assert_kind_of(String, Time.at(0).asctime)
|
||||
end
|
||||
|
||||
def test_to_s
|
||||
assert_equal("2000-01-01 00:00:00 UTC", T2000.to_s)
|
||||
assert_equal(Encoding::US_ASCII, T2000.to_s.encoding)
|
||||
assert_kind_of(String, Time.at(946684800).getlocal.to_s)
|
||||
assert_equal(Time.at(946684800).getlocal.to_s, Time.at(946684800).to_s)
|
||||
end
|
||||
|
||||
def test_zone
|
||||
assert_equal(Encoding.find('locale'), Time.now.zone.encoding)
|
||||
end
|
||||
|
||||
def test_plus_minus_succ
|
||||
# assert_raise(RangeError) { T2000 + 10000000000 }
|
||||
# assert_raise(RangeError) T2000 - 3094168449 }
|
||||
|
@ -565,6 +555,8 @@ class TestTime < Test::Unit::TestCase
|
|||
|
||||
t = Time.mktime(2001, 10, 1)
|
||||
assert_equal("2001-10-01", t.strftime("%F"))
|
||||
assert_equal(Encoding::UTF_8, t.strftime("\u3042%Z").encoding)
|
||||
assert_equal(true, t.strftime("\u3042%Z").valid_encoding?)
|
||||
|
||||
t = Time.mktime(2001, 10, 1, 2, 0, 0)
|
||||
assert_equal("01", t.strftime("%d"))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue