[前][次][番号順一覧][スレッド一覧]

ruby-changes:16539

From: tenderlove <ko1@a...>
Date: Sat, 3 Jul 2010 09:16:10 +0900 (JST)
Subject: [ruby-changes:16539] Ruby:r28531 (trunk): * ext/psych/lib/psych/visitors/yaml_tree.rb (visit_Time): use

tenderlove	2010-07-03 09:15:51 +0900 (Sat, 03 Jul 2010)

  New Revision: 28531

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=28531

  Log:
    * ext/psych/lib/psych/visitors/yaml_tree.rb (visit_Time): use
      Time#nsec to accurately serialize time objects. [ruby-core:29233]

  Modified files:
    trunk/ChangeLog
    trunk/ext/psych/lib/psych/visitors/yaml_tree.rb
    trunk/test/psych/visitors/test_to_ruby.rb
    trunk/test/psych/visitors/test_yaml_tree.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 28530)
+++ ChangeLog	(revision 28531)
@@ -1,3 +1,8 @@
+Sat Jul  3 09:13:55 2010  Aaron Patterson <aaron@t...>
+
+	* 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@r...>
 
 	* io.c (argf_inplace_mode_set): prohibits an assignment of a tainted
Index: ext/psych/lib/psych/visitors/yaml_tree.rb
===================================================================
--- ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 28530)
+++ ext/psych/lib/psych/visitors/yaml_tree.rb	(revision 28531)
@@ -138,9 +138,9 @@
       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
Index: test/psych/visitors/test_yaml_tree.rb
===================================================================
--- test/psych/visitors/test_yaml_tree.rb	(revision 28530)
+++ test/psych/visitors/test_yaml_tree.rb	(revision 28531)
@@ -54,7 +54,7 @@
 
       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
Index: test/psych/visitors/test_to_ruby.rb
===================================================================
--- test/psych/visitors/test_to_ruby.rb	(revision 28530)
+++ test/psych/visitors/test_to_ruby.rb	(revision 28531)
@@ -113,25 +113,25 @@
       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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]