10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
# File 'lib/fortnight.rb', line 10
def in_fortnight(year, month, options={})
begin_of_month = Time.new(year, month)
half_month = begin_of_month.advance(days: 14).end_of_day
final_of_month = begin_of_month.end_of_month.end_of_day
start = options[:half] == :second ? half_month : begin_of_month
finish = options[:half] == :second ? final_of_month : half_month
field = options[:field] || 'created_at'
scope = where("#{field} >= :s AND #{field} <= :f", s: start, f: finish)
scope = scope.order(options[:order]) if options[:order]
scope
end
|