ruby-changes:16566
From: tenderlove <ko1@a...>
Date: Wed, 7 Jul 2010 01:06:29 +0900 (JST)
Subject: [ruby-changes:16566] Ruby:r28558 (trunk): * ext/psych/lib/psych/scalar_scanner.rb (parse_time): dealing with
tenderlove 2010-07-07 01:06:20 +0900 (Wed, 07 Jul 2010) New Revision: 28558 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28558 Log: * ext/psych/lib/psych/scalar_scanner.rb (parse_time): dealing with negative partial hour time zones. [ruby-core:31064] * ext/psych/lib/psych/visitors/yaml_tree.rb: ditto * test/psych/visitors/test_to_ruby.rb: ditto Modified files: trunk/ext/psych/lib/psych/scalar_scanner.rb trunk/ext/psych/lib/psych/visitors/yaml_tree.rb trunk/test/psych/visitors/test_to_ruby.rb Index: ext/psych/lib/psych/scalar_scanner.rb =================================================================== --- ext/psych/lib/psych/scalar_scanner.rb (revision 28557) +++ ext/psych/lib/psych/scalar_scanner.rb (revision 28558) @@ -91,7 +91,14 @@ return Time.at(time.to_i, us) unless md[3] tz = md[3].split(':').map { |digit| Integer(digit, 10) } - offset = tz.first * 3600 + ((tz[1] || 0) * 60) + offset = tz.first * 3600 + + if offset < 0 + offset -= ((tz[1] || 0) * 60) + else + offset += ((tz[1] || 0) * 60) + end + Time.at((time - offset).to_i, us) end end Index: ext/psych/lib/psych/visitors/yaml_tree.rb =================================================================== --- ext/psych/lib/psych/visitors/yaml_tree.rb (revision 28557) +++ ext/psych/lib/psych/visitors/yaml_tree.rb (revision 28558) @@ -269,12 +269,12 @@ private def format_time time - formatted = time.strftime("%Y-%m-%d %H:%M:%S") + formatted = time.strftime("%Y-%m-%d %H:%M:%S.%9N") if time.utc? - formatted += ".%09dZ" % [time.nsec] + formatted += "Z" else - formatted += ".%09d %+.2d:%.2d" % [time.nsec, - time.gmt_offset / 3600, time.gmt_offset % 3600 / 60] + zone = time.strftime('%z') + formatted += " #{zone[0,3]}:#{zone[3,5]}" end formatted end Index: test/psych/visitors/test_to_ruby.rb =================================================================== --- test/psych/visitors/test_to_ruby.rb (revision 28557) +++ test/psych/visitors/test_to_ruby.rb (revision 28558) @@ -112,11 +112,11 @@ def test_time now = Time.now - formatted = now.strftime("%Y-%m-%d %H:%M:%S") + - ".%09d %+.2d:%2d" % [ now.nsec, - now.gmt_offset / 3600, - now.gmt_offset % 3600 / 60] + zone = now.strftime('%z') + zone = " #{zone[0,3]}:#{zone[3,5]}" + formatted = now.strftime("%Y-%m-%d %H:%M:%S.%9N") + zone + assert_equal now, Nodes::Scalar.new(formatted).to_ruby end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/