Method: ActiveScaffold::Finder::ClassMethods#condition_for_datetime

Defined in:
lib/active_scaffold/finder.rb

#condition_for_datetime(column, value, like_pattern = nil) ⇒ Object



363
364
365
366
367
368
369
370
371
372
373
374
375
376
# File 'lib/active_scaffold/finder.rb', line 363

def condition_for_datetime(column, value, like_pattern = nil)
  operator = ActiveScaffold::Finder::NUMERIC_COMPARATORS.include?(value['opt']) && value['opt'] != 'BETWEEN' ? value['opt'] : nil
  from_value, to_value = datetime_from_to(column, value)

  if column.search_sql.is_a? Proc
    column.search_sql.call(from_value, to_value, operator)
  elsif ActiveScaffold::Finder::NULL_COMPARATORS.include?(value['opt'])
    condition_for_null_type(column, value['opt'], like_pattern)
  elsif operator.nil?
    ['%<search_sql>s BETWEEN ? AND ?', from_value, to_value] unless from_value.nil? || to_value.nil?
  else
    ["%<search_sql>s #{value['opt']} ?", from_value] unless from_value.nil?
  end
end