Sha256: 7e23211a25cd991e51bf501c603ca2df496606ebb5c3912fbab0c1e452d576a2

Contents?: true

Size: 421 Bytes

Versions: 10

Compression:

Stored size: 421 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
        nil
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
decidim-core-0.18.1 lib/decidim/attributes/localized_date.rb
decidim-core-0.17.2 lib/decidim/attributes/localized_date.rb
decidim-core-0.18.0 lib/decidim/attributes/localized_date.rb
decidim-core-0.17.1 lib/decidim/attributes/localized_date.rb
decidim-core-0.16.1 lib/decidim/attributes/localized_date.rb
decidim-core-0.17.0 lib/decidim/attributes/localized_date.rb
decidim-core-0.16.0 lib/decidim/attributes/localized_date.rb
decidim-core-0.15.2 lib/decidim/attributes/localized_date.rb
decidim-core-0.15.1 lib/decidim/attributes/localized_date.rb
decidim-core-0.15.0 lib/decidim/attributes/localized_date.rb