v5.2.1 - There is a known bug with easter_date() that can return incorrect dates for some years:
// 2008 OK
echo date("D d M Y", easter_date(2008)); // Sun 23 Mar 2008
// 2009 returns Saturday
echo date("D d M Y", easter_date(2009)); // Sat 11 Apr 2009
However easter_days() works correctly:
echo date("D d M Y", strtotime("2009-03-21 +".easter_days(2009)." days")); // Sun 12 Apr 2009
It is apparently related to timezone settings.
easter_date
(PHP 4, PHP 5)
easter_date — Restituisce un timestamp Unix della mezzanotte del giorno di Pasqua di un dato anno
Descrizione
Restituisce il timestamp Unix corrispondente alla mezzanotte del giorno di Pasqua dell'anno specificato.
Dal PHP 4.3.0, il parametro anno è opzionale e ha come default l'anno corrente, se omesso.
Example #1 esempio di easter_date()
<?php
echo date("d M Y", easter_date(1999)); // 04 Apr 1999
echo date("d M Y", easter_date(2000)); // 23 Apr 2000
echo date("d M Y", easter_date(2001)); // 15 Apr 2001
?>
Questa funzione gerererà un allarme (warning) se l'anno è fuori dall'escursione di validità dei timestamp UNIX (cioè prima del 1970 o dopo il 2037).
La data della Pasqua fu definita dal Concilio di Nicea nel 325 d.C. come la Domenica successiva alla prima luna piena dopo l'Equinozio di Primavera. Si assume che l'Equinozio cada sempre il 21 Marzo, quindi il calcolo si riduce alla determinazione della data della luna piena e la data della Domenica seguente. L'algoritmo qui usato fu proposto attorno all'anno 532 d.C. da Dionysius Exiguus (Dionigi il Piccolo). Nel Calendario Giuliano (for years before 1753) un semplice ciclo di 19 anni è usato per tracciare le fasi della Luna. Nel Calendario Gregoriano (per gli anni dopo il 1753 - ideato da Clavius e Lilius, e introdotto da Papa Gregorio XIII nell'Ottobre 1582, e in Gran Bretagna e nelle sue colonie nel Settembre 1752) due fattori correttivi sono aggiunti per rendere più accurato il ciclo.
(Il codice è basato su un programma in C di Simon Kershaw, <webmaster at ely.anglican dot org>)
Vedere easter_days() per il calcolo della Pasqua prima del 1970 o dopo il 2037.
easter_date
28-Jan-2008 03:50
I made the function like this ... works fine !
function ostern
{
$maerz21=date('z',mktime(0,0,0,3,21,$jb));
$d=((15 + $jb/100 - $jb/400 - (8 * $jb/100 + 13) / 25)%30 + 19 * ($jb%19))%30;
if ($d==29)
{
$D=28;
}
elseif($d==28 && ($jb%17)>=11)
{
$D=27;
}
else $D=$d;
$e=(2 * ($jb%4) + 4 *($jb%7) + 6 * $D + (6 + $jb/100 - $jb/400 - 2)%7)%7;
$ostersonntag=$e+$D+1+$maerz21;
return $ostersonntag;
}
08-Nov-2004 08:17
The algorithm from Bigtree is correct if you add some (int) cast
<?php
function easter_date ($Year) {
/*
G is the Golden Number-1
H is 23-Epact (modulo 30)
I is the number of days from 21 March to the Paschal full moon
J is the weekday for the Paschal full moon (0=Sunday,
1=Monday, etc.)
L is the number of days from 21 March to the Sunday on or before
the Paschal full moon (a number between -6 and 28)
*/
$G = $Year % 19;
$C = (int)($Year / 100);
$H = (int)($C - (int)($C / 4) - (int)((8*$C+13) / 25) + 19*$G + 15) % 30;
$I = (int)$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;
$E = mktime(0,0,0, $m, $d, $y);
return $E;
}
?>
07-Nov-2004 04:49
The algorithm from BigTree will throw an error in 2021 and 2025. Better to install the PHP functions! Details here:
http://aa.usno.navy.mil/faq/docs/easter.html
17-May-2002 08:41
A much smaller hack is the following. I ported this from a Delphi implementation of a function calculating easter dates.
<?php
function easter_date ($Year) {
/*
G is the Golden Number-1
H is 23-Epact (modulo 30)
I is the number of days from 21 March to the Paschal full moon
J is the weekday for the Paschal full moon (0=Sunday,
1=Monday, etc.)
L is the number of days from 21 March to the Sunday on or before
the Paschal full moon (a number between -6 and 28)
*/
$G = $Year % 19;
$C = (int)($Year / 100);
$H = (int)($C - ($C / 4) - ((8*$C+13) / 25) + 19*$G + 15) % 30;
$I = (int)$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;
$E = mktime(0,0,0, $m, $d, $y);
return $E;
}
?>
