* 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28541 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
9f56a870af
commit
ce2e7368d7
@ -1,3 +1,10 @@
|
|||||||
|
Mon Jul 5 12:32:01 2010 Aaron Patterson <aaron@tenderlovemaking.com>
|
||||||
|
|
||||||
|
* 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
|
||||||
|
|
||||||
Sun Jul 4 22:49:54 2010 Tanaka Akira <akr@fsij.org>
|
Sun Jul 4 22:49:54 2010 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* test/ruby/test_syntax.rb: split test_syntax from test_system.rb.
|
* test/ruby/test_syntax.rb: split test_syntax from test_system.rb.
|
||||||
|
@ -88,9 +88,11 @@ module Psych
|
|||||||
time = Time.utc(yy, m, dd, hh, mm, ss, us)
|
time = Time.utc(yy, m, dd, hh, mm, ss, us)
|
||||||
|
|
||||||
return time if 'Z' == md[3]
|
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
|
tz = md[3].split(':').map { |digit| Integer(digit.sub(/([-+])0/, '\1')) }
|
||||||
Time.at((time - (tz * 3600)).to_i, us)
|
offset = tz.first * 3600 + ((tz[1] || 0) * 60)
|
||||||
|
Time.at((time - offset).to_i, us)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -136,26 +136,13 @@ module Psych
|
|||||||
end
|
end
|
||||||
|
|
||||||
def visit_DateTime o
|
def visit_DateTime o
|
||||||
o = o.to_time
|
formatted = format_time 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
|
|
||||||
|
|
||||||
tag = '!ruby/object:DateTime'
|
tag = '!ruby/object:DateTime'
|
||||||
@emitter.scalar formatted, nil, tag, false, false, Nodes::Scalar::ANY
|
@emitter.scalar formatted, nil, tag, false, false, Nodes::Scalar::ANY
|
||||||
end
|
end
|
||||||
|
|
||||||
def visit_Time o
|
def visit_Time o
|
||||||
formatted = o.strftime("%Y-%m-%d %H:%M:%S")
|
formatted = format_time o
|
||||||
if o.utc?
|
|
||||||
formatted += ".%06dZ" % [o.nsec]
|
|
||||||
else
|
|
||||||
formatted += ".%06d %+.2d:00" % [o.nsec, o.gmt_offset / 3600]
|
|
||||||
end
|
|
||||||
|
|
||||||
@emitter.scalar formatted, nil, nil, true, false, Nodes::Scalar::ANY
|
@emitter.scalar formatted, nil, nil, true, false, Nodes::Scalar::ANY
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -281,6 +268,17 @@ module Psych
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
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
|
# FIXME: remove this method once "to_yaml_properties" is removed
|
||||||
def find_ivars target
|
def find_ivars target
|
||||||
loc = target.method(:to_yaml_properties).source_location.first
|
loc = target.method(:to_yaml_properties).source_location.first
|
||||||
|
Loading…
x
Reference in New Issue
Block a user