diff options
author | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-08-03 19:11:41 +0000 |
---|---|---|
committer | nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2015-08-03 19:11:41 +0000 |
commit | 9fa5924294b6d43c8ef6300741bb842a66ee7923 (patch) | |
tree | 63daae718bb22b35f58942e30048eb820f57a139 | |
parent | 43850e265597ef173d6bfcbcfc8f34e92094716c (diff) |
merge revision(s) 49788,49790: [Backport #10904]
* lib/time.rb (strptime): Support %s.%N.
[ruby-core:68301] [Bug #10904] Patch by Sadayuki Furuhashi.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_2@51475 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | lib/time.rb | 8 | ||||
-rw-r--r-- | test/test_time.rb | 11 | ||||
-rw-r--r-- | version.h | 2 |
4 files changed, 24 insertions, 2 deletions
@@ -1,3 +1,8 @@ +Tue Aug 4 04:11:34 2015 Tanaka Akira <akr@fsij.org> + + * lib/time.rb (strptime): Support %s.%N. + [ruby-core:68301] [Bug #10904] Patch by Sadayuki Furuhashi. + Tue Aug 4 03:43:15 2015 Nobuyoshi Nakada <nobu@ruby-lang.org> * transcode.c (load_transcoder_entry): fix transcoder loading race diff --git a/lib/time.rb b/lib/time.rb index d39c4f6515..134d0af0ac 100644 --- a/lib/time.rb +++ b/lib/time.rb @@ -426,7 +426,13 @@ class Time d = Date._strptime(date, format) raise ArgumentError, "invalid strptime format - `#{format}'" unless d if seconds = d[:seconds] - t = Time.at(seconds) + if sec_fraction = d[:sec_fraction] + usec = sec_fraction * 1000000 + usec *= -1 if seconds < 0 + else + usec = 0 + end + t = Time.at(seconds, usec) if zone = d[:zone] force_zone!(t, zone) end diff --git a/test/test_time.rb b/test/test_time.rb index f39713b249..2f34464f32 100644 --- a/test/test_time.rb +++ b/test/test_time.rb @@ -448,6 +448,17 @@ class TestTimeExtension < Test::Unit::TestCase # :nodoc: assert_equal(true, t.utc?) end + def test_strptime_s_N + assert_equal(Time.at(1, 500000), Time.strptime("1.5", "%s.%N")) + assert_equal(Time.at(-2, 500000), Time.strptime("-1.5", "%s.%N")) + t = Time.strptime("1.000000000001", "%s.%N") + assert_equal(1, t.to_i) + assert_equal(Rational("0.000000000001"), t.subsec) + t = Time.strptime("-1.000000000001", "%s.%N") + assert_equal(-2, t.to_i) + assert_equal(1-Rational("0.000000000001"), t.subsec) + end + def test_strptime_Ymd_z t = Time.strptime('20010203 -0200', '%Y%m%d %z') assert_equal(2001, t.year) @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.2.3" #define RUBY_RELEASE_DATE "2015-08-04" -#define RUBY_PATCHLEVEL 149 +#define RUBY_PATCHLEVEL 150 #define RUBY_RELEASE_YEAR 2015 #define RUBY_RELEASE_MONTH 8 |