Module: ByStar::Between
- Included in:
- Base
- Defined in:
- lib/by_star/between.rb
Instance Method Summary collapse
- #at_time(*args) ⇒ Object
- #between_dates(*args) ⇒ Object
- #between_times(*args) ⇒ Object
- #by_calendar_month(*args) ⇒ Object
- #by_cweek(*args) ⇒ Object
- #by_day(*args) ⇒ Object
- #by_fortnight(*args) ⇒ Object
- #by_month(*args) ⇒ Object
- #by_quarter(*args) ⇒ Object
- #by_week(*args) ⇒ Object
- #by_weekend(*args) ⇒ Object
- #by_year(*args) ⇒ Object
- #next_day(options = {}) ⇒ Object
- #next_fortnight(options = {}) ⇒ Object
- #next_month(options = {}) ⇒ Object
- #next_week(options = {}) ⇒ Object
- #next_year(options = {}) ⇒ Object
- #past_day(options = {}) ⇒ Object
- #past_fortnight(options = {}) ⇒ Object
- #past_month(options = {}) ⇒ Object
- #past_week(options = {}) ⇒ Object
- #past_year(options = {}) ⇒ Object
- #today(options = {}) ⇒ Object
- #tomorrow(options = {}) ⇒ Object
- #yesterday(options = {}) ⇒ Object
Instance Method Details
#at_time(*args) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/by_star/between.rb', line 59 def at_time(*args) (*args) do |time, | start_field = by_star_start_field() end_field = by_star_end_field() scope = self scope = if start_field == end_field by_star_point_overlap_query(scope, start_field, time) else by_star_span_overlap_query(scope, start_field, end_field, time, ) end scope = by_star_order(scope, [:order]) if [:order] scope end end |
#between_dates(*args) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/by_star/between.rb', line 51 def between_dates(*args) = args. start_date, end_date = ByStar::Normalization.extract_range(args) start_date = ByStar::Normalization.date(start_date) end_date = ByStar::Normalization.date(end_date) between_times(start_date, end_date, ) end |
#between_times(*args) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 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 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/by_star/between.rb', line 3 def between_times(*args) = args..symbolize_keys! start_time, end_time = ByStar::Normalization.extract_range(args) start_time = start_time.to_time if start_time.is_a?(String) end_time = end_time.to_time if end_time.is_a?(String) offset = [:offset] || 0 field_type = by_star_field_type() if start_time.is_a?(Date) start_time = field_type == 'date' ? start_time : ByStar::Normalization.apply_offset_start(start_time.in_time_zone, offset) elsif start_time start_time += offset.seconds end if end_time.is_a?(Date) end_time = field_type == 'date' ? end_time : ByStar::Normalization.apply_offset_end(end_time.in_time_zone, offset) elsif end_time end_time += offset.seconds end start_field = by_star_start_field() end_field = by_star_end_field() scope = self scope = if !start_time && !end_time scope # do nothing elsif !end_time by_star_after_query(scope, start_field, start_time) elsif !start_time by_star_before_query(scope, start_field, end_time) elsif start_field == end_field by_star_point_query(scope, start_field, start_time, end_time) elsif [:strict] by_star_span_strict_query(scope, start_field, end_field, start_time, end_time) else by_star_span_loose_query(scope, start_field, end_field, start_time, end_time, ) end scope = by_star_order(scope, [:order]) if [:order] scope end |
#by_calendar_month(*args) ⇒ Object
117 118 119 120 121 122 123 |
# File 'lib/by_star/between.rb', line 117 def by_calendar_month(*args) (*args) do |time, | date = ByStar::Normalization.month(time, ) start_day = Array([:start_day]) between_dates(date.beginning_of_calendar_month(*start_day), date.end_of_calendar_month(*start_day), ) end end |
#by_cweek(*args) ⇒ Object
90 91 92 93 94 |
# File 'lib/by_star/between.rb', line 90 def by_cweek(*args) (*args) do |time, | by_week(ByStar::Normalization.cweek(time, ), ) end end |
#by_day(*args) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/by_star/between.rb', line 75 def by_day(*args) (*args) do |time, | date = ByStar::Normalization.date(time) between_dates(date, date, ) end end |
#by_fortnight(*args) ⇒ Object
103 104 105 106 107 108 |
# File 'lib/by_star/between.rb', line 103 def by_fortnight(*args) (*args) do |time, | date = ByStar::Normalization.fortnight(time, ) between_dates(date.beginning_of_fortnight, date.end_of_fortnight, ) end end |
#by_month(*args) ⇒ Object
110 111 112 113 114 115 |
# File 'lib/by_star/between.rb', line 110 def by_month(*args) (*args) do |time, | date = ByStar::Normalization.month(time, ) between_dates(date.beginning_of_month, date.end_of_month, ) end end |
#by_quarter(*args) ⇒ Object
125 126 127 128 129 130 |
# File 'lib/by_star/between.rb', line 125 def by_quarter(*args) (*args) do |time, | date = ByStar::Normalization.quarter(time, ) between_dates(date.beginning_of_quarter, date.end_of_quarter, ) end end |
#by_week(*args) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/by_star/between.rb', line 82 def by_week(*args) (*args) do |time, | date = ByStar::Normalization.week(time, ) start_day = Array([:start_day]) between_dates(date.beginning_of_week(*start_day), date.end_of_week(*start_day), ) end end |
#by_weekend(*args) ⇒ Object
96 97 98 99 100 101 |
# File 'lib/by_star/between.rb', line 96 def by_weekend(*args) (*args) do |time, | date = ByStar::Normalization.week(time, ) between_dates(date.beginning_of_weekend, date.end_of_weekend, ) end end |
#by_year(*args) ⇒ Object
132 133 134 135 136 137 |
# File 'lib/by_star/between.rb', line 132 def by_year(*args) (*args) do |time, | date = ByStar::Normalization.year(time, ) between_dates(date.beginning_of_year, date.to_date.end_of_year, ) end end |
#next_day(options = {}) ⇒ Object
171 172 173 |
# File 'lib/by_star/between.rb', line 171 def next_day( = {}) between_times(Time.current, Time.current + 1.day, ) end |
#next_fortnight(options = {}) ⇒ Object
179 180 181 |
# File 'lib/by_star/between.rb', line 179 def next_fortnight( = {}) between_times(Time.current, Time.current + 2.weeks, ) end |
#next_month(options = {}) ⇒ Object
183 184 185 |
# File 'lib/by_star/between.rb', line 183 def next_month( = {}) between_times(Time.current, Time.current + 1.month, ) end |
#next_week(options = {}) ⇒ Object
175 176 177 |
# File 'lib/by_star/between.rb', line 175 def next_week( = {}) between_times(Time.current, Time.current + 1.week, ) end |
#next_year(options = {}) ⇒ Object
187 188 189 |
# File 'lib/by_star/between.rb', line 187 def next_year( = {}) between_times(Time.current, Time.current + 1.year, ) end |
#past_day(options = {}) ⇒ Object
151 152 153 |
# File 'lib/by_star/between.rb', line 151 def past_day( = {}) between_times(Time.current - 1.day, Time.current, ) end |
#past_fortnight(options = {}) ⇒ Object
159 160 161 |
# File 'lib/by_star/between.rb', line 159 def past_fortnight( = {}) between_times(Time.current - 2.weeks, Time.current, ) end |
#past_month(options = {}) ⇒ Object
163 164 165 |
# File 'lib/by_star/between.rb', line 163 def past_month( = {}) between_times(Time.current - 1.month, Time.current, ) end |
#past_week(options = {}) ⇒ Object
155 156 157 |
# File 'lib/by_star/between.rb', line 155 def past_week( = {}) between_times(Time.current - 1.week, Time.current, ) end |
#past_year(options = {}) ⇒ Object
167 168 169 |
# File 'lib/by_star/between.rb', line 167 def past_year( = {}) between_times(Time.current - 1.year, Time.current, ) end |
#today(options = {}) ⇒ Object
139 140 141 |
# File 'lib/by_star/between.rb', line 139 def today( = {}) by_day(Date.current, ) end |
#tomorrow(options = {}) ⇒ Object
147 148 149 |
# File 'lib/by_star/between.rb', line 147 def tomorrow( = {}) by_day(Date.tomorrow, ) end |
#yesterday(options = {}) ⇒ Object
143 144 145 |
# File 'lib/by_star/between.rb', line 143 def yesterday( = {}) by_day(Date.yesterday, ) end |