Sha256: fbfb4854465f68558d3d3378e58a02931485e66b80b6c388f74932278b7c459a

Contents?: true

Size: 741 Bytes

Versions: 6

Compression:

Stored size: 741 Bytes

Contents

module Alchemy
  module Ingredients
    class DatetimeView < BaseView
      attr_reader :date_format

      # @param ingredient [Alchemy::Ingredient]
      # @param date_format [String] The date format to use. Use either a strftime format string, a I18n format symbol or "rfc822".
      def initialize(ingredient, date_format: nil, html_options: {})
        super(ingredient)
        @date_format = settings_value(:date_format, value: date_format)
      end

      def call
        datetime = ingredient.value.in_time_zone(Rails.application.config.time_zone)
        if date_format == "rfc822"
          datetime.to_fs(:rfc822)
        else
          ::I18n.l(datetime, format: date_format)
        end.html_safe
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
alchemy_cms-7.2.8 app/components/alchemy/ingredients/datetime_view.rb
alchemy_cms-7.1.13 app/components/alchemy/ingredients/datetime_view.rb
alchemy_cms-7.2.7 app/components/alchemy/ingredients/datetime_view.rb
alchemy_cms-7.2.6 app/components/alchemy/ingredients/datetime_view.rb
alchemy_cms-7.2.5 app/components/alchemy/ingredients/datetime_view.rb
alchemy_cms-7.1.12 app/components/alchemy/ingredients/datetime_view.rb