/** * Obtains an instance of {@code MonthDay}. * <p> * The day-of-month must be valid for the month within a leap year. * Hence, for February, day 29 is valid. * <p> * For example, passing in April and day 31 will throw an exception, as * there can never be April 31st in any year. By contrast, passing in * February 29th is permitted, as that month-day can sometimes be valid. * * @param Month $month the month-of-year to represent, not null * @param int $dayOfMonth the day-of-month to represent, from 1 to 31 * @return MonthDay the month-day, not null * @throws DateTimeException if the value of any field is out of range, * or if the day-of-month is invalid for the month */ public static function ofMonth(Month $month, $dayOfMonth) { ChronoField::DAY_OF_MONTH()->checkValidValue($dayOfMonth); if ($dayOfMonth > $month->maxLength()) { throw new DateTimeException("Illegal value for DayOfMonth field, value " . $dayOfMonth . " is not valid for month " . $month->name()); } return new MonthDay($month->getValue(), $dayOfMonth); }