protected function resolveYMD(FieldValues $fieldValues, ResolverStyle $resolverStyle) { $y = $this->range(ChronoField::YEAR())->checkValidIntValue($fieldValues->remove(ChronoField::YEAR()), ChronoField::YEAR()); if ($resolverStyle == ResolverStyle::LENIENT()) { $months = Math::subtractExact($fieldValues->remove(ChronoField::MONTH_OF_YEAR()), 1); $days = Math::subtractExact($fieldValues->remove(ChronoField::DAY_OF_MONTH()), 1); return $this->date($y, 1, 1)->plus($months, ChronoUnit::MONTHS())->plus($days, ChronoUnit::DAYS()); } $moy = $this->range(ChronoField::MONTH_OF_YEAR())->checkValidIntValue($fieldValues->remove(ChronoField::MONTH_OF_YEAR()), ChronoField::MONTH_OF_YEAR()); $domRange = $this->range(ChronoField::DAY_OF_MONTH()); $dom = $domRange->checkValidIntValue($fieldValues->remove(ChronoField::DAY_OF_MONTH()), ChronoField::DAY_OF_MONTH()); if ($resolverStyle == ResolverStyle::SMART()) { // previous valid try { return $this->date($y, $moy, $dom); } catch (DateTimeException $ex) { return $this->date($y, $moy, 1)->adjust(TemporalAdjusters::lastDayOfMonth()); } } return $this->date($y, $moy, $dom); }
public function test_lastDayOfMonth_leap() { foreach (Month::values() as $month) { for ($i = 1; $i <= $month->length(true); $i++) { $date = self::date(2008, $month, $i); $test = TemporalAdjusters::lastDayOfMonth()->adjustInto($date); $this->assertEquals($test->getYear(), 2008); $this->assertEquals($test->getMonth(), $month); $this->assertEquals($test->getDayOfMonth(), $month->length(true)); } } }