Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/date_support.rb

Instance Method Summary collapse

Instance Method Details

#beginning_week_of_monthObject



29
30
31
# File 'lib/date_support.rb', line 29

def beginning_week_of_month
  self - (week_of_month - 1) * 7
end

#day_to(day) ⇒ Object



7
8
9
10
11
12
13
# File 'lib/date_support.rb', line 7

def day_to(day)
  wdays = {sunday: 0, monday: 1, tuesday: 2, wednesday: 3,
    thursday: 4, friday: 5, saturday: 6}
  adder = wdays[day] - wday

  self + adder
end

#nth_week_of_month(nth) ⇒ Object



33
34
35
# File 'lib/date_support.rb', line 33

def nth_week_of_month(nth)
  self + (nth - week_of_month) * 7
end

#week_of_monthObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/date_support.rb', line 15

def week_of_month
  weekend = beginning_of_month.end_of_week :sunday
  week = 1

  loop do
    break if self <= weekend

    weekend += 7
    week += 1
  end

  week
end