public function testToString() { $this->assertSame('2013-09', (string) YearMonth::of(2013, 9)); }
/** * @param DateTimeParseResult $result * * @return YearMonth * * @throws DateTimeException If the year-month is not valid. * @throws DateTimeParseException If required fields are missing from the result. */ public static function from(DateTimeParseResult $result) { return YearMonth::of((int) $result->getField(Field\Year::NAME), (int) $result->getField(Field\MonthOfYear::NAME)); }
/** * Resolves the date, resolving days past the end of month. * * @param integer $year The year to represent, validated as an integer from MIN_YEAR to MAX_YEAR. * @param integer $month The month-of-year to represent, validated as an integer from 1 to 12. * @param integer $day The day-of-month to represent, validated as an integer from 1 to 31. * * @return LocalDate */ private function resolvePreviousValid($year, $month, $day) { if ($day > 28) { $day = min($day, YearMonth::of($year, $month)->getLengthOfMonth()); } return new LocalDate($year, $month, $day); }
/** * Combines this year with a month to create a YearMonth. * * @param integer $month The month-of-year to use, from 1 to 12. * * @return YearMonth * * @throws DateTimeException If the month is invalid. */ public function atMonth($month) { return YearMonth::of($this->year, $month); }