コード例 #1
0
 public function test_until_gap()
 {
     $before = $this->TEST_PARIS_GAP_2008_03_30_02_30->withHour(0)->withMinute(0)->atZone(self::ZONE_PARIS());
     $after = $this->TEST_PARIS_GAP_2008_03_30_02_30->withHour(0)->withMinute(0)->plusDays(1)->atZone(self::ZONE_PARIS());
     $this->assertEquals($before->until($after, CU::HOURS()), 23);
     $this->assertEquals($before->until($after, CU::DAYS()), 1);
 }
コード例 #2
0
 /**
  * Returns a copy of this {@code OffsetDateTime} with the hour-of-day altered.
  * <p>
  * The date and offset do not affect the calculation and will be the same in the result.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param int $hour the hour-of-day to set in the result, from 0 to 23
  * @return OffsetDateTime an {@code OffsetDateTime} based on this date-time with the requested hour, not null
  * @throws DateTimeException if the hour value is invalid
  */
 public function withHour($hour)
 {
     return $this->_with($this->dateTime->withHour($hour), $this->offset);
 }
コード例 #3
0
 /**
  * Returns a copy of this {@code ZonedDateTime} with the hour-of-day altered.
  * <p>
  * This operates on the local time-line,
  * {@linkplain LocalDateTime#withHour(int) changing the time} of 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 $hour the hour-of-day to set in the result, from 0 to 23
  * @return ZonedDateTime a {@code ZonedDateTime} based on this date-time with the requested hour, not null
  * @throws DateTimeException if the hour value is invalid
  */
 public function withHour($hour)
 {
     return $this->resolveLocal($this->dateTime->withHour($hour));
 }