Class: Holidate

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

Class Method Summary collapse

Class Method Details

.christmas_day(year = Date.today.year) ⇒ Object Also known as: xmas



66
67
68
# File 'lib/holidate.rb', line 66

def christmas_day(year=Date.today.year)
  Date.new(year, 12, 25)
end

.columbus_day(year = Date.today.year) ⇒ Object Also known as: columbus



51
52
53
# File 'lib/holidate.rb', line 51

def columbus_day(year=Date.today.year)
  find('second', 'monday', 'october', year)
end

.find(nth_, wday_, month_, year_ = Date.today.year) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/holidate.rb', line 8

def find(nth_, wday_, month_, year_=Date.today.year)
  nth = nth_int(nth_)
  wday = wday_int(wday_)
  month = month_int(month_)
  year = year_int(year_)
  if nth > 0
    Date.new(year, month, (1 + (nth - 1) * 7 + (wday - Date.new(year, month, 1).wday) % 7))
  else
    days_in_month = ((Date.new(year, month) >> 1) - 1).day
    Date.new(year, month, (days_in_month - (-nth - 1) * 7 - (Date.new(year, month, days_in_month).wday - wday) % 7))
  end
end

.independence_day(year = Date.today.year) ⇒ Object Also known as: july_4



41
42
43
# File 'lib/holidate.rb', line 41

def independence_day(year=Date.today.year)
  Date.new(year, 7, 4)
end

.labor_day(year = Date.today.year) ⇒ Object Also known as: labor



46
47
48
# File 'lib/holidate.rb', line 46

def labor_day(year=Date.today.year)
  find('first', 'monday', 'september', year)
end

.martin_luther_king_jr_day(year = Date.today.year) ⇒ Object Also known as: mlk



26
27
28
# File 'lib/holidate.rb', line 26

def martin_luther_king_jr_day(year=Date.today.year)
  find('third', 'monday', 'january', year)
end

.memorial_day(year = Date.today.year) ⇒ Object Also known as: memorial



36
37
38
# File 'lib/holidate.rb', line 36

def memorial_day(year=Date.today.year)
  find('last', 'monday', 'may', year)
end

.new_years_day(year = Date.today.year) ⇒ Object Also known as: new_year



21
22
23
# File 'lib/holidate.rb', line 21

def new_years_day(year=Date.today.year)
  Date.new(year, 1, 1)
end

.thanksgiving_day(year = Date.today.year) ⇒ Object Also known as: thanksgiving



61
62
63
# File 'lib/holidate.rb', line 61

def thanksgiving_day(year=Date.today.year)
  find('fourth', 'thursday', 'november', year)
end

.veterans_day(year = Date.today.year) ⇒ Object Also known as: veteran



56
57
58
# File 'lib/holidate.rb', line 56

def veterans_day(year=Date.today.year)
  Date.new(year, 11, 11)
end

.washingtons_birthday(year = Date.today.year) ⇒ Object Also known as: washington



31
32
33
# File 'lib/holidate.rb', line 31

def washingtons_birthday(year=Date.today.year)
  find('third', 'monday', 'february', year)
end