Class: Delocalize::LocalizedDateTimeParser

Inherits:
Object
  • Object
show all
Defined in:
lib/delocalize/localized_date_time_parser.rb

Class Method Summary collapse

Class Method Details

.parse(datetime, type) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/delocalize/localized_date_time_parser.rb', line 7

def parse(datetime, type)
  return unless datetime
  return datetime if datetime.respond_to?(:strftime) # already a Date/Time object -> no need to parse it

  translate_month_and_day_names(datetime)
  input_formats(type).each do |original_format|
    next unless datetime =~ /^#{apply_regex(original_format)}$/

    datetime = DateTime.strptime(datetime, original_format)
    return Date == type ?
      datetime.to_date :
      Time.zone.local(datetime.year, datetime.mon, datetime.mday, datetime.hour, datetime.min, datetime.sec)
  end
  default_parse(datetime, type)
end