/** * @param integer $dayOfYear The day-of-year to check, validated as an integer. * @param integer|null $year An optional year to check against, fully validated. * * @return void * * @throws DateTimeException If the day-of-year is not valid. */ public static function check($dayOfYear, $year = null) { if ($dayOfYear < 1 || $dayOfYear > 366) { throw DateTimeException::fieldNotInRange(self::NAME, $dayOfYear, 1, 366); } if ($dayOfYear === 366 && $year !== null) { if (!Year::isLeap($year)) { throw new DateTimeException("Invalid day-of-year 366 as {$year} is not a leap year"); } } }
/** * Returns the length of the given month-of-year. * * If no year is given, the highest value (29) is returned for the month of February. * * @param integer $monthOfYear The month-of-year, fully validated. * @param integer|null $year An optional year the month-of-year belongs to, fully validated. * * @return integer */ public static function getLength($monthOfYear, $year = null) { switch ($monthOfYear) { case 2: return $year === null || Year::isLeap($year) ? 29 : 28; case 4: case 6: case 9: case 11: return 30; default: return 31; } }
/** * Checks if the year is a leap year, according to the ISO proleptic calendar system rules. * * @return boolean */ public function isLeapYear() { return Field\Year::isLeap($this->year); }
/** * Returns whether the given year is valid for this month-day. * * This method checks whether this month and day and the input year form a valid date. * This can only return false for February 29th. * * @param integer $year * * @return boolean */ public function isValidYear($year) { return $this->month !== 2 || $this->day !== 29 || Field\Year::isLeap($year); }