Re: What about Easter?
by CountZero (Bishop) on Jul 24, 2005 at 18:32 UTC
|
Indeed, but only if we also get the functions: jewish_newyear_date, islamic_newyear_date, chinese_newyear_date, eastern_orthodox_easter_date, pre_1583_easter_date and to be totally orthogonal western_newyear_date (I know it is always on January 1st, but we should not let such little issue stop us from being truly multi-cultural and non-western centric.).
CountZero "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] |
Re: What about Easter?
by neniro (Priest) on Jul 24, 2005 at 17:03 UTC
|
| [reply] [Watch: Dir/Any] |
|
print easter_date(2005);
sub easter_date {
my $Year = shift;
$G = $Year % 19;
$C = int($Year / 100);
$H = int($C - ($C / 4) - ((8*$C+13) / 25) + 19*$G + 15) % 30;
+
$I = $H - int($H / 28)*(1 - int($H / 28)*int(29 / ($H + 1))*(
+int(21 - $G) / 11));
$J = ($Year + int($Year/4) + $I + 2 - $C + int($C/4)) % 7;
$L = $I - $J;
$m = 3 + int(($L + 40) / 44);
$d = $L + 28 - 31 * (int($m / 4));
$y = $Year;
return sprintf("%04d-%02d-%02d", $y, $m, $d);
}
| [reply] [Watch: Dir/Any] [d/l] |
|
DON'T USE THIS CODE!
I wrote a quick and dirty compare of the date calculated by this sub against the list in the zip file at Easter Sunday Dates and found it to be 22% inaccurate. Good enough for PHP perhaps? *grin*
Yes I get that the thread was a joke :)
Update: see Re^3: What about Easter? by themage for an updated subroutine which does not produce any erros when compared to the list.
-- Murray Barton Do not seek to follow in the footsteps of the wise. Seek what they sought. -Basho
| [reply] [Watch: Dir/Any] |
|
There is a small error in the PHP version, that pg ported here: <updated, wrong name>.
The line
$H = int($C - ($C / 4) - ((8*$C+13) / 25) + 19*$G + 15) % 30;
Should be:
$H = ($C - int($C / 4) - int((8*$C+13) / 25) + 19*$G + 15) % 30;
The final sub sould look like:
sub easter_date {
my $Year = shift;
my ($G,$C,$H,$I,$J,$L)="0"x6;
$G = $Year % 19;
$C = int($Year / 100);
$H = ($C - int($C / 4) - int((8*$C+13) / 25) + 19*$G + 15) % 30;
$I = $H - int($H / 28)*(1 - int($H / 28)*int(29 / ($H + 1))*(int(21
+- $G) / 11));
$J = ($Year + int($Year/4) + $I + 2 - $C + int($C/4)) % 7;
$L = $I - $J;
my $m = 3 + int(($L + 40) / 44);
my $d = $L + 28 - 31 * (int($m / 4));
my $y = $Year;
return sprintf("%04d-%02d-%02d", $y, $m, $d);
}
This way, I think that it should be ok. What you think greenFox?
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
|
Too SLOW! Must be in CORE!
| [reply] [Watch: Dir/Any] |
|
The slight chuckle that I had after reading the original post was swept away by the shocking realization that someone, somewhere considered this necessary enough to be in the core language. Wow.
| [reply] [Watch: Dir/Any] |
Re: What about Easter?
by bart (Canon) on Jul 24, 2005 at 17:43 UTC
|
You appear not to know how things work with Perl. Stuff that we don't need in every other script is not supposed to go into core perl (except for the stuff that was already in perl4, for example sockets), but into modules on CPAN. In this case, you should take a look at Date::Easter.
There's no need at all to reinstall perl, in order to add this module. | [reply] [Watch: Dir/Any] |
Re: What about Easter?
by jpeg (Chaplain) on Jul 24, 2005 at 22:08 UTC
|
Cue subthread featuring 5 ways to calculate easter_date in Perl6, of which 3 don't work yet, and a post by timtoady explaining that easter_date was considered for perl 5 but voted out, but that they've fixed the situation for perl 6 and you'll like it better.
| [reply] [Watch: Dir/Any] |
|
considered for perl 5 but voted out
Voted?! perl 5? I don't think so.
| [reply] [Watch: Dir/Any] |
Re: What about Easter?
by Anonymous Monk on Jul 25, 2005 at 12:27 UTC
|
Larry has wanted an easter_date function in Perl ever since Perl 3, saying it's a glaring omission from Perl. But as most people will know, the Easter Bunny holds the copyrights and patents on all that's related to Easter. And while the Bunny grants licenses free of charge to almost anybody, it turns out the Easter Bunny is really Guido van Rossum in a fury suit. And he has denied Perl to the right to include an easter_date() function in Perl.
Perl6 will likely to have a Western object, with Western falling either half a year before Easter, or half a year after. You can get the Western date by calling the date function in it (it takes a mandatory year as argument):
print western.date(now.date.year(-digits => 4)).as_string();
Alternatively, there will be a Unicode character for it (one from the 3 upcoming Unicode planes reserved for Perl characters). But there will be a ASCII equivalent, Huffman encoded to 7 characters. Described on page 13,897 of the compact abridged Perl6 pocket reference guide. | [reply] [Watch: Dir/Any] [d/l] |
|
Well, the Easter Bunny's philosophy is: "Free as in eggs, not as in code".
| [reply] [Watch: Dir/Any] |
Re: What about Easter?
by m.att (Pilgrim) on Jul 24, 2005 at 16:47 UTC
|
Okay okay okay, apparently the line between self-deprecating humour and trolling is very fine. This is an attempt at the former. An easter_date() function is madness.
:) | [reply] [Watch: Dir/Any] |