Method: Date._parse
- Defined in:
- lib/date/format.rb
._parse(str, comp = true) ⇒ Object
call-seq:
_parse(str, comp=true) -> Hash
Attempt to parse the string by trying a wide variety of date formats sequentially (unless a match is found by the fast Ragel-based parser). The comp argument determines whether to convert 2-digit years to 4-digit years. If the str is not in a supported format, an empty hash will be returned.
This method searches for a match anywhere in the string, unlike most of the other ruby 1.9-only parsing methods which require that an exact match for the entire string.
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 |
# File 'lib/date/format.rb', line 662 def self._parse(str, comp=true) if v = _ragel_parse(str) return v end str = str.dup e = {:_ => {:comp => comp}} str.gsub!(/[^-+',.\/:@[:alnum:]\[\]]+/, ' ') _parse_time(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\.)/i, ' ') if e[:year] e[:year] = -e[:year] + 1 end end if str.sub!(/\A\s*(\d{1,2})\s*\z/, ' ') 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.delete(:_) e end |