mirror of
https://github.com/ruby/ruby.git
synced 2025-09-17 01:23:57 +02:00
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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_9_2@28602 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
12ce578196
commit
c13b3808b9
3 changed files with 19 additions and 10 deletions
|
@ -90,8 +90,15 @@ module Psych
|
||||||
return time if 'Z' == md[3]
|
return time if 'Z' == md[3]
|
||||||
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.sub(/([-+])0/, '\1')) }
|
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
|
||||||
|
|
|
@ -257,12 +257,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 += ".%06dZ" % [time.nsec]
|
formatted += "Z"
|
||||||
else
|
else
|
||||||
formatted += ".%06d %+.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
|
||||||
|
|
|
@ -112,8 +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')
|
||||||
".%06d %+.2d:00" % [now.nsec, now.gmt_offset / 3600]
|
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
|
assert_equal now, Nodes::Scalar.new(formatted).to_ruby
|
||||||
end
|
end
|
||||||
|
@ -121,7 +123,7 @@ description:
|
||||||
def test_time_utc
|
def test_time_utc
|
||||||
now = Time.now.utc
|
now = Time.now.utc
|
||||||
formatted = now.strftime("%Y-%m-%d %H:%M:%S") +
|
formatted = now.strftime("%Y-%m-%d %H:%M:%S") +
|
||||||
".%06dZ" % [now.nsec]
|
".%09dZ" % [now.nsec]
|
||||||
|
|
||||||
assert_equal now, Nodes::Scalar.new(formatted).to_ruby
|
assert_equal now, Nodes::Scalar.new(formatted).to_ruby
|
||||||
end
|
end
|
||||||
|
@ -129,7 +131,7 @@ description:
|
||||||
def test_time_utc_no_z
|
def test_time_utc_no_z
|
||||||
now = Time.now.utc
|
now = Time.now.utc
|
||||||
formatted = now.strftime("%Y-%m-%d %H:%M:%S") +
|
formatted = now.strftime("%Y-%m-%d %H:%M:%S") +
|
||||||
".%06d" % [now.nsec]
|
".%09d" % [now.nsec]
|
||||||
|
|
||||||
assert_equal now, Nodes::Scalar.new(formatted).to_ruby
|
assert_equal now, Nodes::Scalar.new(formatted).to_ruby
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue