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

ruby-changes:33717

From: akr <ko1@a...>
Date: Sun, 4 May 2014 00:23:38 +0900 (JST)
Subject: [ruby-changes:33717] akr:r45798 (trunk): * lib/time.rb (make_time): Produce fixed-offset time object if

akr	2014-05-04 00:23:29 +0900 (Sun, 04 May 2014)

  New Revision: 45798

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

  Log:
    * lib/time.rb (make_time): Produce fixed-offset time object if
      appropriate.
      (Time.strptime): Use d[:zone] instead of d[:offset].
    
    * lib/rss/rss.rb (Time.w3cdtf): Produce fixed-offset time object if
      appropriate.

  Modified files:
    trunk/ChangeLog
    trunk/lib/rss/rss.rb
    trunk/lib/time.rb
    trunk/test/test_time.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45797)
+++ ChangeLog	(revision 45798)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat May  3 23:52:20 2014  Tanaka Akira  <akr@f...>
+
+	* lib/time.rb (make_time): Produce fixed-offset time object if
+	  appropriate.
+	  (Time.strptime): Use d[:zone] instead of d[:offset].
+
+	* lib/rss/rss.rb (Time.w3cdtf): Produce fixed-offset time object if
+	  appropriate.
+
 Sat May  3 20:21:38 2014  Tanaka Akira  <akr@f...>
 
 	* lib/time.rb (Time.strptime): Use d[:offset] if d[:seconds] is not
Index: lib/rss/rss.rb
===================================================================
--- lib/rss/rss.rb	(revision 45797)
+++ lib/rss/rss.rb	(revision 45798)
@@ -28,7 +28,7 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/rss/rss.rb#L28
             datetime = apply_offset(*(datetime + [off]))
             datetime << usec
             time = Time.utc(*datetime)
-            time.localtime unless zone_utc?(zone)
+            time.localtime(off) unless zone_utc?(zone)
             time
           else
             datetime << usec
Index: lib/time.rb
===================================================================
--- lib/time.rb	(revision 45797)
+++ lib/time.rb	(revision 45798)
@@ -258,7 +258,11 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L258
         year, mon, day, hour, min, sec =
           apply_offset(year, mon, day, hour, min, sec, off)
         t = self.utc(year, mon, day, hour, min, sec, usec)
-        t.localtime if !zone_utc?(zone)
+        if zone_utc?(zone)
+          t.utc
+        else
+          t.localtime(off)
+        end
         t
       else
         self.local(year, mon, day, hour, min, sec, usec)
@@ -394,14 +398,18 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/time.rb#L398
       raise ArgumentError, "invalid strptime format - `#{format}'" unless d
       if seconds = d[:seconds]
         t = Time.at(seconds)
+        if zone = d[:zone]
+          if zone_utc?(zone)
+            t.utc
+          elsif offset = zone_offset(zone)
+            t.localtime(offset)
+          end
+        end
       else
         year = d[:year]
         year = yield(year) if year && block_given?
         t = make_time(year, d[:mon], d[:mday], d[:hour], d[:min], d[:sec], d[:sec_fraction], d[:zone], now)
       end
-      if offset = d[:offset]
-        t.localtime(offset)
-      end
       t
     end
 
Index: test/test_time.rb
===================================================================
--- test/test_time.rb	(revision 45797)
+++ test/test_time.rb	(revision 45798)
@@ -407,6 +407,10 @@ class TestTimeExtension < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/test_time.rb#L407
     t = Time.strptime('0 +0100', '%s %z')
     assert_equal(0, t.to_r)
     assert_equal(3600, t.utc_offset)
+    t = Time.strptime('0 UTC', '%s %z')
+    assert_equal(0, t.to_r)
+    assert_equal(0, t.utc_offset)
+    assert_equal(true, t.utc?)
   end
 
   def test_strptime_Ymd_z
@@ -418,6 +422,15 @@ class TestTimeExtension < Test::Unit::Te https://github.com/ruby/ruby/blob/trunk/test/test_time.rb#L422
     assert_equal(0, t.min)
     assert_equal(0, t.sec)
     assert_equal(-7200, t.utc_offset)
+    t = Time.strptime('20010203 UTC', '%Y%m%d %z')
+    assert_equal(2001, t.year)
+    assert_equal(2, t.mon)
+    assert_equal(3, t.day)
+    assert_equal(0, t.hour)
+    assert_equal(0, t.min)
+    assert_equal(0, t.sec)
+    assert_equal(0, t.utc_offset)
+    assert_equal(true, t.utc?)
   end
 
   def test_nsec

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

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