Class: Date

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

Class Method Summary collapse

Instance Method Summary collapse

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

Instance Method Details

#easterObject

:call-seq:

ref.easter()    => easter_sunday_Date

Return the Date of Easter Sunday for the year in which ref falls. The Gregorian calendar is used.



88
89
90
# File 'lib/date_easter.rb', line 88

def easter
  Date::easter(self.year)
end