Bug #11509
closedIncorrect fraction_digits calculation in lib/rss/rss.rb:41 Time#w3cdtf
Description
Current code is:
        fraction_digits = Math.log10(usec.to_s.sub(/0*$/, '').to_i).floor + 1
This makes time to lose as many digits, as there are zeros right after dot:
<       <dc:date>2014-03-04T07:37:30.04253+04:00</dc:date>
>       <dc:date>2014-03-04T07:37:30.0425+04:00</dc:date>
My solution that solves the issue is:
        fraction_digits = (usec + 1000000).to_s.length - 1
My Ruby is 2.0.0, but looks like noone touched RSS module for a year, so the bug is still here: https://bugs.ruby-lang.org/projects/ruby-trunk/repository/entry/lib/rss/rss.rb#L56
        
          
          Updated by Nakilon (Victor Maslov) about 10 years ago
          
          
        
        
      
      Sorry for broken markdown -- here I fixed it:
Current code is:
  def w3cdtf
    if usec.zero?
      fraction_digits = 0
    else
      fraction_digits = Math.log10(usec.to_s.sub(/0*$/, '').to_i).floor + 1
    end
  end
This makes time to lose as many digits, as there are zeros right after dot:
<       <dc:date>2014-03-04T07:37:30.04253+04:00</dc:date>
>       <dc:date>2014-03-04T07:37:30.0425+04:00</dc:date>
My solution that solves the issue is:
  def w3cdtf
    fraction_digits = (usec + 1000000).to_s.sub(/0*$/, '').length - 1
    xmlschema(fraction_digits)
  end
My Ruby is 2.0.0, but looks like noone touched RSS module for a year, so the bug is still here: https://bugs.ruby-lang.org/projects/ruby-trunk/repository/entry/lib/rss/rss.rb#L56
        
          
          Updated by nobu (Nobuyoshi Nakada) about 10 years ago
          
          
        
        
      
      - Status changed from Open to Closed
 
Applied in changeset r51766.
rss.rb: fix usec width
- lib/rss/rss.rb (Time#w3cdtf): fix zero-trimmed width of fraction
digits. [ruby-core:70667] [Bug #11509] 
        
          
          Updated by nobu (Nobuyoshi Nakada) about 10 years ago
          
          
        
        
      
      - Description updated (diff)
 
        
          
          Updated by nobu (Nobuyoshi Nakada) about 10 years ago
          
          
        
        
      
      - Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN to 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED
 
        
          
          Updated by usa (Usaku NAKAMURA) about 10 years ago
          
          
        
        
      
      - Backport changed from 2.0.0: REQUIRED, 2.1: REQUIRED, 2.2: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE, 2.2: REQUIRED
 
ruby_2_1 r51977 merged revision(s) 51766,51767.
        
          
          Updated by nagachika (Tomoyuki Chikanaga) about 10 years ago
          
          
        
        
      
      - Backport changed from 2.0.0: REQUIRED, 2.1: DONE, 2.2: REQUIRED to 2.0.0: REQUIRED, 2.1: DONE, 2.2: DONE
 
Backported into ruby_2_2 branch at r51987.