Class: Decidim::Attributes::LocalizedDate

Inherits:
Virtus::Attribute
  • Object
show all
Defined in:
lib/decidim/attributes/localized_date.rb

Overview

Custom Virtus value to parse a String representing a Date using the app localization format.

Instance Method Summary collapse

Instance Method Details

#coerce(value) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/decidim/attributes/localized_date.rb', line 8

def coerce(value)
  return value unless value.is_a?(String)

  Date.strptime(value, I18n.t("date.formats.decidim_short"))
rescue ArgumentError
  nil
end

#typeObject



16
17
18
# File 'lib/decidim/attributes/localized_date.rb', line 16

def type
  Axiom::Types::Date
end