Class: WhenEaster
- Inherits:
-
Object
- Object
- WhenEaster
- Defined in:
- lib/when_easter.rb
Class Method Summary collapse
-
.find(year = nil) ⇒ Object
WhenEaster.find => In the year 2011, the Roman Easter is on 24 April.
-
.find_greek(year) ⇒ Object
WhenEaster.find_greek => In the year 2011, the Greek Easter is on 24 April.
-
.find_roman(year = nil) ⇒ Object
WhenEaster.find_roman => In the year 2011, the Roman Easter is on 24 April.
-
.greek_easter(year = nil) ⇒ Object
WhenEaster.greek_easter => Sun Apr 24 00:00:00 +0200 2011.
-
.roman_easter(year = nil) ⇒ Object
WhenEaster.roman_easter => Sun Apr 24 00:00:00 +0200 2011.
Class Method Details
.find(year = nil) ⇒ Object
WhenEaster.find
> In the year 2011, the Roman Easter is on 24 April. n In the year 2011, the Greek Easter is on 24 April.
4 5 6 7 8 |
# File 'lib/when_easter.rb', line 4 def self.find(year = nil) roman_date = self.roman_easter(year) greek_date = self.greek_easter(year) return "In the year #{roman_date.year}, the Roman Easter is on #{roman_date.strftime("%d %B")}. \nIn the year #{greek_date.year}, the Roman Easter is on #{greek_date.strftime("%d %B")}." end |
.find_greek(year) ⇒ Object
WhenEaster.find_greek
> In the year 2011, the Greek Easter is on 24 April.
19 20 21 22 |
# File 'lib/when_easter.rb', line 19 def self.find_greek(year) date = self.greek_easter(year) return "In the year #{date.year}, the Greek Easter is on #{date.strftime("%d %B")}." end |
.find_roman(year = nil) ⇒ Object
WhenEaster.find_roman
> In the year 2011, the Roman Easter is on 24 April.
12 13 14 15 |
# File 'lib/when_easter.rb', line 12 def self.find_roman(year = nil) date = self.roman_easter(year) return "In the year #{date.year}, the Roman Easter is on #{date.strftime("%d %B")}." end |
.greek_easter(year = nil) ⇒ Object
WhenEaster.greek_easter
> Sun Apr 24 00:00:00 +0200 2011
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/when_easter.rb', line 57 def self.greek_easter(year = nil) year = Time.now.year if year.nil? year = year.to_i if year.is_a?(String) a = year % 19 b = year % 4 c = year % 7 d = (19 * a + 16) % 30 e = (2 * b + 4 * c + 6 * d) % 7; easter = 3 + d + e; if easter <= 30 Time.local(year, 4, easter) else Time.local(year, 5, (easter - 30)) end end |
.roman_easter(year = nil) ⇒ Object
WhenEaster.roman_easter
> Sun Apr 24 00:00:00 +0200 2011
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/when_easter.rb', line 25 def self.roman_easter(year = nil) year = Time.now.year if year.nil? year = year.to_i if year.is_a?(String) g = year % 19 +1 s = (year -1600) / 100 - (year-1600) / 400 l = (((year - 1400) / 100) * 8) / 25 p_2 = (3-11*g +s -l) % 30 if p_2 == 29 || (p_2 == 28 && g > 11) p = p_2 -1 else p= p_2 end d= (year + year / 4 - year / 100 + year / 400) % 7 d_2 = (8-d) % 7 p_3 = (80 + p) % 7 x_2 = d_2 - p_3 x = (x_2 -1) % 7 +1 e = p+x if e < 11 Time.local(year,3,e+21) else Time.local(year,4,e-10) end end |