Method: Date._parse

Defined in:
lib/framework/date/format.rb,
lib/framework/autocomplete/Date.rb

._parse(str, comp) ⇒ Object



1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
# File 'lib/framework/date/format.rb', line 1034

def self._parse(str, comp=true)
  str = str.dup

  e = Date::Format::Bag.new

  e._comp = comp

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

  _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\.)/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.to_hash
end