class Delocalize::Parsers::DateTime

Constants

REGEXPS

extend/change this according to your needs by merging your custom regexps

Attributes

type[R]

Public Instance Methods

parse(datetime) click to toggle source
# File lib/delocalize/parsers/date_time.rb, line 31
def parse(datetime)
  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) rescue break
    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

Public Class Methods

new(type) click to toggle source
# File lib/delocalize/parsers/date_time.rb, line 27
def initialize(type)
  @type = type
end