note 103180 added to function.checkdate
| From: | phil at lavin dot me dot uk | Date: | Wed, 30 Mar 2011 12:14:58 +0000 |
| Subject: | note 103180 added to function.checkdate | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178338@lists.php.net to get a copy of this message | ||
Holy not-testing... Took me 5 mins to work out the bugs in the code. Would have been easier to
re-write it.
Here's the corrected version of gman's code:
<?php
function is_leap($year = null)
{
if (strpos($year, '+') === 0) {
$chunk = explode('+', $year);
return checkdate(2, 29, date('Y') + $chunk[1]);
}
else {
return checkdate(2, 29, ($year == null) ? date('Y') : $year);
}
}
//Usage
if (is_leap()) {
echo "Current Year is a leap year";
}
if (is_leap(1992)) {
echo "1992 was a leap year";
}
if (is_leap('+4')) {
echo "In four years it will be a leap year";
}
?>
----
Server IP: 109.169.40.147
Probable Submitter: 87.84.128.98
----
Manual Page -- http://www.php.net/manual/en/function.checkdate.php
Edit -- https://master.php.net/note/edit/103180
Del: integrated -- https://master.php.net/note/delete/103180/integrated
Del: useless -- https://master.php.net/note/delete/103180/useless
Del: bad code -- https://master.php.net/note/delete/103180/bad+code
Del: spam -- https://master.php.net/note/delete/103180/spam
Del: non-english -- https://master.php.net/note/delete/103180/non-english
Del: in docs -- https://master.php.net/note/delete/103180/in+docs
Del: other reasons-- https://master.php.net/note/delete/103180
Reject -- https://master.php.net/note/reject/103180
Search -- https://master.php.net/manage/user-notes.php