Class: Date
- Inherits:
-
Object
- Object
- Date
- Defined in:
- lib/date_easter.rb
Class Method Summary collapse
-
.easter(year) ⇒ Object
:call-seq: Date::easter(year) => easter_sunday_Date.
Instance Method Summary collapse
-
#easter ⇒ Object
:call-seq: ref.easter() => easter_sunday_Date.
Class Method Details
.easter(year) ⇒ Object
:call-seq:
Date::easter(year) => easter_sunday_Date
Return the Date upon which Easter Sunday falls in year. The Gregorian calendar is used.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/date_easter.rb', line 48 def self.easter(year) unless year.is_a? Numeric raise TypeError, "year must be Numeric" end if year < 1583 raise ArgumentError, "Years before 1583 not supported" elsif year > 4099 raise ArgumentError, "Years after 4099 not supported" end golden_number = (year % 19) + 1 century = (year / 100) + 1 julian_epact = (11 * (golden_number -1)) % 30 solar_correction = (3 * century) / 4 lunar_correction = ((8 * century) + 5) / 25 gregorian_epact = (julian_epact - solar_correction + lunar_correction + 8) % 30 days_fm_ve_to_pfm = (23 - gregorian_epact) % 30 if gregorian_epact == 24 or gregorian_epact == 25 && golden_number > 11 days_fm_ve_to_pfm -= 1 end vernal_equinox = Date.new(year, 3, 21) paschal_full_moon = vernal_equinox + days_fm_ve_to_pfm days_to_sunday = 7 - paschal_full_moon.wday easter_sunday = paschal_full_moon + days_to_sunday end |