Method: ActiveScaffold::Finder::ClassMethods#condition_value_for_datetime

Defined in:
lib/active_scaffold/finder.rb

#condition_value_for_datetime(column, value, conversion = :to_time) ⇒ Object



316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
# File 'lib/active_scaffold/finder.rb', line 316

def condition_value_for_datetime(column, value, conversion = :to_time)
  return if value.nil? || value.blank?
  if value.is_a? Hash
    local_time_from_hash(value, conversion)
  elsif value.respond_to?(:strftime)
    if conversion == :to_time
      # Explicitly get the current zone, because TimeWithZone#to_time in rails 3.2.3 returns UTC.
      # https://github.com/rails/rails/pull/2453
      value.to_time.in_time_zone
    else
      value.send(conversion)
    end
  elsif conversion == :to_date
    parse_date_with_format(*format_for_date(column, value))
  elsif value.include?('T')
    Time.zone.parse(value)
  else # datetime
    time = parse_time_with_format(value, *format_for_datetime(column, value))
    conversion == :to_time ? time : time.send(conversion)
  end
end