Class: Decidim::Attributes::TimeWithZone

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

Overview

Custom Virtus value to parse a String representing a Time using the app TimeZone.

Instance Method Summary collapse

Instance Method Details

#coerce(value) ⇒ Object



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

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

  Time.zone.strptime(value, I18n.t("time.formats.decidim_short"))
rescue ArgumentError
  nil
end

#typeObject



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

def type
  Axiom::Types::Time
end