Module: DigitalOpera::HolidayCalculations

Included in:
Date, Time
Defined in:
lib/is_business_day/digitalopera/holiday_calculations.rb

Instance Method Summary collapse

Instance Method Details

#is_a_holiday?Boolean

Returns TRUE || FALSE if the date is a recognized holiday

Returns:

  • (Boolean)


10
11
12
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 10

def is_a_holiday?
  self.is_memorial_day? || self.is_labor_day? || self.is_thanksgiving_day? || self.is_new_years_day? || self.is_xmas_day? || self.is_xmas_eve? || self.is_fourth_of_july?
end

#is_christmas_day?Boolean Also known as: is_xmas_day?

Christmas Day (December 25th) & Christmas Eve (December 24th) Since these holidays do not change from year to year, we are only providing boolean checks

Returns:

  • (Boolean)


87
88
89
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 87

def is_christmas_day?
  self.month == 12 && self.mday == 25
end

#is_christmas_eve?Boolean Also known as: is_xmas_eve?

Returns:

  • (Boolean)


97
98
99
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 97

def is_christmas_eve?
  self.month == 12 && self.mday == 24
end

#is_fourth_of_july?Boolean

July 4th Since this holiday does not change we are only providing boolean checks

Returns:

  • (Boolean)


122
123
124
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 122

def is_fourth_of_july?
  self.month == 7 && self.mday == 4
end

#is_labor_day?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 33

def is_labor_day?
  self == self.labor_day_this_year
end

#is_memorial_day?Boolean

Returns:

  • (Boolean)


54
55
56
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 54

def is_memorial_day?
  self == self.memorial_day_this_year
end

#is_new_years_day?Boolean

New Years Day (January 1st) Since this holiday does not change, it is always January 1st, we are only providing boolean checks

Returns:

  • (Boolean)


111
112
113
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 111

def is_new_years_day?
  self.yday == 1
end

#is_not_a_holiday?Boolean

Returns TRUE || FALSE if the date IS NOT a recognized holiday

Returns:

  • (Boolean)


16
17
18
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 16

def is_not_a_holiday?
  self.is_not_memorial_day? && self.is_not_labor_day? && self.is_not_thanksgiving_day? && self.is_not_new_years_day? && self.is_not_xmas_day? && self.is_not_xmas_eve? && self.is_not_fourth_of_july?
end

#is_not_christmas_day?Boolean Also known as: is_not_xmas_day?

Returns:

  • (Boolean)


92
93
94
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 92

def is_not_christmas_day?
  self.month != 12 || self.mday != 25
end

#is_not_christmas_eve?Boolean Also known as: is_not_xmas_eve?

Returns:

  • (Boolean)


102
103
104
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 102

def is_not_christmas_eve?
  self.month != 12 || self.mday != 24
end

#is_not_fourth_of_july?Boolean

Returns:

  • (Boolean)


126
127
128
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 126

def is_not_fourth_of_july?
  self.month != 7 || self.mday != 4
end

#is_not_labor_day?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 37

def is_not_labor_day?
  self != self.labor_day_this_year
end

#is_not_memorial_day?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 58

def is_not_memorial_day?
  self != self.memorial_day_this_year
end

#is_not_new_years_day?Boolean

Returns:

  • (Boolean)


115
116
117
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 115

def is_not_new_years_day?
  self.yday != 1
end

#is_not_thanksgiving_day?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 79

def is_not_thanksgiving_day?
  self != self.thanksgiving_day_this_year
end

#is_thanksgiving_day?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 75

def is_thanksgiving_day?
  self == self.thanksgiving_day_this_year
end

#labor_day_this_yearObject

Labor Day (First monday in september) en.wikipedia.org/wiki/Labor_Day



23
24
25
26
27
28
29
30
31
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 23

def labor_day_this_year
  september = Date.parse("01/09/#{self.year}")
  labor_day = september.beginning_of_month.step(september.end_of_month, 1).map{ |day| day if day.monday? }.compact.first
  if self.class.name == "Time"
    return labor_day.to_time
  else
    return labor_day
  end
end

#memorial_day_this_yearObject

Memorial Day (Last monday in may) en.wikipedia.org/wiki/Memorial_Day



44
45
46
47
48
49
50
51
52
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 44

def memorial_day_this_year
  may           = Date.parse("01/05/#{self.year}")
  memorial_day  = may.beginning_of_month.step(may.end_of_month, 1).map{ |day| day if day.monday? }.compact.last
  if self.class.name == "Time"
    return memorial_day.to_time
  else
    return memorial_day
  end
end

#thanksgiving_day_this_yearObject

Thanksgiving Day (fourth thursday in november in the US) en.wikipedia.org/wiki/Thanksgiving



65
66
67
68
69
70
71
72
73
# File 'lib/is_business_day/digitalopera/holiday_calculations.rb', line 65

def thanksgiving_day_this_year
  november          = Date.parse("01/11/#{self.year}")
  thanksgiving_day  = november.beginning_of_month.step(november.end_of_month, 1).map{ |day| day if day.thursday? }.compact.fourth
  if self.class.name == "Time"
    return thanksgiving_day.to_time
  else
    return thanksgiving_day
  end
end