Sha256: cf79c011440f2752d46275db13364949c3334844d0115564af1afa0e2fad73df

Contents?: true

Size: 977 Bytes

Versions: 42

Compression:

Stored size: 977 Bytes

Contents

# frozen_string_literal: true

module ActionView
  module Helpers
    module Tags # :nodoc:
      class DatetimeField < TextField # :nodoc:
        def render
          options = @options.stringify_keys
          options["value"] = datetime_value(options["value"] || value)
          options["min"] = format_datetime(parse_datetime(options["min"]))
          options["max"] = format_datetime(parse_datetime(options["max"]))
          @options = options
          super
        end

        private
          def datetime_value(value)
            if value.is_a?(String)
              value
            else
              format_datetime(value)
            end
          end

          def format_datetime(value)
            raise NotImplementedError
          end

          def parse_datetime(value)
            if value.is_a?(String)
              DateTime.parse(value) rescue nil
            else
              value
            end
          end
      end
    end
  end
end

Version data entries

42 entries across 42 versions & 6 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/actionview-7.1.3.4/lib/action_view/helpers/tags/datetime_field.rb
actionview-8.0.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-8.0.0.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.2.2.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.1.5.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-8.0.0 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.2.2 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.1.5 lib/action_view/helpers/tags/datetime_field.rb
actionview-8.0.0.rc2 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.2.1.2 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.1.4.2 lib/action_view/helpers/tags/datetime_field.rb
actionview-8.0.0.rc1 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.2.1.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-7.1.4.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-8.0.0.beta1 lib/action_view/helpers/tags/datetime_field.rb
omg-actionview-8.0.0.alpha9 lib/action_view/helpers/tags/datetime_field.rb
omg-actionview-8.0.0.alpha8 lib/action_view/helpers/tags/datetime_field.rb
omg-actionview-8.0.0.alpha7 lib/action_view/helpers/tags/datetime_field.rb
omg-actionview-8.0.0.alpha4 lib/action_view/helpers/tags/datetime_field.rb
omg-actionview-8.0.0.alpha3 lib/action_view/helpers/tags/datetime_field.rb