Method: ActiveScaffold::Finder::ClassMethods#datetime_from_to_for_range

Defined in:
lib/active_scaffold/finder.rb

#datetime_from_to_for_range(column, value) ⇒ Object



427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
# File 'lib/active_scaffold/finder.rb', line 427

def datetime_from_to_for_range(column, value)
  case value['range']
  when 'TODAY'
    [datetime_now.beginning_of_day, datetime_now.end_of_day]
  when 'YESTERDAY'
    [datetime_now.ago(1.day).beginning_of_day, datetime_now.ago(1.day).end_of_day]
  when 'TOMORROW'
    [datetime_now.in(1.day).beginning_of_day, datetime_now.in(1.day).end_of_day]
  else
    range_type, range = value['range'].downcase.split('_')
    raise ArgumentError unless %w[week month year].include?(range)
    case range_type
    when 'this'
      return datetime_now.send("beginning_of_#{range}".to_sym), datetime_now.send("end_of_#{range}")
    when 'prev'
      return datetime_now.ago(1.send(range.to_sym)).send("beginning_of_#{range}".to_sym), datetime_now.ago(1.send(range.to_sym)).send("end_of_#{range}".to_sym)
    when 'next'
      return datetime_now.in(1.send(range.to_sym)).send("beginning_of_#{range}".to_sym), datetime_now.in(1.send(range.to_sym)).send("end_of_#{range}".to_sym)
    else
      return nil, nil
    end
  end
end