Sha256: b59c8ff3e0504b92d41c3cb2733969abe18c33964ad95b7c697a8bddca86ffe4
Contents?: true
Size: 666 Bytes
Versions: 6
Compression:
Stored size: 666 Bytes
Contents
# frozen_string_literal: true module Decidim module Attributes # Custom Virtus value to parse a String representing a Date using # the app localization format. class LocalizedDate < Virtus::Attribute def coerce(value) return value unless value.is_a?(String) Date.strptime(value, I18n.t("date.formats.decidim_short")) rescue ArgumentError coerce_fallback(value) end def type Axiom::Types::Date end private def coerce_fallback(value) coercer.coercers[DateTime].public_send(type.coercion_method, value) rescue Date::Error nil end end end end
Version data entries
6 entries across 6 versions & 1 rubygems