Module: TimeTree::DateCalculator
- Included in:
- FileParser
- Defined in:
- lib/time_tree/date_calculator.rb
Instance Method Summary collapse
- #date_between?(date, from, to) ⇒ Boolean
- #in_prev_month?(date, count = 0, ref_date = Date.today) ⇒ Boolean
- #in_prev_week?(date, count = 0, ref_date = Date.today) ⇒ Boolean
- #next_weekday(date, weekday, count = 0) ⇒ Object
- #prev_weekday(date, weekday, count = 0) ⇒ Object
Instance Method Details
#date_between?(date, from, to) ⇒ Boolean
16 17 18 |
# File 'lib/time_tree/date_calculator.rb', line 16 def date_between?(date, from, to) date >= from && to >= date end |
#in_prev_month?(date, count = 0, ref_date = Date.today) ⇒ Boolean
26 27 28 29 |
# File 'lib/time_tree/date_calculator.rb', line 26 def in_prev_month?(date, count = 0, ref_date = Date.today) ref_month = ref_date >> (-1 * count) date.year == ref_month.year && date.month == ref_month.month end |
#in_prev_week?(date, count = 0, ref_date = Date.today) ⇒ Boolean
20 21 22 23 24 |
# File 'lib/time_tree/date_calculator.rb', line 20 def in_prev_week?(date, count = 0, ref_date = Date.today) monday = prev_weekday(ref_date, :mon, count) sunday = monday + 6 date_between?(date, monday, sunday) end |
#next_weekday(date, weekday, count = 0) ⇒ Object
10 11 12 13 14 |
# File 'lib/time_tree/date_calculator.rb', line 10 def next_weekday(date, weekday, count = 0) delta = (7 - date.wday + daynum(weekday)) % 7 delta = 7 if delta == 0 date + (delta + (count * 7)) end |
#prev_weekday(date, weekday, count = 0) ⇒ Object
5 6 7 8 |
# File 'lib/time_tree/date_calculator.rb', line 5 def prev_weekday(date, weekday, count = 0) delta = (7 + date.wday - daynum(weekday)) % 7 date - (delta + (count * 7)) end |