Class: InferModel::Parsers::DateTime

Inherits:
Object
  • Object
show all
Extended by:
Dry::Initializer, Callable
Defined in:
lib/infer_model/parsers/date_time.rb

Constant Summary collapse

ACCEPTABLE_DATETIME_FORMATS =
[
  "%Y-%m-%dT%T%z",
  "%Y-%m-%dT%T%Z",
  "%Y-%m-%dT%TZ",
  "%d.%m.%Y %T%z",
  "%d.%m.%Y %T%Z",
  "%d.%m.%Y %T",
  "%d.%m.%Y %H:%M",
  "%Y-%m-%dT",
  "%Y-%m-%d",
  "%d.%m.%Y",
].freeze

Instance Method Summary collapse

Instance Method Details

#callObject

Raises:



29
30
31
32
33
34
35
36
# File 'lib/infer_model/parsers/date_time.rb', line 29

def call
  raise Parsers::Error, "value was blank which is not allowed" if value.nil? && !allow_blank
  return if value.nil? || value.empty?

  # make sure value parsed once before applying time zone
  # so formats are validated
  apply_time_zone(parsed_datetime)
end