15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/simple_date_scopes/simple_date_scopes.rb', line 15
def acts_as_date_scopes_on(field = DEFAULT_FIELD)
scope :yesterday, -> { in_x_of(Date.today - 1.day, field, :day) }
scope :today, -> { in_x_of(Date.today, field, :day) }
scope :tomorrow, -> { in_x_of(Date.today + 1.day, field, :day) }
scope :in_week_of, ->(date) { in_x_of(date, field, :week) }
scope :last_week, -> { in_week_of(Date.today - 7.days) }
scope :this_week, -> { in_week_of(Date.today) }
scope :next_week, -> { in_week_of(Date.today + 7.days) }
scope :in_month_of, ->(date) { in_x_of(date, field, :month) }
scope :last_month, -> { in_month_of(Date.today - 1.months) }
scope :this_month, -> { in_month_of(Date.today) }
scope :next_month, -> { in_month_of(Date.today + 1.months) }
scope :in_year_of, ->(date) { in_x_of(date, field, :year) }
scope :last_year, -> { in_year_of(Date.today - 1.years) }
scope :this_year, -> { in_year_of(Date.today) }
scope :next_year, -> { in_year_of(Date.today + 1.years) }
end
|