Sha256: 343dd7ffdeeb3caa944e0874d03b67bfad982f8dc40508582452582699012fb5

Contents?: true

Size: 475 Bytes

Versions: 33

Compression:

Stored size: 475 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

      def type
        Axiom::Types::Date
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
decidim-core-0.26.3 lib/decidim/attributes/localized_date.rb
decidim-core-0.26.2 lib/decidim/attributes/localized_date.rb
decidim-core-0.26.1 lib/decidim/attributes/localized_date.rb
decidim-core-0.26.0 lib/decidim/attributes/localized_date.rb
decidim-core-0.26.0.rc2 lib/decidim/attributes/localized_date.rb
decidim-core-0.26.0.rc1 lib/decidim/attributes/localized_date.rb
decidim-core-0.25.2 lib/decidim/attributes/localized_date.rb
decidim-core-0.25.1 lib/decidim/attributes/localized_date.rb
decidim-core-0.25.0 lib/decidim/attributes/localized_date.rb
decidim-core-0.25.0.rc4 lib/decidim/attributes/localized_date.rb
decidim-core-0.25.0.rc3 lib/decidim/attributes/localized_date.rb
decidim-core-0.25.0.rc2 lib/decidim/attributes/localized_date.rb
decidim-core-0.25.0.rc1 lib/decidim/attributes/localized_date.rb
decidim-core-0.24.3 lib/decidim/attributes/localized_date.rb
decidim-core-0.23.6 lib/decidim/attributes/localized_date.rb
decidim-core-0.24.2 lib/decidim/attributes/localized_date.rb
decidim-core-0.23.5 lib/decidim/attributes/localized_date.rb
decidim-core-0.24.1 lib/decidim/attributes/localized_date.rb
decidim-core-0.24.0 lib/decidim/attributes/localized_date.rb
decidim-core-0.24.0.rc2 lib/decidim/attributes/localized_date.rb