Flowdock
method

_strptime_i

Importance_0
_strptime_i(str, fmt, 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 384
  def self._strptime_i(str, fmt, e) # :nodoc:
    fmt.scan(/%[EO]?(:{1,3}z|.)|(.)/m) do |s, c|
      if s
        case s
        when 'A', 'a'
          return unless str.sub!(/\A(#{Format::DAYS.keys.join('|')})/io, '') ||
                        str.sub!(/\A(#{Format::ABBR_DAYS.keys.join('|')})/io, '')
          val = Format::DAYS[$1.downcase] || Format::ABBR_DAYS[$1.downcase]
          return unless val
          e.wday = val
        when 'B', 'b', 'h'
          return unless str.sub!(/\A(#{Format::MONTHS.keys.join('|')})/io, '') ||
                        str.sub!(/\A(#{Format::ABBR_MONTHS.keys.join('|')})/io, '')
          val = Format::MONTHS[$1.downcase] || Format::ABBR_MONTHS[$1.downcase]
          return unless val
          e.mon = val
        when 'C'
          return unless str.sub!(if num_pattern?($')
                                 then /\A([-+]?\d{1,2})/
                                 else /\A([-+]?\d{1,})/
                                 end, '')
          val = $1.to_i
          e._cent = val
        when 'c'
          return unless _strptime_i(str, '%a %b %e %H:%M:%S %Y', e)
        when 'D'
          return unless _strptime_i(str, '%m/%d/%y', e)
        when 'd', 'e'
          return unless str.sub!(/\A( \d|\d{1,2})/, '')
          val = $1.to_i
          return unless (1..31) === val
          e.mday = val
        when 'F'
          return unless _strptime_i(str, '%Y-%m-%d', e)
        when 'G'
          return unless str.sub!(if num_pattern?($')
                                 then /\A([-+]?\d{1,4})/
                                 else /\A([-+]?\d{1,})/
                                 end, '')
          val = $1.to_i
          e.cwyear = val
        when 'g'
          return unless str.sub!(/\A(\d{1,2})/, '')
          val = $1.to_i
          return unless (0..99) === val
          e.cwyear = val
          e._cent ||= if val >= 69 then 19 else 20 end
        when 'H', 'k'
          return unless str.sub!(/\A( \d|\d{1,2})/, '')
          val = $1.to_i
          return unless (0..24) === val
          e.hour = val
        when 'I', 'l'
          return unless str.sub!(/\A( \d|\d{1,2})/, '')
          val = $1.to_i
          return unless (1..12) === val
          e.hour = val
        when 'j'
          return unless str.sub!(/\A(\d{1,3})/, '')
          val = $1.to_i
          return unless (1..366) === val
          e.yday = val
        when 'L'
          return unless str.sub!(if num_pattern?($')
                                 then /\A([-+]?\d{1,3})/
                                 else /\A([-+]?\d{1,})/
                                 end, '')
#         val = $1.to_i.to_r / (10**3)
          val = $1.to_i.to_r / (10**$1.size)
          e.sec_fraction = val
        when 'M'
          return unless str.sub!(/\A(\d{1,2})/, '')
          val = $1.to_i
          return unless (0..59) === val
          e.min = val
        when 'm'
          return unless str.sub!(/\A(\d{1,2})/, '')
          val = $1.to_i
          return unless (1..12) === val
          e.mon = val
        when 'N'
          return unless str.sub!(if num_pattern?($')
                                 then /\A([-+]?\d{1,9})/
                                 else /\A([-+]?\d{1,})/
                                 end, '')
#         val = $1.to_i.to_r / (10**9)
          val = $1.to_i.to_r / (10**$1.size)
          e.sec_fraction = val
        when 'n', 't'
          return unless _strptime_i(str, "\s", e)
        when 'P', 'p'
          return unless str.sub!(/\A([ap])(?:m\b|\.m\.)/i, '')
          e._merid = if $1.downcase == 'a' then 0 else 12 end
        when 'Q'
          return unless str.sub!(/\A(-?\d{1,})/, '')
          val = $1.to_i.to_r / 10**3
          e.seconds = val
        when 'R'
          return unless _strptime_i(str, '%H:%M', e)
        when 'r'
          return unless _strptime_i(str, '%I:%M:%S %p', e)
        when 'S'
          return unless str.sub!(/\A(\d{1,2})/, '')
          val = $1.to_i
          return unless (0..60) === val
          e.sec = val
        when 's'
          return unless str.sub!(/\A(-?\d{1,})/, '')
          val = $1.to_i
          e.seconds = val
        when 'T'
          return unless _strptime_i(str, '%H:%M:%S', e)
        when 'U', 'W'
          return unless str.sub!(/\A(\d{1,2})/, '')
          val = $1.to_i
          return unless (0..53) === val
          e.__send__(if s == 'U' then :wnum0= else :wnum1= end, val)
        when 'u'
          return unless str.sub!(/\A(\d{1})/, '')
          val = $1.to_i
          return unless (1..7) === val
          e.cwday = val
        when 'V'
          return unless str.sub!(/\A(\d{1,2})/, '')
          val = $1.to_i
          return unless (1..53) === val
          e.cweek = val
        when 'v'
          return unless _strptime_i(str, '%e-%b-%Y', e)
        when 'w'
          return unless str.sub!(/\A(\d{1})/, '')
          val = $1.to_i
          return unless (0..6) === val
          e.wday = val
        when 'X'
          return unless _strptime_i(str, '%H:%M:%S', e)
        when 'x'
          return unless _strptime_i(str, '%m/%d/%y', e)
        when 'Y'
          return unless str.sub!(if num_pattern?($')
                                 then /\A([-+]?\d{1,4})/
                                 else /\A([-+]?\d{1,})/
                                 end, '')
          val = $1.to_i
          e.year = val
        when 'y'
          return unless str.sub!(/\A(\d{1,2})/, '')
          val = $1.to_i
          return unless (0..99) === val
          e.year = val
          e._cent ||= if val >= 69 then 19 else 20 end
        when 'Z', /\A:{0,3}z/
          return unless str.sub!(/\A((?:gmt|utc?)?[-+]\d+(?:[,.:]\d+(?::\d+)?)?
                                    |[a-z.\s]+(?:standard|daylight)\s+time\b
                                    |[a-z]+(?:\s+dst)?\b
                                    )/ix, '')
          val = $1
          e.zone = val
          offset = zone_to_diff(val)
          e.offset = offset
        when '%'
          return unless str.sub!(/\A%/, '')
        when '+'
          return unless _strptime_i(str, '%a %b %e %H:%M:%S %Z %Y', e)
        when '1'
          if $VERBOSE
            warn("warning: strptime: %1 is deprecated; forget this")
          end
          return unless str.sub!(/\A(\d+)/, '')
          val = $1.to_i
          e.jd = val
        when '2'
          if $VERBOSE
            warn("warning: strptime: %2 is deprecated; use '%Y-%j'")
          end
          return unless _strptime_i(str, '%Y-%j', e)
        when '3'
          if $VERBOSE
            warn("warning: strptime: %3 is deprecated; use '%F'")
          end
          return unless _strptime_i(str, '%F', e)
        else
          return unless str.sub!(Regexp.new('\\A' + Regexp.quote(s)), '')
        end
      else
        case c
        when /\A[\s\v]/
          str.sub!(/\A[\s\v]+/, '')
        else
          return unless str.sub!(Regexp.new('\\A' + Regexp.quote(c)), '')
        end
      end
    end
  end
Register or log in to add new notes.