Flowdock
_parse(str, comp=false) public

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 1054
  def self._parse(str, comp=false)
    str = str.dup

    e = Format::Bag.new

    e._comp = comp

    str.gsub!(/[^-+',.\/:@[:alnum:]\[\]\x80-\xff]+/n, ' ')

    _parse_time(str, e) # || _parse_beat(str, e)
    _parse_day(str, e)

    _parse_eu(str, e)     ||
    _parse_us(str, e)     ||
    _parse_iso(str, e)    ||
    _parse_jis(str, e)    ||
    _parse_vms(str, e)    ||
    _parse_sla(str, e)    ||
    _parse_dot(str, e)    ||
    _parse_iso2(str, e)   ||
    _parse_year(str, e)   ||
    _parse_mon(str, e)    ||
    _parse_mday(str, e)   ||
    _parse_ddd(str, e)

    if str.sub!(/\b(bc\b|bce\b|b\.c\.|b\.c\.e\.)/in, ' ')
      if e.year
        e.year = -e.year + 1
      end
    end

    if str.sub!(/\A\s*(\d{1,2})\s*\z/n, ' ')
      if e.hour && !e.mday
        v = $1.to_i
        if (1..31) === v
          e.mday = v
        end
      end
      if e.mday && !e.hour
        v = $1.to_i
        if (0..24) === v
          e.hour = v
        end
      end
    end

    if e._comp
      if e.cwyear
        if e.cwyear >= 0 && e.cwyear <= 99
          e.cwyear += if e.cwyear >= 69
                      then 1900 else 2000 end
        end
      end
      if e.year
        if e.year >= 0 && e.year <= 99
          e.year += if e.year >= 69
                    then 1900 else 2000 end
        end
      end
    end

    e.offset ||= zone_to_diff(e.zone) if e.zone

    e.to_hash
  end
Register or log in to add new notes.