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

ruby-changes:39518

From: usa <ko1@a...>
Date: Mon, 17 Aug 2015 16:42:12 +0900 (JST)
Subject: [ruby-changes:39518] usa:r51599 (ruby_2_1): merge revision(s) 49788, 49790: [Backport #10904]

usa	2015-08-17 16:41:58 +0900 (Mon, 17 Aug 2015)

  New Revision: 51599

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

  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_1/
  Modified files:
    branches/ruby_2_1/ChangeLog
    branches/ruby_2_1/lib/time.rb
    branches/ruby_2_1/test/test_time.rb
    branches/ruby_2_1/version.h
Index: ruby_2_1/ChangeLog
===================================================================
--- ruby_2_1/ChangeLog	(revision 51598)
+++ ruby_2_1/ChangeLog	(revision 51599)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/ChangeLog#L1
+Mon Aug 17 16:24:10 2015  Tanaka Akira  <akr@f...>
+
+	* lib/time.rb (strptime): Support %s.%N.
+	  [ruby-core:68301] [Bug #10904] Patch by Sadayuki Furuhashi.
+
 Mon Aug 17 16:22:28 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* transcode.c (load_transcoder_entry): fix transcoder loading race
Index: ruby_2_1/lib/time.rb
===================================================================
--- ruby_2_1/lib/time.rb	(revision 51598)
+++ ruby_2_1/lib/time.rb	(revision 51599)
@@ -393,10 +393,16 @@ class Time https://github.com/ruby/ruby/blob/trunk/ruby_2_1/lib/time.rb#L393
       d = Date._strptime(date, format)
       raise ArgumentError, "invalid strptime format - `#{format}'" unless d
       if seconds = d[:seconds]
+        if sec_fraction = d[:sec_fraction]
+          usec = sec_fraction * 1000000
+          usec *= -1 if seconds < 0
+        else
+          usec = 0
+        end
         if offset = d[:offset]
-          Time.at(seconds).localtime(offset)
+          Time.at(seconds, usec).localtime(offset)
         else
-          Time.at(seconds)
+          Time.at(seconds, usec)
         end
       else
         year = d[:year]
Index: ruby_2_1/version.h
===================================================================
--- ruby_2_1/version.h	(revision 51598)
+++ ruby_2_1/version.h	(revision 51599)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_1/version.h#L1
 #define RUBY_VERSION "2.1.7"
 #define RUBY_RELEASE_DATE "2015-08-17"
-#define RUBY_PATCHLEVEL 382
+#define RUBY_PATCHLEVEL 383
 
 #define RUBY_RELEASE_YEAR 2015
 #define RUBY_RELEASE_MONTH 8
Index: ruby_2_1/test/test_time.rb
===================================================================
--- ruby_2_1/test/test_time.rb	(revision 51598)
+++ ruby_2_1/test/test_time.rb	(revision 51599)
@@ -404,6 +404,17 @@ class TestTimeExtension < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/ruby_2_1/test/test_time.rb#L404
     assert_equal(3600, Time.strptime('0 +0100', '%s %z').utc_offset)
   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_nsec
     assert_equal(123456789, Time.xmlschema("2000-01-01T00:00:00.123456789+00:00").tv_nsec)
     assert_equal(123456789, Time.parse("2000-01-01T00:00:00.123456789+00:00").tv_nsec)

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


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

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