/** * @dataProvider provider_samplePlusDaysSymmetry * @group long */ public function test_plusDays_symmetry(LocalDateTime $reference) { for ($days = 0; $days < 365 * 8; $days++) { $t = $reference->plusDays($days)->plusDays(-$days); $this->assertEquals($t, $reference); $t = $reference->plusDays(-$days)->plusDays($days); $this->assertEquals($t, $reference); } }
/** * Returns a copy of this OffsetDateTime with the specified number of days added. * <p> * This method adds the specified amount 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 day would result in 2009-01-01. * <p> * This instance is immutable and unaffected by this method call. * * @param int $days the days to add, may be negative * @return OffsetDateTime an {@code OffsetDateTime} based on this date-time with the days added, not null * @throws DateTimeException if the result exceeds the supported date range */ public function plusDays($days) { return $this->_with($this->dateTime->plusDays($days), $this->offset); }
/** * Returns a copy of this {@code ZonedDateTime} with the specified number of days added. * <p> * This operates on the local time-line, * {@link LocalDateTime#plusDays(long) adding days} 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 $days the days to add, may be negative * @return ZonedDateTime a {@code ZonedDateTime} based on this date-time with the days added, not null * @throws DateTimeException if the result exceeds the supported date range */ public function plusDays($days) { return $this->resolveLocal($this->dateTime->plusDays($days)); }