Sha256: 084c666058fc4f5c7ad781903e6faa0d2b95cce9fcf4505e18eb2cbeefa65f65
Contents?: true
Size: 637 Bytes
Versions: 10
Compression:
Stored size: 637 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::DateTime 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 fallback = super return fallback unless fallback.is_a?(Time) Time.zone.parse(fallback.strftime("%F %T")) end end end end
Version data entries
10 entries across 10 versions & 1 rubygems