private Method

InstanceTag.date_or_time_select(options)

There's no documentation for this item.

Source Code

# File action_view/helpers/date_helper.rb, line 593
def date_or_time_select(options)
  defaults = { :discard_type => true }
  options  = defaults.merge(options)
  datetime = value(object)
  datetime ||= default_time_from_options(options[:default]) unless options[:include_blank]

  position = { :year => 1, :month => 2, :day => 3, :hour => 4, :minute => 5, :second => 6 }

  order = (options[:order] ||= [:year, :month, :day])

  # Discard explicit and implicit by not being included in the :order
  discard = {}
  discard[:year]   = true if options[:discard_year] or !order.include?(:year)
  discard[:month]  = true if options[:discard_month] or !order.include?(:month)
  discard[:day]    = true if options[:discard_day] or discard[:month] or !order.include?(:day)
  discard[:hour]   = true if options[:discard_hour]
  discard[:minute] = true if options[:discard_minute] or discard[:hour]
  discard[:second] = true unless options[:include_seconds] && !discard[:minute]

  # If the day is hidden and the month is visible, the day should be set to the 1st so all month choices are valid
  # (otherwise it could be 31 and february wouldn't be a valid date)
  if datetime && discard[:day] && !discard[:month]
    datetime = datetime.change(:day => 1)
  end

  # Maintain valid dates by including hidden fields for discarded elements
  [:day, :month, :year].each { |o| order.unshift(o) unless order.include?(o) }

  # Ensure proper ordering of :hour, :minute and :second
  [:hour, :minute, :second].each { |o| order.delete(o); order.push(o) }

  date_or_time_select = ''
  order.reverse.each do |param|
    # Send hidden fields for discarded elements once output has started
    # This ensures AR can reconstruct valid dates using ParseDate
    next if discard[param] && date_or_time_select.empty?

    date_or_time_select.insert(0, self.send("select_#{param}", datetime, options_with_prefix(position[param], options.merge(:use_hidden => discard[param]))))
    date_or_time_select.insert(0,
      case param
        when :hour then (discard[:year] && discard[:day] ? "" : " — ")
        when :minute then " : "
        when :second then options[:include_seconds] ? " : " : ""
        else ""
      end)

  end

  date_or_time_select
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.