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

ruby-changes:39685

From: nobu <ko1@a...>
Date: Sat, 5 Sep 2015 11:40:02 +0900 (JST)
Subject: [ruby-changes:39685] nobu:r51766 (trunk): rss.rb: fix usec width

nobu	2015-09-05 11:39:55 +0900 (Sat, 05 Sep 2015)

  New Revision: 51766

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

  Log:
    rss.rb: fix usec width
    
    * lib/rss/rss.rb (Time#w3cdtf): fix zero-trimmed width of fraction
      digits.  [ruby-core:70667] [Bug #11509]

  Modified files:
    trunk/ChangeLog
    trunk/lib/rss/rss.rb
    trunk/test/rss/test_to_s.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51765)
+++ ChangeLog	(revision 51766)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Sep  5 11:39:52 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* lib/rss/rss.rb (Time#w3cdtf): fix zero-trimmed width of fraction
+	  digits.  [ruby-core:70667] [Bug #11509]
+
 Sat Sep  5 08:28:58 2015  Nobuyoshi Nakada  <nobu@r...>
 
 	* hash.c (rb_hash_equal, rb_hash_eql): [DOC] the orders of each
Index: lib/rss/rss.rb
===================================================================
--- lib/rss/rss.rb	(revision 51765)
+++ lib/rss/rss.rb	(revision 51766)
@@ -53,7 +53,7 @@ class Time https://github.com/ruby/ruby/blob/trunk/lib/rss/rss.rb#L53
       if usec.zero?
         fraction_digits = 0
       else
-        fraction_digits = Math.log10(usec.to_s.sub(/0*$/, '').to_i).floor + 1
+        fraction_digits = strftime('%6N').sub!(/0*\z/, '').size
       end
       xmlschema(fraction_digits)
     end
Index: test/rss/test_to_s.rb
===================================================================
--- test/rss/test_to_s.rb	(revision 51765)
+++ test/rss/test_to_s.rb	(revision 51766)
@@ -102,6 +102,12 @@ module RSS https://github.com/ruby/ruby/blob/trunk/test/rss/test_to_s.rb#L102
       assert_textinput20(@textinput_info, rss.textinput)
     end
 
+    def test_time_w3cdtf
+      assert_equal("2015-09-05T01:25:48.0001Z",
+                   Time.utc(2015, 9, 5, 1, 25, 48, 100).w3cdtf,
+                   '[ruby-core:70667] [Bug #11509]')
+    end
+
     private
     def setup_xml_declaration_info
       @version = "1.0"

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

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