Class: Daru::Offsets::Week
- Inherits:
-
DateOffset
- Object
- DateOffset
- Daru::Offsets::Week
- Defined in:
- lib/daru/date_time/offsets.rb
Instance Method Summary collapse
- #+(date_time) ⇒ Object
- #-(date_time) ⇒ Object
- #freq_string ⇒ Object
-
#initialize(*args) ⇒ Week
constructor
A new instance of Week.
- #on_offset?(date_time) ⇒ Boolean
Methods inherited from DateOffset
Constructor Details
Instance Method Details
#+(date_time) ⇒ Object
221 222 223 224 225 226 227 228 229 |
# File 'lib/daru/date_time/offsets.rb', line 221 def + date_time wday = date_time.wday distance = (@weekday - wday).abs if @weekday > wday date_time + distance + 7*(@n-1) else date_time + (7-distance) + 7*(@n -1) end end |
#-(date_time) ⇒ Object
231 232 233 234 235 236 237 238 239 |
# File 'lib/daru/date_time/offsets.rb', line 231 def - date_time wday = date_time.wday distance = (@weekday - wday).abs if @weekday >= wday date_time - ((7 - distance) + 7*(@n -1)) else date_time - (distance + 7*(@n-1)) end end |
#freq_string ⇒ Object
245 246 247 |
# File 'lib/daru/date_time/offsets.rb', line 245 def freq_string (@n == 1 ? '' : @n.to_s) + 'W' + '-' + Daru::DAYS_OF_WEEK.key(@weekday) end |
#on_offset?(date_time) ⇒ Boolean
241 242 243 |
# File 'lib/daru/date_time/offsets.rb', line 241 def on_offset? date_time date_time.wday == @weekday end |