Class: HolidaysRules::Rules::Easter

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(year) ⇒ Easter

Returns a new instance of Easter.



69
70
71
# File 'lib/holidays_rules/rules.rb', line 69

def initialize(year)
  @year = year
end

Class Method Details

.holiday?(date) ⇒ Boolean

Returns:

  • (Boolean)


92
93
94
95
96
# File 'lib/holidays_rules/rules.rb', line 92

def self.holiday?(date)
  easter = Easter.new(date.year)

  easter.date == date
end

Instance Method Details

#dateObject



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/holidays_rules/rules.rb', line 73

def date
  a = @year % 19
  b = @year / 100
  c = @year % 100
  d = b / 4
  e = b % 4
  f = (b + 8) / 25
  g = (b - f + 1) / 3
  h = (19 * a + b - d - g + 15) % 30
  i = c / 4
  k = c % 4
  l = (32 + 2 * e + 2 * i - h - k) % 7
  m = (a + 11 * h + 22 * l) / 451
  month = (h + l - 7 * m + 114) / 31
  day = ((h + l - 7 * m + 114) % 31) + 1

  Date.new(@year, month, day)
end