AlchemyCMS/alchemy_cms

View on GitHub
app/models/alchemy/ingredients/datetime.rb

Summary

Maintainability
A
0 mins
Test Coverage
A
100%
# frozen_string_literal: true

module Alchemy
  module Ingredients
    # A datetime value
    #
    class Datetime < Alchemy::Ingredient
      allow_settings %i[date_format input_type]

      def value
        ActiveRecord::Type::DateTime.new.cast(self[:value])
      end

      # Returns localized date for the Element#preview_text method.
      def preview_text(_maxlength = nil)
        return "" unless value

        ::I18n.l(value, format: :"alchemy.ingredient_date")
      end
    end
  end
end