note 108521 added to function.easter-date
| From: | luca at musician dot org | Date: | Thu, 03 May 2012 15:19:03 +0000 |
| Subject: | note 108521 added to function.easter-date | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-187457@lists.php.net to get a copy of this message | ||
Due to range limitations of core functions such as easter_date(), mktime(), strtotime(), I wrote
this function to get the Easter Day in string format yyyy-mm-dd.
function myEaster($year)
{
/*Warning: easter_date(): This function is only valid for years between 1970 and 2037
* The easter_days() function can be used instead of easter_date() to calculate Easter for years
which fall outside the range.
*/
//The next line would do the work if there were no limitations:
//return date("Y-m-d",easter_date($year));
/*Outside range (1970,2037) they advise to use easter_days().
* Unfortunately, when you have to create a date object as 21-03-yyyy to which add
easter_days(), then obtain Easter,
* functions like strtotime(), DateTime::createFromFormat() will fail. (return value is
01-01-1970)
*/
$march21=date("$year-03-21");
$days=easter_days($year);
if($year<=2037)
//The next line would do the work if strtotime() wasn't affected by same limitations. But,
the if..else is required to handle all years.
$date = date("Y-m-d",strtotime(date("Y-m-d", strtotime($march21)) .
" +$days day"));
else
{
if($days<=10){
$day=str_pad(21+$days, 2, '0', STR_PAD_LEFT);
$date=date("$year-03-$day");
}
else
{
$day=str_pad($days-10, 2, '0', STR_PAD_LEFT);
$date=date("$year-04-$day");
}
}
return $date;
}
----
Server IP: 69.147.83.197
Probable Submitter: 213.82.29.9
----
Manual Page -- http://www.php.net/manual/en/function.easter-date.php
Edit -- https://master.php.net/note/edit/108521
Del: integrated -- https://master.php.net/note/delete/108521/integrated
Del: useless -- https://master.php.net/note/delete/108521/useless
Del: bad code -- https://master.php.net/note/delete/108521/bad+code
Del: spam -- https://master.php.net/note/delete/108521/spam
Del: non-english -- https://master.php.net/note/delete/108521/non-english
Del: in docs -- https://master.php.net/note/delete/108521/in+docs
Del: other reasons-- https://master.php.net/note/delete/108521
Reject -- https://master.php.net/note/reject/108521
Search -- https://master.php.net/manage/user-notes.php