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

ruby-changes:16607

From: yugui <ko1@a...>
Date: Sat, 10 Jul 2010 13:06:01 +0900 (JST)
Subject: [ruby-changes:16607] Ruby:r28601 (ruby_1_9_2): merges r28541 from trunk into ruby_1_9_2.

yugui	2010-07-10 13:05:47 +0900 (Sat, 10 Jul 2010)

  New Revision: 28601

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

  Log:
    merges r28541 from trunk into ruby_1_9_2.
    --
    * ext/psych/lib/psych/scalar_scanner.rb (parse_string): support
      timezones that are not one hour off. [ruby-core:31023]
    * ext/psych/lib/psych/visitors/yaml_tree.rb: ditto
    --
    * test/psych/test_date_time.rb (TestDateTime#test_round_trip_with_offset):
      test for [ruby-core:31023].

  Modified files:
    branches/ruby_1_9_2/ChangeLog
    branches/ruby_1_9_2/ext/psych/lib/psych/scalar_scanner.rb
    branches/ruby_1_9_2/ext/psych/lib/psych/visitors/yaml_tree.rb
    branches/ruby_1_9_2/test/psych/test_date_time.rb

Index: ruby_1_9_2/ChangeLog
===================================================================
--- ruby_1_9_2/ChangeLog	(revision 28600)
+++ ruby_1_9_2/ChangeLog	(revision 28601)
@@ -1,3 +1,15 @@
+Sat Jul 10 11:41:54 2010  Yuki Sonoda (Yugui)  <yugui@y...>
+
+	* test/psych/test_date_time.rb (TestDateTime#test_round_trip_with_offset):
+	  test for [ruby-core:31023].
+
+Mon Jul  5 12:32:01 2010  Aaron Patterson <aaron@t...>
+
+	* ext/psych/lib/psych/scalar_scanner.rb (parse_string): support
+	  timezones that are not one hour off. [ruby-core:31023]
+
+	* ext/psych/lib/psych/visitors/yaml_tree.rb: ditto
+
 Sat Jul  3 09:47:26 2010  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych/visitors/to_ruby.rb(visit_Psych_Nodes_Scalar):
Index: ruby_1_9_2/ext/psych/lib/psych/scalar_scanner.rb
===================================================================
--- ruby_1_9_2/ext/psych/lib/psych/scalar_scanner.rb	(revision 28600)
+++ ruby_1_9_2/ext/psych/lib/psych/scalar_scanner.rb	(revision 28601)
@@ -88,9 +88,11 @@
       time = Time.utc(yy, m, dd, hh, mm, ss, us)
 
       return time if 'Z' == md[3]
+      return Time.at(time.to_i, us) unless md[3]
 
-      tz = md[3] ? Integer(md[3].split(':').first.sub(/([-+])0/, '\1')) : 0
-      Time.at((time - (tz * 3600)).to_i, us)
+      tz = md[3].split(':').map { |digit| Integer(digit.sub(/([-+])0/, '\1')) }
+      offset = tz.first * 3600 + ((tz[1] || 0) * 60)
+      Time.at((time - offset).to_i, us)
     end
   end
 end
Index: ruby_1_9_2/ext/psych/lib/psych/visitors/yaml_tree.rb
===================================================================
--- ruby_1_9_2/ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 28600)
+++ ruby_1_9_2/ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 28601)
@@ -124,26 +124,13 @@
       end
 
       def visit_DateTime o
-        o = o.to_time
-        formatted = o.strftime("%Y-%m-%d %H:%M:%S")
-        if o.utc?
-          formatted += ".%06dZ" % [o.nsec]
-        else
-          formatted += ".%06d %+.2d:00" % [o.nsec, o.gmt_offset / 3600]
-        end
-
+        formatted = format_time o.to_time
         tag = '!ruby/object:DateTime'
         @emitter.scalar formatted, nil, tag, false, false, Nodes::Scalar::ANY
       end
 
       def visit_Time o
-        formatted = o.strftime("%Y-%m-%d %H:%M:%S")
-        if o.utc?
-          formatted += ".%06dZ" % [o.nsec]
-        else
-          formatted += ".%06d %+.2d:00" % [o.nsec, o.gmt_offset / 3600]
-        end
-
+        formatted = format_time o
         @emitter.scalar formatted, nil, nil, true, false, Nodes::Scalar::ANY
       end
 
@@ -269,6 +256,17 @@
       end
 
       private
+      def format_time time
+        formatted = time.strftime("%Y-%m-%d %H:%M:%S")
+        if time.utc?
+          formatted += ".%06dZ" % [time.nsec]
+        else
+          formatted += ".%06d %+.2d:%.2d" % [time.nsec,
+            time.gmt_offset / 3600, time.gmt_offset % 3600 / 60]
+        end
+        formatted
+      end
+
       # FIXME: remove this method once "to_yaml_properties" is removed
       def find_ivars target
         loc = target.method(:to_yaml_properties).source_location.first
Index: ruby_1_9_2/test/psych/test_date_time.rb
===================================================================
--- ruby_1_9_2/test/psych/test_date_time.rb	(revision 28600)
+++ ruby_1_9_2/test/psych/test_date_time.rb	(revision 28601)
@@ -13,5 +13,11 @@
       dt = DateTime.now
       assert_cycle dt
     end
+
+    def test_round_trip_with_offset
+      dt = DateTime.now
+      dt = dt.new_offset(Rational(3671, 60 * 60 * 24))
+      assert_cycle dt
+    end
   end
 end

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

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