/** * Returns a copy of this {@code LocalDateTime} with the specified number of weeks added. * <p> * This method adds the specified amount in weeks to the days field incrementing * the month and year fields as necessary to ensure the result remains valid. * The result is only invalid if the maximum/minimum year is exceeded. * <p> * For example, 2008-12-31 plus one week would result in 2009-01-07. * <p> * This instance is immutable and unaffected by this method call. * * @param int $weeks the weeks to add, may be negative * @return LocalDateTime a {@code LocalDateTime} based on this date-time with the weeks added, not null * @throws DateTimeException if the result exceeds the supported date range */ public function plusWeeks($weeks) { $newDate = $this->date->plusWeeks($weeks); return $this->_with($newDate, $this->time); }
/** * @dataProvider data_dayOfWeekInMonth_positive */ public function test_dayOfWeekInMonth_positive($year, $month, DayOfWeek $dow, LocalDate $expected) { for ($ordinal = 1; $ordinal <= 5; $ordinal++) { for ($day = 1; $day <= Month::of($month)->length(false); $day++) { $date = LocalDate::of($year, $month, $day); $test = TemporalAdjusters::dayOfWeekInMonth($ordinal, $dow)->adjustInto($date); $this->assertEquals($test, $expected->plusWeeks($ordinal - 1)); } } }