/** * Returns a copy of this {@code MonthDay} with the month-of-year altered. * <p> * This returns a month-day with the specified month. * If the day-of-month is invalid for the specified month, the day will * be adjusted to the last valid day-of-month. * <p> * This instance is immutable and unaffected by this method call. * * @param Month $month the month-of-year to set in the returned month-day, not null * @return MonthDay a {@code MonthDay} based on this month-day with the requested month, not null */ public function with(Month $month) { if ($month->getValue() == $this->month) { return $this; } $day = Math::min($this->day, $month->maxLength()); return new MonthDay($month->getValue(), $day); }
/** * Obtains an instance of {@code LocalDate} from a year, month and day. * <p> * This returns a {@code LocalDate} with the specified year, month and day-of-month. * The day must be valid for the year and month, otherwise an exception will be thrown. * * @param int $year the year to represent, from MIN_YEAR to MAX_YEAR * @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 LocalDate the local date, 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-year */ public static function ofMonth($year, Month $month, $dayOfMonth) { ChronoField::YEAR()->checkValidValue($year); ChronoField::DAY_OF_MONTH()->checkValidValue($dayOfMonth); return self::create($year, $month->getValue(), $dayOfMonth); }
/** * Obtains an instance of {@code YearMonth} from a year and month. * * @param int $year the year to represent, from MIN_YEAR to MAX_YEAR * @param Month $month the month-of-year to represent, not null * @return YearMonth the year-month, not null * @throws DateTimeException if the year value is invalid */ public static function ofMonth($year, Month $month) { return self::of($year, $month->getValue()); }