ruby-changes:16608
From: yugui <ko1@a...>
Date: Sat, 10 Jul 2010 13:06:02 +0900 (JST)
Subject: [ruby-changes:16608] Ruby:r28602 (ruby_1_9_2): merges r28550,r28551,r28554 and r28558 from trunk into ruby_1_9_2.
yugui 2010-07-10 13:05:52 +0900 (Sat, 10 Jul 2010) New Revision: 28602 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28602 Log: merges r28550,r28551,r28554 and r28558 from trunk into ruby_1_9_2. -- * ext/psych/lib/psych/scalar_scanner.rb: making the code more beautiful. Thanks nobu! -- * ext/psych/lib/psych/visitors/yaml_tree.rb (format_time): nanoseconds require more digits when dumping. Thanks akr! [ruby-core:31047] * test/psych/visitors/test_to_ruby.rb: adjusting tests for nanoseconds -- * test/psych/visitors/test_to_ruby.rb (test_time): time test must respect non-whole timezone. Thanks akr! [ruby-core:31061] -- * 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: 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/visitors/test_to_ruby.rb Index: ruby_1_9_2/ext/psych/lib/psych/scalar_scanner.rb =================================================================== --- ruby_1_9_2/ext/psych/lib/psych/scalar_scanner.rb (revision 28601) +++ ruby_1_9_2/ext/psych/lib/psych/scalar_scanner.rb (revision 28602) @@ -90,8 +90,15 @@ return time if 'Z' == md[3] return Time.at(time.to_i, us) unless md[3] - tz = md[3].split(':').map { |digit| Integer(digit.sub(/([-+])0/, '\1')) } - offset = tz.first * 3600 + ((tz[1] || 0) * 60) + tz = md[3].split(':').map { |digit| Integer(digit, 10) } + 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: 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 28601) +++ ruby_1_9_2/ext/psych/lib/psych/visitors/yaml_tree.rb (revision 28602) @@ -257,12 +257,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 += ".%06dZ" % [time.nsec] + formatted += "Z" else - formatted += ".%06d %+.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: ruby_1_9_2/test/psych/visitors/test_to_ruby.rb =================================================================== --- ruby_1_9_2/test/psych/visitors/test_to_ruby.rb (revision 28601) +++ ruby_1_9_2/test/psych/visitors/test_to_ruby.rb (revision 28602) @@ -112,16 +112,18 @@ def test_time now = Time.now - formatted = now.strftime("%Y-%m-%d %H:%M:%S") + - ".%06d %+.2d:00" % [now.nsec, now.gmt_offset / 3600] + 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 def test_time_utc now = Time.now.utc formatted = now.strftime("%Y-%m-%d %H:%M:%S") + - ".%06dZ" % [now.nsec] + ".%09dZ" % [now.nsec] assert_equal now, Nodes::Scalar.new(formatted).to_ruby end @@ -129,7 +131,7 @@ def test_time_utc_no_z now = Time.now.utc formatted = now.strftime("%Y-%m-%d %H:%M:%S") + - ".%06d" % [now.nsec] + ".%09d" % [now.nsec] assert_equal now, Nodes::Scalar.new(formatted).to_ruby end -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/