-
-
Save kivanio/80d6f68acbe4f82ad9de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'time' | |
module EasterCalculations | |
extend ActiveSupport::Concern | |
module ClassMethods | |
def easter(year = nil) | |
y = year ||= now.year | |
c = y / 100 | |
n = y - 19 * ( y / 19 ) | |
k = ( c - 17 ) / 25 | |
i = c - c / 4 - ( c - k ) / 3 + 19 * n + 15 | |
i = i - 30 * ( i / 30 ) | |
i = i - ( i / 28 ) * ( 1 - ( i / 28 ) * ( 29 / ( i + 1 ) ) * ( ( 21 - n ) / 11 ) ) | |
j = y + y / 4 + i + 2 - c + c / 4 | |
j = j - 7 * ( j / 7 ) | |
l = i - j | |
m = 3 + ( l + 40 ) / 44 | |
d = l + 28 - 31 * ( m / 4 ) | |
mktime(y, m, d) | |
end | |
end | |
def easter? | |
self.class.easter.utc == self.at_beginning_of_day.utc | |
end | |
def good_friday? | |
(self.class.easter.utc - 2.days) == self.at_beginning_of_day.utc | |
end | |
def easter_monday? | |
(self.class.easter.utc + 1.day) == self.at_beginning_of_day.utc | |
end | |
end | |
Time.send(:include, EasterCalculations) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment