mirror of
https://github.com/Respect/Validation.git
synced 2026-03-17 15:50:03 +01:00
Most changes was made by php-cs-fixer. Also removes unused `RecursiveTreeIterator` class.
24 lines
548 B
PHP
24 lines
548 B
PHP
<?php
|
|
namespace Respect\Validation\Rules;
|
|
|
|
use DateTime;
|
|
|
|
class LeapYear extends AbstractRule
|
|
{
|
|
public function validate($year)
|
|
{
|
|
if (is_numeric($year)) {
|
|
$year = (int) $year;
|
|
} elseif (is_string($year)) {
|
|
$year = (int) date('Y', strtotime($year));
|
|
} elseif ($year instanceof DateTime) {
|
|
$year = (int) $year->format('Y');
|
|
} else {
|
|
return false;
|
|
}
|
|
|
|
$date = strtotime(sprintf('%d-02-29', $year));
|
|
|
|
return (bool) date('L', $date);
|
|
}
|
|
}
|