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

ruby-changes:31098

From: akr <ko1@a...>
Date: Mon, 7 Oct 2013 20:10:08 +0900 (JST)
Subject: [ruby-changes:31098] akr:r43177 (trunk): * lib/time.rb (Time.strptime): Use :offset.

akr	2013-10-07 20:10:03 +0900 (Mon, 07 Oct 2013)

  New Revision: 43177

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

  Log:
    * lib/time.rb (Time.strptime): Use :offset.
      Patch by Felipe Contreras.  [ruby-core:57694]

  Modified files:
    trunk/ChangeLog
    trunk/lib/time.rb
    trunk/test/test_time.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43176)
+++ ChangeLog	(revision 43177)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Oct  7 20:07:20 2013  Tanaka Akira  <akr@f...>
+
+	* lib/time.rb (Time.strptime): Use :offset.
+	  Patch by Felipe Contreras.  [ruby-core:57694]
+
 Mon Oct  7 16:47:27 2013  Koichi Sasada  <ko1@a...>
 
 	* test/-ext-/debug/test_profile_frames.rb: rename class C to
Index: lib/time.rb
===================================================================
--- lib/time.rb	(revision 43176)
+++ lib/time.rb	(revision 43177)
@@ -393,7 +393,8 @@ 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]
-        Time.at(seconds)
+        offset = d[:offset] || 0
+        Time.at(seconds).localtime(offset)
       else
         year = d[:year]
         year = yield(year) if year && block_given?
Index: test/test_time.rb
===================================================================
--- test/test_time.rb	(revision 43176)
+++ test/test_time.rb	(revision 43177)
@@ -400,6 +400,8 @@ class TestTimeExtension < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/test_time.rb#L400
   def test_strptime
     assert_equal(Time.utc(2005, 8, 28, 06, 54, 20), Time.strptime("28/Aug/2005:06:54:20 +0000", "%d/%b/%Y:%T %z"))
     assert_equal(Time.at(1).localtime, Time.strptime("1", "%s"))
+    assert_equal(0, Time.strptime('0', '%s').utc_offset)
+    assert_equal(3600, Time.strptime('0 +0100', '%s %z').utc_offset)
   end
 
   def test_nsec

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

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