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

ruby-changes:33762

From: akr <ko1@a...>
Date: Tue, 6 May 2014 18:50:17 +0900 (JST)
Subject: [ruby-changes:33762] akr:r45843 (trunk): * lib/time.rb (Time.make_time): Adjust the time zone of "now".

akr	2014-05-06 18:50:08 +0900 (Tue, 06 May 2014)

  New Revision: 45843

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

  Log:
    * lib/time.rb (Time.make_time): Adjust the time zone of "now".

  Modified files:
    trunk/ChangeLog
    trunk/lib/time.rb
    trunk/test/test_time.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45842)
+++ ChangeLog	(revision 45843)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue May  6 18:48:50 2014  Tanaka Akira  <akr@f...>
+
+	* lib/time.rb (Time.make_time): Adjust the time zone of "now".
+
 Tue May  6 18:33:12 2014  Tadayoshi Funaba  <tadf@d...>
 
 	* io.c (io_{read,write}_nonblock): use rb_get_kwargs instead of
Index: lib/time.rb
===================================================================
--- lib/time.rb	(revision 45842)
+++ lib/time.rb	(revision 45843)
@@ -251,8 +251,19 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L251
         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 off
+        now = now.getlocal(off) if now.utc_offset != off
+      else
+        now = now.getlocal
+      end
+
       usec = nil
       usec = sec_fraction * 1000000 if sec_fraction
+
       if now
         begin
           break if year; year = now.year
@@ -273,8 +284,10 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L284
       sec ||= 0
       usec ||= 0
 
-      off = nil
-      off = zone_offset(zone, year) if zone
+      if year != off_year
+        off = nil
+        off = zone_offset(zone, year) if zone
+      end
 
       if off
         year, mon, day, hour, min, sec =
Index: test/test_time.rb
===================================================================
--- test/test_time.rb	(revision 45842)
+++ test/test_time.rb	(revision 45843)
@@ -238,6 +238,14 @@ class TestTimeExtension < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/test_time.rb#L238
     assert_raise(ArgumentError) { Time.parse("foo", now) }
   end
 
+  def test_completion_with_different_timezone
+    now = Time.new(2001,2,3,0,0,0,"+09:00") # 2001-02-02 15:00:00 UTC
+    t = Time.parse("10:20:30 GMT", now)
+    assert_equal(Time.utc(2001,2,2,10,20,30), t)
+    assert_equal(false, t.utc?)
+    assert_equal(0, t.utc_offset)
+  end
+
   def test_invalid
     # They were actually used in some web sites.
     assert_raise(ArgumentError) { Time.httpdate("1 Dec 2001 10:23:57 GMT") }

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

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