Sha256: 921f6760707735802884cf08324877f6e05ec2b2d743f0de9adff08f56e3bd9b

Contents?: true

Size: 760 Bytes

Versions: 59

Compression:

Stored size: 760 Bytes

Contents

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

        private

          def format_date(value)
            value.try(:strftime, "%Y-%m-%dT%T.%L%z")
          end

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

Version data entries

59 entries across 58 versions & 8 rubygems

Version Path
actionview-4.2.11.3 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.11.2 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.11.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.11 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.10 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.10.rc1 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.9 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.9.rc2 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.9.rc1 lib/action_view/helpers/tags/datetime_field.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/actionview-4.2.8/lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.8 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.8.rc1 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.7.1 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.7 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.7.rc1 lib/action_view/helpers/tags/datetime_field.rb
actionview-5.0.0.racecar1 lib/action_view/helpers/tags/datetime_field.rb
actionview-5.0.0.rc1 lib/action_view/helpers/tags/datetime_field.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/actionview-4.2.6/lib/action_view/helpers/tags/datetime_field.rb
actionview-5.0.0.beta4 lib/action_view/helpers/tags/datetime_field.rb
actionview-4.2.6 lib/action_view/helpers/tags/datetime_field.rb