summaryrefslogtreecommitdiff
path: root/test/ruby/test_time.rb
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-27 09:18:18 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-27 09:18:18 +0000
commit23b280869314c59be4e4fb01d68ebacf753475a9 (patch)
tree67b49fe3fb2ce6a9e4d6faee0da10fb003f9c6ca /test/ruby/test_time.rb
parent4d033a11c5bd778f124febb30e419bd91d372076 (diff)
* 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
Diffstat (limited to 'test/ruby/test_time.rb')
-rw-r--r--test/ruby/test_time.rb24
1 files changed, 8 insertions, 16 deletions
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index 32d3b976d0..0f54b65cc7 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -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"))