Example #1
0
 /**
  * Returns a copy of this {@code OffsetDateTime} with the time truncated.
  * <p>
  * Truncation returns a copy of the original date-time with fields
  * smaller than the specified unit set to zero.
  * For example, truncating with the {@link ChronoUnit#MINUTES minutes} unit
  * will set the second-of-minute and nano-of-second field to zero.
  * <p>
  * The unit must have a {@linkplain TemporalUnit#getDuration() duration}
  * that divides into the length of a standard day without remainder.
  * This includes all supplied time units on {@link ChronoUnit} and
  * {@link ChronoUnit#DAYS DAYS}. Other units throw an exception.
  * <p>
  * The offset does not affect the calculation and will be the same in the result.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param TemporalUnit $unit the unit to truncate to, not null
  * @return OffsetDateTime an {@code OffsetDateTime} based on this date-time with the time truncated, not null
  * @throws DateTimeException if unable to truncate
  * @throws UnsupportedTemporalTypeException if the unit is not supported
  */
 public function truncatedTo(TemporalUnit $unit)
 {
     return $this->_with($this->dateTime->truncatedTo($unit), $this->offset);
 }
Example #2
0
 /**
  * Returns a copy of this {@code ZonedDateTime} with the time truncated.
  * <p>
  * Truncation returns a copy of the original date-time with fields
  * smaller than the specified unit set to zero.
  * For example, truncating with the {@link ChronoUnit#MINUTES minutes} unit
  * will set the second-of-minute and nano-of-second field to zero.
  * <p>
  * The unit must have a {@linkplain TemporalUnit#getDuration() duration}
  * that divides into the length of a standard day without remainder.
  * This includes all supplied time units on {@link ChronoUnit} and
  * {@link ChronoUnit#DAYS DAYS}. Other units throw an exception.
  * <p>
  * This operates on the local time-line,
  * {@link LocalDateTime#truncatedTo(TemporalUnit) truncating}
  * the underlying 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 TemporalUnit $unit the unit to truncate to, not null
  * @return ZonedDateTime a {@code ZonedDateTime} based on this date-time with the time truncated, not null
  * @throws DateTimeException if unable to truncate
  * @throws UnsupportedTemporalTypeException if the unit is not supported
  */
 public function truncatedTo(TemporalUnit $unit)
 {
     return $this->resolveLocal($this->dateTime->truncatedTo($unit));
 }