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

ruby-changes:44522

From: akr <ko1@a...>
Date: Sat, 5 Nov 2016 23:03:41 +0900 (JST)
Subject: [ruby-changes:44522] akr:r56595 (trunk): Time.parse's "now" argument as nil works again.

akr	2016-11-05 23:03:34 +0900 (Sat, 05 Nov 2016)

  New Revision: 56595

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

  Log:
    Time.parse's "now" argument as nil works again.
    
    * lib/time.rb (make_time): "now" argument as nil works again.
      This is broken since Ruby 2.2.
      Mathieu Jobin pointed a problem.
      https://github.com/ruby/ruby/commit/e4b05d91eb0d48fd172abf015c493bb42d755d07#commitcomment-17421387

  Modified files:
    trunk/ChangeLog
    trunk/lib/time.rb
    trunk/test/test_time.rb
Index: lib/time.rb
===================================================================
--- lib/time.rb	(revision 56594)
+++ lib/time.rb	(revision 56595)
@@ -254,14 +254,18 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L254
         raise ArgumentError, "no time information in #{date.inspect}"
       end
 
-      off_year = year || now.year
       off = nil
-      off = zone_offset(zone, off_year) if zone
+      if year || now
+        off_year = year || now.year
+        off = zone_offset(zone, off_year) if zone
+      end
 
-      if off
-        now = now.getlocal(off) if now.utc_offset != off
-      else
-        now = now.getlocal
+      if now
+        if off
+          now = now.getlocal(off) if now.utc_offset != off
+        else
+          now = now.getlocal
+        end
       end
 
       usec = nil
Index: test/test_time.rb
===================================================================
--- test/test_time.rb	(revision 56594)
+++ test/test_time.rb	(revision 56595)
@@ -338,6 +338,11 @@ class TestTimeExtension < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/test_time.rb#L338
     assert_equal(t1.utc?, t2.utc?)
   end
 
+  def test_parse_now_nil
+    assert_equal(Time.new(2000,1,1,0,0,0,"+11:00"),
+                 Time.parse("2000-01-01T00:00:00+11:00", nil))
+  end
+
   def test_parse_leap_second
     t = Time.utc(1998,12,31,23,59,59)
     assert_equal(t, Time.parse("Thu Dec 31 23:59:59 UTC 1998"))
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56594)
+++ ChangeLog	(revision 56595)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Nov  5 22:51:06 2016  Tanaka Akira  <akr@f...>
+
+	* lib/time.rb (make_time): "now" argument as nil works again.
+	  This is broken since Ruby 2.2.
+	  Mathieu Jobin pointed a problem.
+	  https://github.com/ruby/ruby/commit/e4b05d91eb0d48fd172abf015c493bb42d755d07#commitcomment-17421387
+
 Sat Nov  5 22:50:13 2016  Akinori MUSHA  <knu@i...>
 
 	* lib/ipaddr.rb (IPAddr#==): If coercion fails, return false

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

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