Sha256: 60569afa592b3d53c16c2547dc975d50b490b46bc74a11f166b2773ec845e30d

Contents?: true

Size: 515 Bytes

Versions: 3

Compression:

Stored size: 515 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Attributes
    # Custom attributes value to parse a String representing a Time using
    # the app TimeZone.
    class TimeWithZone < ActiveModel::Type::Time
      def type
        :"decidim/attributes/time_with_zone"
      end

      private

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-core-0.27.0 lib/decidim/attributes/time_with_zone.rb
decidim-core-0.27.0.rc2 lib/decidim/attributes/time_with_zone.rb
decidim-core-0.27.0.rc1 lib/decidim/attributes/time_with_zone.rb