1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28558 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
tenderlove 2010-07-06 16:06:20 +00:00
parent 5bf4c6a635
commit 3b87ff32de
3 changed files with 16 additions and 9 deletions

View file

@ -91,7 +91,14 @@ module Psych
return Time.at(time.to_i, us) unless md[3] return Time.at(time.to_i, us) unless md[3]
tz = md[3].split(':').map { |digit| Integer(digit, 10) } 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) Time.at((time - offset).to_i, us)
end end
end end

View file

@ -269,12 +269,12 @@ module Psych
private private
def format_time time 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? if time.utc?
formatted += ".%09dZ" % [time.nsec] formatted += "Z"
else else
formatted += ".%09d %+.2d:%.2d" % [time.nsec, zone = time.strftime('%z')
time.gmt_offset / 3600, time.gmt_offset % 3600 / 60] formatted += " #{zone[0,3]}:#{zone[3,5]}"
end end
formatted formatted
end end

View file

@ -112,10 +112,10 @@ description:
def test_time def test_time
now = Time.now now = Time.now
formatted = now.strftime("%Y-%m-%d %H:%M:%S") + zone = now.strftime('%z')
".%09d %+.2d:%2d" % [ now.nsec, zone = " #{zone[0,3]}:#{zone[3,5]}"
now.gmt_offset / 3600,
now.gmt_offset % 3600 / 60] formatted = now.strftime("%Y-%m-%d %H:%M:%S.%9N") + zone
assert_equal now, Nodes::Scalar.new(formatted).to_ruby assert_equal now, Nodes::Scalar.new(formatted).to_ruby
end end