Module: TimeCrisis::Holiday

Defined in:
lib/time_crisis/holiday.rb

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.holidaysObject



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/time_crisis/holiday.rb', line 66

def holidays
  @@holidays ||= {
          :new_years_day => [1, 1],
          :presidents_day => TimeCrisis::Holiday.presidents_day,
          :memorial_day => TimeCrisis::Holiday.memorial_day,
          :independence_day => [7, 4],
          :labor_day => TimeCrisis::Holiday.labor_day,
          :veterans_day => TimeCrisis::Holiday.veterans_day,
          :thanksgiving_day => TimeCrisis::Holiday.thanksgiving_day,
          :christmas_day => [12, 25]
  }
end

.labor_dayObject



23
24
25
26
27
28
29
30
31
# File 'lib/time_crisis/holiday.rb', line 23

def labor_day
  first_monday_in_sept = TimeCrisis::Date.nth_weekday({
          :month => 9,
          :weekday => :monday,
          :nth => 1
  })

  [first_monday_in_sept.month, first_monday_in_sept.day]
end

.memorial_dayObject



13
14
15
16
17
18
19
20
21
# File 'lib/time_crisis/holiday.rb', line 13

def memorial_day
  last_monday_of_may = TimeCrisis::Date.nth_weekday({
          :month => 5,
          :weekday => :monday,
          :nth => :last
  })

  [last_monday_of_may.month, last_monday_of_may.day]
end

.presidents_dayObject



3
4
5
6
7
8
9
10
11
# File 'lib/time_crisis/holiday.rb', line 3

def presidents_day
  third_monday_of_feb = TimeCrisis::Date.nth_weekday({
          :month => 2,
          :weekday => :monday,
          :nth => 3
  })

  [third_monday_of_feb.month, third_monday_of_feb.day]
end

.thanksgiving_dayObject



56
57
58
59
60
61
62
63
64
# File 'lib/time_crisis/holiday.rb', line 56

def thanksgiving_day
  fourth_thursday_in_november = TimeCrisis::Date.nth_weekday({
          :month => 9,
          :weekday => :thursday,
          :nth => 4
  })

  [fourth_thursday_in_november.month, fourth_thursday_in_november.day]
end

.veterans_dayObject



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/time_crisis/holiday.rb', line 33

def veterans_day
  day = nil

  nov11 = TimeCrisis::Date.today.change({
          :month => 11,
          :day => 11
  })

  # Veterans day is usually observed on November 11. However, if it occurs
  # on a Sunday then the following Monday is designated for holiday leave, 
  # and if it occurs Saturday then either Saturday or Friday may be so 
  # designated.
  if nov11.wday == 0
    day = 12
  elsif nov11.wday == 6
    day = 10
  else
    day = 11
  end

  [11, day]
end