Module: EnterpriseTimeExtensions
- Defined in:
- lib/enterprise_time_extensions.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #after_hours? ⇒ Boolean
- #christmas_day? ⇒ Boolean
- #holiday? ⇒ Boolean
- #independence_day? ⇒ Boolean
- #labor_day? ⇒ Boolean
- #memorial_day? ⇒ Boolean
- #mlk_jr_day? ⇒ Boolean
- #new_years_day? ⇒ Boolean
- #thanksgiving? ⇒ Boolean
Instance Method Details
#after_hours? ⇒ Boolean
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/enterprise_time_extensions.rb', line 34 def after_hours? result = true # M-F, 8am to 6pm are business hours if (1..5).include?(self.wday) && (8..17).include?(self.hour) result = false end # unless it's a holiday! if self.holiday? result = true end result end |
#christmas_day? ⇒ Boolean
96 97 98 99 |
# File 'lib/enterprise_time_extensions.rb', line 96 def christmas_day? return false unless self.month == 12 && self.mday == 25 true end |
#holiday? ⇒ Boolean
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/enterprise_time_extensions.rb', line 47 def holiday? unless new_years_day? || mlk_jr_day? || memorial_day? || independence_day? || labor_day? || thanksgiving? || christmas_day? return false end true end |
#independence_day? ⇒ Boolean
81 82 83 84 |
# File 'lib/enterprise_time_extensions.rb', line 81 def independence_day? return false unless self.month == 7 && self.mday == 4 true end |
#labor_day? ⇒ Boolean
86 87 88 89 |
# File 'lib/enterprise_time_extensions.rb', line 86 def labor_day? return false unless self.yday == Time.nth_wday(1,1,9,self.year).yday true end |
#memorial_day? ⇒ Boolean
70 71 72 73 74 75 76 77 78 79 |
# File 'lib/enterprise_time_extensions.rb', line 70 def memorial_day? last_day_of_month = Time.local(self.year, 5, 31) if last_day_of_month.wday == 0 d = 25 else d = last_day_of_month.mday - last_day_of_month.wday + 1 end return false unless self.yday == Time.local(self.year, 5, d).yday true end |
#mlk_jr_day? ⇒ Boolean
65 66 67 68 |
# File 'lib/enterprise_time_extensions.rb', line 65 def mlk_jr_day? return false unless self.yday == Time.nth_wday(3,1,1,self.year).yday true end |
#new_years_day? ⇒ Boolean
60 61 62 63 |
# File 'lib/enterprise_time_extensions.rb', line 60 def new_years_day? return false unless self.yday == 1 true end |
#thanksgiving? ⇒ Boolean
91 92 93 94 |
# File 'lib/enterprise_time_extensions.rb', line 91 def thanksgiving? return false unless self.yday == self.class.nth_wday(4,4,11,self.year).yday true end |