[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Proposal: Yet another Date method

Bertram Scharpf

4/8/2007 1:05:00 PM

Hi,

I would like the Date class to be extended by this:

require "date"

class Date
class <<self
def easter_western year
# This is after Donald E. Knuth and it works for both
# Julian (before 1583) and Gregorian (after 1582) calendars.
g = year%19 + 1 # golden number
c = year/100 + 1 # century
x = (3*c/4) - 12 # corrections
z = (8*c+5)/25 - 5
d = 5*year/4 - x - 10 # March((-d)%7)th is Sunday
e = (11*g + 20 + z - x) % 30 # moon phase
e += 1 if e == 25 and g > 11 or e == 24
n = 44 - e # full moon
n += 30 if n < 21
month = 3
day = n+7 - (d+n)%7
if day > 31 then
month += 1
day -= 31
end
civil year, month, day
end
alias easter easter_western
end
end

I tested it with all easter date tables I found on the web
in German, English and French.

Happy Easter!

Bertram


--
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-...

3 Answers

Christian Neukirchen

4/8/2007 4:36:00 PM

0

Bertram Scharpf <lists@bertram-scharpf.de> writes:

> Hi,
>
> I would like the Date class to be extended by this:

cf. ruby-1.8.6/sample/goodfriday.rb

> Happy Easter!
>
> Bertram
--
Christian Neukirchen <chneukirchen@gmail.com> http://chneuk...

Servando Garcia

4/8/2007 8:00:00 PM

0

If we are taking a vote on this I vote YES
On Sun, 2007-04-08 at 22:05 +0900, Bertram Scharpf wrote:
> Hi,
>
> I would like the Date class to be extended by this:
>
> require "date"
>
> class Date
> class <<self
> def easter_western year
> # This is after Donald E. Knuth and it works for both
> # Julian (before 1583) and Gregorian (after 1582) calendars.
> g = year%19 + 1 # golden number
> c = year/100 + 1 # century
> x = (3*c/4) - 12 # corrections
> z = (8*c+5)/25 - 5
> d = 5*year/4 - x - 10 # March((-d)%7)th is Sunday
> e = (11*g + 20 + z - x) % 30 # moon phase
> e += 1 if e == 25 and g > 11 or e == 24
> n = 44 - e # full moon
> n += 30 if n < 21
> month = 3
> day = n+7 - (d+n)%7
> if day > 31 then
> month += 1
> day -= 31
> end
> civil year, month, day
> end
> alias easter easter_western
> end
> end
>
> I tested it with all easter date tables I found on the web
> in German, English and French.
>
> Happy Easter!
>
> Bertram
>
>


Jeremy McAnally

4/9/2007 2:44:00 AM

0

I wrote something that tests for Easter, Christmas, 4th of July, and
so on wrapped into a method called "is_national_holiday?" that I
planned on releasing as a gem, but I never did...I still have it if
you actually need something that doees this.

--Jeremy

On 4/8/07, Bertram Scharpf <lists@bertram-scharpf.de> wrote:
> Hi,
>
> I would like the Date class to be extended by this:
>
> require "date"
>
> class Date
> class <<self
> def easter_western year
> # This is after Donald E. Knuth and it works for both
> # Julian (before 1583) and Gregorian (after 1582) calendars.
> g = year%19 + 1 # golden number
> c = year/100 + 1 # century
> x = (3*c/4) - 12 # corrections
> z = (8*c+5)/25 - 5
> d = 5*year/4 - x - 10 # March((-d)%7)th is Sunday
> e = (11*g + 20 + z - x) % 30 # moon phase
> e += 1 if e == 25 and g > 11 or e == 24
> n = 44 - e # full moon
> n += 30 if n < 21
> month = 3
> day = n+7 - (d+n)%7
> if day > 31 then
> month += 1
> day -= 31
> end
> civil year, month, day
> end
> alias easter easter_western
> end
> end
>
> I tested it with all easter date tables I found on the web
> in German, English and French.
>
> Happy Easter!
>
> Bertram
>
>
> --
> Bertram Scharpf
> Stuttgart, Deutschland/Germany
> http://www.bertram-...
>
>


--
http://www.jeremymca...

My free Ruby e-book:
http://www.humblelittlerubybook...

My blogs:
http://www.mrneigh...
http://www.rubyinpra...