Flowdock
method

_parse_ddd

Importance_0
_parse_ddd(str, e) private

No documentation

This method has no description. You can help the Ruby community by adding new notes.

Hide source
# File lib/date/format.rb, line 916
  def self._parse_ddd(str, e) # :nodoc:
    if str.sub!(
                /([-+]?)(\d{2,14})
                  (?:
                    \s*
                    t?
                    \s*
                    (\d{2,6})?(?:[,.](\d*))?
                  )?
                  (?:
                    \s*
                    (
                      z\b
                    |
                      [-+]\d{1,4}\b
                    |
                      \[[-+]?\d[^\]]*\]
                    )
                  )?
                /inx,
                ' ')
      case $2.size
      when 2
        if $3.nil? && $4
          e.sec  = $2[-2, 2].to_i
        else
          e.mday = $2[ 0, 2].to_i
        end
      when 4
        if $3.nil? && $4
          e.sec  = $2[-2, 2].to_i
          e.min  = $2[-4, 2].to_i
        else
          e.mon  = $2[ 0, 2].to_i
          e.mday = $2[ 2, 2].to_i
        end
      when 6
        if $3.nil? && $4
          e.sec  = $2[-2, 2].to_i
          e.min  = $2[-4, 2].to_i
          e.hour = $2[-6, 2].to_i
        else
          e.year = ($1 + $2[ 0, 2]).to_i
          e.mon  = $2[ 2, 2].to_i
          e.mday = $2[ 4, 2].to_i
        end
      when 8, 10, 12, 14
        if $3.nil? && $4
          e.sec  = $2[-2, 2].to_i
          e.min  = $2[-4, 2].to_i
          e.hour = $2[-6, 2].to_i
          e.mday = $2[-8, 2].to_i
          if $2.size >= 10
            e.mon  = $2[-10, 2].to_i
          end
          if $2.size == 12
            e.year = ($1 + $2[-12, 2]).to_i
          end
          if $2.size == 14
            e.year = ($1 + $2[-14, 4]).to_i
            e._comp = false
          end
        else
          e.year = ($1 + $2[ 0, 4]).to_i
          e.mon  = $2[ 4, 2].to_i
          e.mday = $2[ 6, 2].to_i
          e.hour = $2[ 8, 2].to_i if $2.size >= 10
          e.min  = $2[10, 2].to_i if $2.size >= 12
          e.sec  = $2[12, 2].to_i if $2.size >= 14
          e._comp = false
        end
      when 3
        if $3.nil? && $4
          e.sec  = $2[-2, 2].to_i
          e.min  = $2[-3, 1].to_i
        else
          e.yday = $2[ 0, 3].to_i
        end
      when 5
        if $3.nil? && $4
          e.sec  = $2[-2, 2].to_i
          e.min  = $2[-4, 2].to_i
          e.hour = $2[-5, 1].to_i
        else
          e.year = ($1 + $2[ 0, 2]).to_i
          e.yday = $2[ 2, 3].to_i
        end
      when 7
        if $3.nil? && $4
          e.sec  = $2[-2, 2].to_i
          e.min  = $2[-4, 2].to_i
          e.hour = $2[-6, 2].to_i
          e.mday = $2[-7, 1].to_i
        else
          e.year = ($1 + $2[ 0, 4]).to_i
          e.yday = $2[ 4, 3].to_i
        end
      end
      if $3
        if $4
          case $3.size
          when 2, 4, 6
            e.sec  = $3[-2, 2].to_i
            e.min  = $3[-4, 2].to_i if $3.size >= 4
            e.hour = $3[-6, 2].to_i if $3.size >= 6
          end
        else
          case $3.size
          when 2, 4, 6
            e.hour = $3[ 0, 2].to_i
            e.min  = $3[ 2, 2].to_i if $3.size >= 4
            e.sec  = $3[ 4, 2].to_i if $3.size >= 6
          end
        end
      end
      if $4
        e.sec_fraction = Rational($4.to_i, 10**$4.size)
      end
      if $5
        e.zone = $5
        if e.zone[0,1] == '['
          o, n, = e.zone[1..-2].split(':')
          e.zone = n || o
          if /\A\d/ =~ o
            o = format('+%s', o)
          end
          e.offset = zone_to_diff(o)
        end
      end
      true
    end
  end
Register or log in to add new notes.