summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2010-07-07 11:07:56 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2010-07-07 11:07:56 -0700
commita5a87e37c7ee522b36b1d43dc78a0f7a50d41efc (patch)
treef529fcb65a29daf896a7feda0b7c4aa28512a35b
parent2c2b6e72b18fc6666b218837016b0be9d29c48ce (diff)
downloadpsych-a5a87e37c7ee522b36b1d43dc78a0f7a50d41efc.zip
merging from ruby
-rw-r--r--lib/psych/scalar_scanner.rb9
-rw-r--r--lib/psych/visitors/yaml_tree.rb8
-rw-r--r--test/psych/visitors/test_to_ruby.rb6
3 files changed, 16 insertions, 7 deletions
diff --git a/lib/psych/scalar_scanner.rb b/lib/psych/scalar_scanner.rb
index dc6f994..e1e59d3 100644
--- a/lib/psych/scalar_scanner.rb
+++ b/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/lib/psych/visitors/yaml_tree.rb b/lib/psych/visitors/yaml_tree.rb
index 4df7b4d..5f757e9 100644
--- a/lib/psych/visitors/yaml_tree.rb
+++ b/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 1a4d319..b5b8e14 100644
--- a/test/psych/visitors/test_to_ruby.rb
+++ b/test/psych/visitors/test_to_ruby.rb
@@ -112,8 +112,10 @@ description:
def test_time
now = Time.now
- formatted = now.strftime("%Y-%m-%d %H:%M:%S") +
- ".%09d %+.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