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 393
  def self._strptime_i(str, fmt, e) # :nodoc:
    fmt.scan(/%([EO]?(?::{1,3}z|.))|(.)/) do |s, c|
      a = $&
      if s
        case s
        when 'A', 'a'
          return unless str.sub!(/\A(#{Format::DAYS.keys.join('|')})/o, '') ||
                        str.sub!(/\A(#{Format::ABBR_DAYS.keys.join('|')})/o, '')
          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('|')})/o, '') ||
                        str.sub!(/\A(#{Format::ABBR_MONTHS.keys.join('|')})/o, '')
          val = Format::MONTHS[$1.downcase] || Format::ABBR_MONTHS[$1.downcase]
          return unless val
          e.mon = val
        when 'C', 'EC'
          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', 'Ec'
          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', 'Od', 'Oe'
          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', 'OH'
          return unless str.sub!(/\A( \d|\d{1,2})/, '')
          val = $1.to_i
          return unless (0..24) === val
          e.hour = val
        when 'I', 'l', 'OI'
          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 = Rational($1.to_i, 10**3)
          val = Rational($1.to_i, 10**$1.size)
          e.sec_fraction = val
        when 'M', 'OM'
          return unless str.sub!(/\A(\d{1,2})/, '')
          val = $1.to_i
          return unless (0..59) === val
          e.min = val
        when 'm', 'Om'
          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 = Rational($1.to_i, 10**9)
          val = Rational($1.to_i, 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\.)/, '')
          e._merid = if $1.downcase == 'a' then 0 else 12 end
        when 'Q'
          return unless str.sub!(/\A(-?\d{1,})/, '')
          val = Rational($1.to_i, 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', 'OS'
          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', 'OU', 'OW'
          return unless str.sub!(/\A(\d{1,2})/, '')
          val = $1.to_i
          return unless (0..53) === val
          e.__send__(if s[-1,1] == 'U' then :wnum0= else :wnum1= end, val)
        when 'u', 'Ou'
          return unless str.sub!(/\A(\d{1})/, '')
          val = $1.to_i
          return unless (1..7) === val
          e.cwday = val
        when 'V', 'OV'
          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', 'EX'
          return unless _strptime_i(str, '%H:%M:%S', e)
        when 'x', 'Ex'
          return unless _strptime_i(str, '%m/%d/%y', e)
        when 'Y', 'EY'
          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', 'Ey', 'Oy'
          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+)?)?
                                    |[[:alpha:].\s]+(?:standard|daylight)\s+time\b
                                    |[[:alpha:]]+(?:\s+dst)?\b
                                    )/x, '')
          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)
        else
          return unless str.sub!(Regexp.new('\A' + Regexp.quote(a)), '')
        end
      else
        case c
        when /\A[\s\v]/
          str.sub!(/\A[\s\v]+/, '')
        else
          return unless str.sub!(Regexp.new('\A' + Regexp.quote(a)), '')
        end
      end
    end
  end
Register or log in to add new notes.