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
218 219 220 221 222 223 224 225 226 |
# File 'lib/daru/date_time/offsets.rb', line 218 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
228 229 230 231 232 233 234 235 236 |
# File 'lib/daru/date_time/offsets.rb', line 228 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
242 243 244 |
# File 'lib/daru/date_time/offsets.rb', line 242 def freq_string (@n == 1 ? '' : @n.to_s) + 'W' + '-' + Daru::DAYS_OF_WEEK.key(@weekday) end |
#on_offset?(date_time) ⇒ Boolean
238 239 240 |
# File 'lib/daru/date_time/offsets.rb', line 238 def on_offset? date_time date_time.wday == @weekday end |