Class: TypedEAV::Field::DateTime

Inherits:
Base show all
Defined in:
app/models/typed_eav/field/date_time.rb

Constant Summary

Constants inherited from Base

Base::RESERVED_NAMES

Constants included from ColumnMapping

ColumnMapping::DEFAULT_OPERATORS_BY_COLUMN, ColumnMapping::FALLBACK_OPERATORS

Instance Method Summary collapse

Methods inherited from Base

#allowed_option_values, #array_field?, #clear_option_cache!, #default_value, #default_value=, #field_type_name, #optionable?

Instance Method Details

#cast(raw) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/models/typed_eav/field/date_time.rb', line 10

def cast(raw)
  return [nil, false] if raw.nil?
  return [raw, false] if raw.is_a?(::Time)

  result = ::Time.zone.parse(raw.to_s)
  if result.nil?
    [nil, !raw.to_s.strip.empty?]
  else
    [result, false]
  end
rescue ArgumentError
  [nil, true]
end

#validate_typed_value(record, val) ⇒ Object



24
25
26
# File 'app/models/typed_eav/field/date_time.rb', line 24

def validate_typed_value(record, val)
  validate_datetime_range(record, val)
end