misuzu/src/DateCheck.php

28 lines
797 B
PHP

<?php
namespace Misuzu;
final class DateCheck {
public static function isLeapYear(int $year): bool {
return (($year % 4) === 0 && ($year % 100) !== 0)
|| ($year % 400) === 0;
}
// i realise this implementation is probably horribly naive,
// but for what i need it will Do the Job
public static function isValidDate(int $year, int $month, int $day): bool {
if($month < 1 || $month > 12)
return false;
if($day < 1 || $day > 31)
return false;
if($month === 2)
$days = $year === 0 || self::isLeapYear($year) ? 29 : 28;
elseif($month === 4 || $month === 6 || $month === 9 || $month === 11)
$days = 30;
else
$days = 31;
return $day <= $days;
}
}