[前][次][番号順一覧][スレッド一覧]

ruby-changes:39394

From: nagachika <ko1@a...>
Date: Tue, 4 Aug 2015 04:11:48 +0900 (JST)
Subject: [ruby-changes:39394] nagachika:r51475 (ruby_2_2): merge revision(s) 49788, 49790: [Backport #10904]

nagachika	2015-08-04 04:11:41 +0900 (Tue, 04 Aug 2015)

  New Revision: 51475

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51475

  Log:
    merge revision(s) 49788,49790: [Backport #10904]
    
    * lib/time.rb (strptime): Support %s.%N.
      [ruby-core:68301] [Bug #10904] Patch by Sadayuki Furuhashi.

  Modified directories:
    branches/ruby_2_2/
  Modified files:
    branches/ruby_2_2/ChangeLog
    branches/ruby_2_2/lib/time.rb
    branches/ruby_2_2/test/test_time.rb
    branches/ruby_2_2/version.h
Index: ruby_2_2/ChangeLog
===================================================================
--- ruby_2_2/ChangeLog	(revision 51474)
+++ ruby_2_2/ChangeLog	(revision 51475)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/ChangeLog#L1
+Tue Aug  4 04:11:34 2015  Tanaka Akira  <akr@f...>
+
+	* 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@r...>
 
 	* transcode.c (load_transcoder_entry): fix transcoder loading race
Index: ruby_2_2/lib/time.rb
===================================================================
--- ruby_2_2/lib/time.rb	(revision 51474)
+++ ruby_2_2/lib/time.rb	(revision 51475)
@@ -426,7 +426,13 @@ class Time https://github.com/ruby/ruby/blob/trunk/ruby_2_2/lib/time.rb#L426
       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
Index: ruby_2_2/version.h
===================================================================
--- ruby_2_2/version.h	(revision 51474)
+++ ruby_2_2/version.h	(revision 51475)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_2/version.h#L1
 #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
Index: ruby_2_2/test/test_time.rb
===================================================================
--- ruby_2_2/test/test_time.rb	(revision 51474)
+++ ruby_2_2/test/test_time.rb	(revision 51475)
@@ -448,6 +448,17 @@ class TestTimeExtension < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/ruby_2_2/test/test_time.rb#L448
     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)

Property changes on: ruby_2_2
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r49788,49790


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]