Module: ByStar::Between

Included in:
Base
Defined in:
lib/by_star/between.rb

Instance Method Summary collapse

Instance Method Details

#between_times(start, finish, options = {}) ⇒ Object



5
6
7
8
# File 'lib/by_star/between.rb', line 5

def between_times(start, finish, options={})
  offset = by_star_offset(options)
  between_times_query(start + offset, finish + offset, options)
end

#by_calendar_month(*args) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/by_star/between.rb', line 46

def by_calendar_month(*args)
  with_by_star_options(*args) do |time, options|
    time = ByStar::Normalization.month(time, options)
    start_day = Array(options[:start_day])
    between_times(time.beginning_of_calendar_month(*start_day), time.end_of_calendar_month(*start_day), options)
  end
end

#by_day(*args) ⇒ Object



10
11
12
13
14
15
# File 'lib/by_star/between.rb', line 10

def by_day(*args)
  with_by_star_options(*args) do |time, options|
    time = ByStar::Normalization.time(time)
    between_times(time.beginning_of_day, time.end_of_day, options)
  end
end

#by_fortnight(*args) ⇒ Object



32
33
34
35
36
37
# File 'lib/by_star/between.rb', line 32

def by_fortnight(*args)
  with_by_star_options(*args) do |time, options|
    time = ByStar::Normalization.fortnight(time, options)
    between_times(time.beginning_of_fortnight, time.end_of_fortnight, options)
  end
end

#by_month(*args) ⇒ Object



39
40
41
42
43
44
# File 'lib/by_star/between.rb', line 39

def by_month(*args)
  with_by_star_options(*args) do |time, options|
    time = ByStar::Normalization.month(time, options)
    between_times(time.beginning_of_month, time.end_of_month, options)
  end
end

#by_quarter(*args) ⇒ Object



54
55
56
57
58
59
# File 'lib/by_star/between.rb', line 54

def by_quarter(*args)
  with_by_star_options(*args) do |time, options|
    time = ByStar::Normalization.quarter(time, options)
    between_times(time.beginning_of_quarter, time.end_of_quarter, options)
  end
end

#by_week(*args) ⇒ Object



17
18
19
20
21
22
23
# File 'lib/by_star/between.rb', line 17

def by_week(*args)
  with_by_star_options(*args) do |time, options|
    time = ByStar::Normalization.week(time, options)
    start_day = Array(options[:start_day])
    between_times(time.beginning_of_week(*start_day), time.end_of_week(*start_day), options)
  end
end

#by_weekend(*args) ⇒ Object



25
26
27
28
29
30
# File 'lib/by_star/between.rb', line 25

def by_weekend(*args)
  with_by_star_options(*args) do |time, options|
    time = ByStar::Normalization.week(time, options)
    between_times(time.beginning_of_weekend, time.end_of_weekend, options)
  end
end

#by_year(*args) ⇒ Object



61
62
63
64
65
66
# File 'lib/by_star/between.rb', line 61

def by_year(*args)
  with_by_star_options(*args) do |time, options|
    time = ByStar::Normalization.year(time, options)
    between_times(time.beginning_of_year, time.end_of_year, options)
  end
end

#next_day(options = {}) ⇒ Object



100
101
102
# File 'lib/by_star/between.rb', line 100

def next_day(options={})
  between_times(Time.zone.now, Time.zone.now + 1.day, options)
end

#next_fortnight(options = {}) ⇒ Object



108
109
110
# File 'lib/by_star/between.rb', line 108

def next_fortnight(options={})
  between_times(Time.zone.now, Time.zone.now + 2.weeks, options)
end

#next_month(options = {}) ⇒ Object



112
113
114
# File 'lib/by_star/between.rb', line 112

def next_month(options={})
  between_times(Time.zone.now, Time.zone.now + 1.month, options)
end

#next_week(options = {}) ⇒ Object



104
105
106
# File 'lib/by_star/between.rb', line 104

def next_week(options={})
  between_times(Time.zone.now, Time.zone.now  + 1.week, options)
end

#next_year(options = {}) ⇒ Object



116
117
118
# File 'lib/by_star/between.rb', line 116

def next_year(options={})
  between_times(Time.zone.now, Time.zone.now + 1.year, options)
end

#past_day(options = {}) ⇒ Object



80
81
82
# File 'lib/by_star/between.rb', line 80

def past_day(options={})
  between_times(Time.zone.now - 1.day, Time.zone.now, options)
end

#past_fortnight(options = {}) ⇒ Object



88
89
90
# File 'lib/by_star/between.rb', line 88

def past_fortnight(options={})
  between_times(Time.zone.now - 2.weeks, Time.zone.now, options)
end

#past_month(options = {}) ⇒ Object



92
93
94
# File 'lib/by_star/between.rb', line 92

def past_month(options={})
  between_times(Time.zone.now - 1.month, Time.zone.now, options)
end

#past_week(options = {}) ⇒ Object



84
85
86
# File 'lib/by_star/between.rb', line 84

def past_week(options={})
  between_times(Time.zone.now - 1.week, Time.zone.now, options)
end

#past_year(options = {}) ⇒ Object



96
97
98
# File 'lib/by_star/between.rb', line 96

def past_year(options={})
  between_times(Time.zone.now - 1.year, Time.zone.now, options)
end

#today(options = {}) ⇒ Object



68
69
70
# File 'lib/by_star/between.rb', line 68

def today(options={})
  by_day(Time.zone.now, options)
end

#tomorrow(options = {}) ⇒ Object



76
77
78
# File 'lib/by_star/between.rb', line 76

def tomorrow(options={})
  by_day(Time.zone.now.tomorrow, options)
end

#yesterday(options = {}) ⇒ Object



72
73
74
# File 'lib/by_star/between.rb', line 72

def yesterday(options={})
  by_day(Time.zone.now.yesterday, options)
end