/**
  * @dataProvider provider_samplePlusWeeksSymmetry
  * @group long
  */
 public function test_plusWeeks_symmetry(LocalDateTime $reference)
 {
     for ($weeks = 0; $weeks < 365 * 8; $weeks++) {
         $t = $reference->plusWeeks($weeks)->plusWeeks(-$weeks);
         $this->assertEquals($t, $reference);
         $t = $reference->plusWeeks(-$weeks)->plusWeeks($weeks);
         $this->assertEquals($t, $reference);
     }
 }
Example #2
0
 /**
  * Returns a copy of this OffsetDateTime 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 OffsetDateTime an {@code OffsetDateTime} 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)
 {
     return $this->_with($this->dateTime->plusWeeks($weeks), $this->offset);
 }
Example #3
0
 /**
  * Returns a copy of this {@code ZonedDateTime} with the specified number of weeks added.
  * <p>
  * This operates on the local time-line,
  * {@link LocalDateTime#plusWeeks(long) adding weeks} to the local date-time.
  * This is then converted back to a {@code ZonedDateTime}, using the zone ID
  * to obtain the offset.
  * <p>
  * When converting back to {@code ZonedDateTime}, if the local date-time is in an overlap,
  * then the offset will be retained if possible, otherwise the earlier offset will be used.
  * If in a gap, the local date-time will be adjusted forward by the length of the gap.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param int $weeks the weeks to add, may be negative
  * @return ZonedDateTime a {@code ZonedDateTime} 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)
 {
     return $this->resolveLocal($this->dateTime->plusWeeks($weeks));
 }