summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-03 00:15:51 +0000
committertenderlove <tenderlove@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-07-03 00:15:51 +0000
commit6fe92a3cd6b4116580ff7663180407bc0c38030f (patch)
tree71416058bc05485b9a2ca9abd49932ad3c0528d2
parentfcb613ae477e7bf1aeb8d7c6a15ddf2585d514e7 (diff)
* ext/psych/lib/psych/visitors/yaml_tree.rb (visit_Time): use
Time#nsec to accurately serialize time objects. [ruby-core:29233] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@28531 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/psych/lib/psych/visitors/yaml_tree.rb4
-rw-r--r--test/psych/visitors/test_to_ruby.rb12
-rw-r--r--test/psych/visitors/test_yaml_tree.rb2
4 files changed, 14 insertions, 9 deletions
diff --git a/ChangeLog b/ChangeLog
index 013433f9e76..0b65b8cec5a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Jul 3 09:13:55 2010 Aaron Patterson <aaron@tenderlovemaking.com>
+
+ * ext/psych/lib/psych/visitors/yaml_tree.rb (visit_Time): use
+ Time#nsec to accurately serialize time objects. [ruby-core:29233]
+
Fri Jul 2 23:30:23 2010 NAKAMURA Usaku <usa@ruby-lang.org>
* io.c (argf_inplace_mode_set): prohibits an assignment of a tainted
diff --git a/ext/psych/lib/psych/visitors/yaml_tree.rb b/ext/psych/lib/psych/visitors/yaml_tree.rb
index 93ccc5832b1..4282e0bb0a3 100644
--- a/ext/psych/lib/psych/visitors/yaml_tree.rb
+++ b/ext/psych/lib/psych/visitors/yaml_tree.rb
@@ -138,9 +138,9 @@ module Psych
def visit_Time o
formatted = o.strftime("%Y-%m-%d %H:%M:%S")
if o.utc?
- formatted += ".%06dZ" % [o.usec]
+ formatted += ".%06dZ" % [o.nsec]
else
- formatted += ".%06d %+.2d:00" % [o.usec, o.gmt_offset / 3600]
+ formatted += ".%06d %+.2d:00" % [o.nsec, o.gmt_offset / 3600]
end
@emitter.scalar formatted, nil, nil, true, false, Nodes::Scalar::ANY
diff --git a/test/psych/visitors/test_to_ruby.rb b/test/psych/visitors/test_to_ruby.rb
index 8ad41dbe7d5..eb2841d9d0f 100644
--- a/test/psych/visitors/test_to_ruby.rb
+++ b/test/psych/visitors/test_to_ruby.rb
@@ -113,25 +113,25 @@ description:
def test_time
now = Time.now
formatted = now.strftime("%Y-%m-%d %H:%M:%S") +
- ".%06d %+.2d:00" % [now.usec, now.gmt_offset / 3600]
+ ".%06d %+.2d:00" % [now.nsec, now.gmt_offset / 3600]
- assert_in_delta now, Nodes::Scalar.new(formatted).to_ruby, 0.000001
+ assert_equal now, Nodes::Scalar.new(formatted).to_ruby
end
def test_time_utc
now = Time.now.utc
formatted = now.strftime("%Y-%m-%d %H:%M:%S") +
- ".%06dZ" % [now.usec]
+ ".%06dZ" % [now.nsec]
- assert_in_delta now, Nodes::Scalar.new(formatted).to_ruby, 0.000001
+ assert_equal now, Nodes::Scalar.new(formatted).to_ruby
end
def test_time_utc_no_z
now = Time.now.utc
formatted = now.strftime("%Y-%m-%d %H:%M:%S") +
- ".%06d" % [now.usec]
+ ".%06d" % [now.nsec]
- assert_in_delta now, Nodes::Scalar.new(formatted).to_ruby, 0.000001
+ assert_equal now, Nodes::Scalar.new(formatted).to_ruby
end
def test_date
diff --git a/test/psych/visitors/test_yaml_tree.rb b/test/psych/visitors/test_yaml_tree.rb
index 758cfaed726..ed89e786006 100644
--- a/test/psych/visitors/test_yaml_tree.rb
+++ b/test/psych/visitors/test_yaml_tree.rb
@@ -54,7 +54,7 @@ module Psych
def test_time
t = Time.now
- assert_in_delta t, Psych.load(Psych.dump(t)), 0.000001
+ assert_equal t, Psych.load(Psych.dump(t))
end
def test_date