aboutsummaryrefslogblamecommitdiffstats
path: root/actionview/lib/action_view/helpers/tags/datetime_field.rb
blob: b3940c7e44129c518a7d16e33d61f25574e74608 (plain) (tree)
1
2
3
4
5
6
7
8
9

                 

                                               

                                           
                                                         

                                                                      





                            
                                
                                     
             

                                   




                                              
             



         
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)
            raise NotImplementedError
          end

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