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

ruby-changes:33715

From: akr <ko1@a...>
Date: Sat, 3 May 2014 20:31:42 +0900 (JST)
Subject: [ruby-changes:33715] akr:r45796 (trunk): * lib/time.rb (Time.strptime): Use d[:offset] if d[:seconds] is not

akr	2014-05-03 20:31:33 +0900 (Sat, 03 May 2014)

  New Revision: 45796

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

  Log:
    * lib/time.rb (Time.strptime): Use d[:offset] if d[:seconds] is not
      given.
      Reported by tadayoshi funaba.  [ruby-core:62322]

  Modified files:
    trunk/ChangeLog
    trunk/lib/time.rb
    trunk/test/test_time.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45795)
+++ ChangeLog	(revision 45796)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat May  3 20:21:38 2014  Tanaka Akira  <akr@f...>
+
+	* lib/time.rb (Time.strptime): Use d[:offset] if d[:seconds] is not
+	  given.
+	  Reported by tadayoshi funaba.  [ruby-core:62322]
+
 Sat May  3 04:04:16 2014  Eric Wong  <e@8...>
 
 	* complex.c (parse_comp): replace ALLOCA_N with ALLOCV_N/ALLOCV_END
Index: lib/time.rb
===================================================================
--- lib/time.rb	(revision 45795)
+++ lib/time.rb	(revision 45796)
@@ -393,16 +393,16 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L393
       d = Date._strptime(date, format)
       raise ArgumentError, "invalid strptime format - `#{format}'" unless d
       if seconds = d[:seconds]
-        if offset = d[:offset]
-          Time.at(seconds).localtime(offset)
-        else
-          Time.at(seconds)
-        end
+        t = Time.at(seconds)
       else
         year = d[:year]
         year = yield(year) if year && block_given?
-        make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
+        t = make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
       end
+      if offset = d[:offset]
+        t.localtime(offset)
+      end
+      t
     end
 
     MonthValue = { # :nodoc:
Index: test/test_time.rb
===================================================================
--- test/test_time.rb	(revision 45795)
+++ test/test_time.rb	(revision 45796)
@@ -402,6 +402,7 @@ class TestTimeExtension < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/test_time.rb#L402
     assert_equal(Time.at(1).localtime, Time.strptime("1", "%s"))
     assert_equal(false, Time.strptime('0', '%s').utc?)
     assert_equal(3600, Time.strptime('0 +0100', '%s %z').utc_offset)
+    assert_equal(-7200, Time.strptime('20010203 -0200', '%Y%m%d %z').utc_offset)
   end
 
   def test_nsec

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

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