summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-06 16:06:20 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-06 16:06:20 +0000
commit3b87ff32de3d97780e7b077aabebc5b56a8283ab (patch)
tree2c9e728e9ef15b1d10f588a2a56021c0be5d40bb
parent5bf4c6a635d30ba2e209fa9a2f824e06a6fa479b (diff)
* 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
-rw-r--r--ext/psych/lib/psych/scalar_scanner.rb9
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb8
-rw-r--r--test/psych/visitors/test_to_ruby.rb8
3 files changed, 16 insertions, 9 deletions
diff --git a/ext/psych/lib/psych/scalar_scanner.rb b/ext/psych/lib/psych/scalar_scanner.rb
index dc6f9944fa..e1e59d37e3 100644
--- a/ext/psych/lib/psych/scalar_scanner.rb
+++ b/ext/psych/lib/psych/scalar_scanner.rb
@@ -91,7 +91,14 @@ module Psych
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
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index 4df7b4d5db..5f757e9e1b 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -269,12 +269,12 @@ module Psych
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
diff --git a/test/psych/visitors/test_to_ruby.rb b/test/psych/visitors/test_to_ruby.rb
index 077b8796a5..b5b8e1443d 100644
--- a/test/psych/visitors/test_to_ruby.rb
+++ b/test/psych/visitors/test_to_ruby.rb
@@ -112,10 +112,10 @@ description:
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