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

ruby-changes:21395

From: yugui <ko1@a...>
Date: Sun, 9 Oct 2011 22:21:04 +0900 (JST)
Subject: [ruby-changes:21395] yugui:r33444 (ruby_1_9_3): merges r33398 from trunk into ruby_1_9_3.

yugui	2011-10-09 22:19:32 +0900 (Sun, 09 Oct 2011)

  New Revision: 33444

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

  Log:
    merges r33398 from trunk into ruby_1_9_3.
    --
    * lib/time.rb (Time.strptime): use Time.at if d[:seconds] is set.
      Reported by Christopher Eberz. [ruby-core:39903] Bug #5399

  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/lib/time.rb
    branches/ruby_1_9_3/test/test_time.rb

Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 33443)
+++ ruby_1_9_3/ChangeLog	(revision 33444)
@@ -1,3 +1,8 @@
+Tue Oct  4 16:17:50 2011  NARUSE, Yui  <naruse@r...>
+
+	* lib/time.rb (Time.strptime): use Time.at if d[:seconds] is set.
+	  Reported by Christopher Eberz. [ruby-core:39903] Bug #5399
+
 Tue Oct  4 11:44:10 2011  NARUSE, Yui  <naruse@r...>
 
 	* gc.c (rb_gc_set_params): ruby_verbose can be Qnil, so use RTEST.
Index: ruby_1_9_3/lib/time.rb
===================================================================
--- ruby_1_9_3/lib/time.rb	(revision 33443)
+++ ruby_1_9_3/lib/time.rb	(revision 33444)
@@ -281,9 +281,13 @@
     def strptime(date, format, now=self.now)
       d = Date._strptime(date, format)
       raise ArgumentError, "invalid strptime format - `#{format}'" unless d
-      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)
+      if seconds = d[:seconds]
+        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)
+      end
     end
 
     MonthValue = {
Index: ruby_1_9_3/test/test_time.rb
===================================================================
--- ruby_1_9_3/test/test_time.rb	(revision 33443)
+++ ruby_1_9_3/test/test_time.rb	(revision 33444)
@@ -392,6 +392,7 @@
 
   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"))
   end
 
   def test_nsec

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

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