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

ruby-changes:21349

From: naruse <ko1@a...>
Date: Tue, 4 Oct 2011 16:37:24 +0900 (JST)
Subject: [ruby-changes:21349] naruse:r33398 (trunk): * lib/time.rb (Time.strptime): use Time.at if d[:seconds] is set.

naruse	2011-10-04 16:37:11 +0900 (Tue, 04 Oct 2011)

  New Revision: 33398

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

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

  Modified files:
    trunk/ChangeLog
    trunk/lib/time.rb
    trunk/test/test_time.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 33397)
+++ ChangeLog	(revision 33398)
@@ -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 15:04:43 2011  Nobuyoshi Nakada  <nobu@r...>
 
 	* class.c (class_alloc): allocate extra memory after containing
Index: lib/time.rb
===================================================================
--- lib/time.rb	(revision 33397)
+++ lib/time.rb	(revision 33398)
@@ -280,9 +280,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: test/test_time.rb
===================================================================
--- test/test_time.rb	(revision 33397)
+++ test/test_time.rb	(revision 33398)
@@ -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/

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