Java Code Examples for java.time.temporal.Temporal#with()

The following examples show how to use java.time.temporal.Temporal#with() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Schedule.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
/**
 * Wraps an adjuster to round the temporal to the next period if the adjusted time is before
 * the temporal instant.
 *
 * @param amount the amount to add to the adjusted time if before the temporal argument of
 * {@code TemporarlAdjuster#adjustInto()} is after the adjusted time
 * @param adjuster the adjuster to wrap
 * @return an adjuster
 */
private static TemporalAdjuster sameOrNext(final TemporalAmount amount, final TemporalAdjuster adjuster) {
  return new TemporalAdjuster() {

    @Override
    public Temporal adjustInto(Temporal temporal) {
      Temporal adjusted = temporal.with(adjuster);
      return (ChronoUnit.NANOS.between(temporal, adjusted) >= 0)
          ? adjusted
          : temporal.plus(amount).with(adjuster);
      }
  };
}
 
Example 2
Source File: YearMonth.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adjusts the specified temporal object to have this year-month.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the year and month changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#PROLEPTIC_MONTH} as the field.
 * If the specified temporal object does not use the ISO calendar system then
 * a {@code DateTimeException} is thrown.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisYearMonth.adjustInto(temporal);
 *   temporal = temporal.with(thisYearMonth);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
        throw new DateTimeException("Adjustment only supported on ISO date-time");
    }
    return temporal.with(PROLEPTIC_MONTH, getProlepticMonth());
}
 
Example 3
Source File: Year.java    From openjdk-jdk9 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adjusts the specified temporal object to have this year.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the year changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#YEAR} as the field.
 * If the specified temporal object does not use the ISO calendar system then
 * a {@code DateTimeException} is thrown.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisYear.adjustInto(temporal);
 *   temporal = temporal.with(thisYear);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
        throw new DateTimeException("Adjustment only supported on ISO date-time");
    }
    return temporal.with(YEAR, year);
}
 
Example 4
Source File: Year.java    From jdk8u60 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adjusts the specified temporal object to have this year.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the year changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#YEAR} as the field.
 * If the specified temporal object does not use the ISO calendar system then
 * a {@code DateTimeException} is thrown.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisYear.adjustInto(temporal);
 *   temporal = temporal.with(thisYear);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
        throw new DateTimeException("Adjustment only supported on ISO date-time");
    }
    return temporal.with(YEAR, year);
}
 
Example 5
Source File: YearMonth.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adjusts the specified temporal object to have this year-month.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the year and month changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#PROLEPTIC_MONTH} as the field.
 * If the specified temporal object does not use the ISO calendar system then
 * a {@code DateTimeException} is thrown.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisYearMonth.adjustInto(temporal);
 *   temporal = temporal.with(thisYearMonth);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
        throw new DateTimeException("Adjustment only supported on ISO date-time");
    }
    return temporal.with(PROLEPTIC_MONTH, getProlepticMonth());
}
 
Example 6
Source File: YearMonth.java    From desugar_jdk_libs with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adjusts the specified temporal object to have this year-month.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the year and month changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#PROLEPTIC_MONTH} as the field.
 * If the specified temporal object does not use the ISO calendar system then
 * a {@code DateTimeException} is thrown.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisYearMonth.adjustInto(temporal);
 *   temporal = temporal.with(thisYearMonth);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
        throw new DateTimeException("Adjustment only supported on ISO date-time");
    }
    return temporal.with(PROLEPTIC_MONTH, getProlepticMonth());
}
 
Example 7
Source File: MonthDay.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adjusts the specified temporal object to have this month-day.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the month and day-of-month changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * twice, passing {@link ChronoField#MONTH_OF_YEAR} and
 * {@link ChronoField#DAY_OF_MONTH} as the fields.
 * If the specified temporal object does not use the ISO calendar system then
 * a {@code DateTimeException} is thrown.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisMonthDay.adjustInto(temporal);
 *   temporal = temporal.with(thisMonthDay);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
        throw new DateTimeException("Adjustment only supported on ISO date-time");
    }
    temporal = temporal.with(MONTH_OF_YEAR, month);
    return temporal.with(DAY_OF_MONTH, Math.min(temporal.range(DAY_OF_MONTH).getMaximum(), day));
}
 
Example 8
Source File: YearMonth.java    From Bytecoder with Apache License 2.0 3 votes vote down vote up
/**
 * Adjusts the specified temporal object to have this year-month.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the year and month changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#PROLEPTIC_MONTH} as the field.
 * If the specified temporal object does not use the ISO calendar system then
 * a {@code DateTimeException} is thrown.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisYearMonth.adjustInto(temporal);
 *   temporal = temporal.with(thisYearMonth);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
        throw new DateTimeException("Adjustment only supported on ISO date-time");
    }
    return temporal.with(PROLEPTIC_MONTH, getProlepticMonth());
}
 
Example 9
Source File: MonthDay.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adjusts the specified temporal object to have this month-day.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the month and day-of-month changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * twice, passing {@link ChronoField#MONTH_OF_YEAR} and
 * {@link ChronoField#DAY_OF_MONTH} as the fields.
 * If the specified temporal object does not use the ISO calendar system then
 * a {@code DateTimeException} is thrown.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisMonthDay.adjustInto(temporal);
 *   temporal = temporal.with(thisMonthDay);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
        throw new DateTimeException("Adjustment only supported on ISO date-time");
    }
    temporal = temporal.with(MONTH_OF_YEAR, month);
    return temporal.with(DAY_OF_MONTH, Math.min(temporal.range(DAY_OF_MONTH).getMaximum(), day));
}
 
Example 10
Source File: YearMonth.java    From jdk8u_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Adjusts the specified temporal object to have this year-month.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the year and month changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#PROLEPTIC_MONTH} as the field.
 * If the specified temporal object does not use the ISO calendar system then
 * a {@code DateTimeException} is thrown.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisYearMonth.adjustInto(temporal);
 *   temporal = temporal.with(thisYearMonth);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    if (Chronology.from(temporal).equals(IsoChronology.INSTANCE) == false) {
        throw new DateTimeException("Adjustment only supported on ISO date-time");
    }
    return temporal.with(PROLEPTIC_MONTH, getProlepticMonth());
}
 
Example 11
Source File: DateAdjuster.java    From Strata with Apache License 2.0 2 votes vote down vote up
/**
 * Adjusts the temporal according to the rules of the implementation.
 * <p>
 * This method implements {@link TemporalAdjuster} by calling {@link #adjust(LocalDate)}.
 * Note that conversion to {@code LocalDate} ignores the calendar system
 * of the input, which is the desired behaviour in this case.
 * 
 * @param temporal  the temporal to adjust
 * @return the adjusted temporal
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public default Temporal adjustInto(Temporal temporal) {
  // conversion to LocalDate ensures that other calendar systems are ignored
  return temporal.with(adjust(LocalDate.from(temporal)));
}
 
Example 12
Source File: ChronoLocalDate.java    From openjdk-jdk8u with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Adjusts the specified temporal object to have the same date as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the date changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#EPOCH_DAY} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisLocalDate.adjustInto(temporal);
 *   temporal = temporal.with(thisLocalDate);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
default Temporal adjustInto(Temporal temporal) {
    return temporal.with(EPOCH_DAY, toEpochDay());
}
 
Example 13
Source File: Era.java    From j2objc with Apache License 2.0 2 votes vote down vote up
/**
 * Adjusts the specified temporal object to have the same era as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the era changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#ERA} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisEra.adjustInto(temporal);
 *   temporal = temporal.with(thisEra);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
default Temporal adjustInto(Temporal temporal) {
    return temporal.with(ERA, getValue());
}
 
Example 14
Source File: ChronoLocalDate.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Adjusts the specified temporal object to have the same date as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the date changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#EPOCH_DAY} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisLocalDate.adjustInto(temporal);
 *   temporal = temporal.with(thisLocalDate);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
default Temporal adjustInto(Temporal temporal) {
    return temporal.with(EPOCH_DAY, toEpochDay());
}
 
Example 15
Source File: ZoneOffset.java    From jdk8u60 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Adjusts the specified temporal object to have the same offset as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the offset changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#OFFSET_SECONDS} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisOffset.adjustInto(temporal);
 *   temporal = temporal.with(thisOffset);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    return temporal.with(OFFSET_SECONDS, totalSeconds);
}
 
Example 16
Source File: ChronoLocalDate.java    From jdk8u-dev-jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Adjusts the specified temporal object to have the same date as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the date changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#EPOCH_DAY} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisLocalDate.adjustInto(temporal);
 *   temporal = temporal.with(thisLocalDate);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
default Temporal adjustInto(Temporal temporal) {
    return temporal.with(EPOCH_DAY, toEpochDay());
}
 
Example 17
Source File: ZoneOffset.java    From JDKSourceCode1.8 with MIT License 2 votes vote down vote up
/**
 * Adjusts the specified temporal object to have the same offset as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the offset changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#OFFSET_SECONDS} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisOffset.adjustInto(temporal);
 *   temporal = temporal.with(thisOffset);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    return temporal.with(OFFSET_SECONDS, totalSeconds);
}
 
Example 18
Source File: LocalTime.java    From hottub with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Adjusts the specified temporal object to have the same time as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the time changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#NANO_OF_DAY} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisLocalTime.adjustInto(temporal);
 *   temporal = temporal.with(thisLocalTime);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    return temporal.with(NANO_OF_DAY, toNanoOfDay());
}
 
Example 19
Source File: LocalTime.java    From JDKSourceCode1.8 with MIT License 2 votes vote down vote up
/**
 * Adjusts the specified temporal object to have the same time as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the time changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#NANO_OF_DAY} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisLocalTime.adjustInto(temporal);
 *   temporal = temporal.with(thisLocalTime);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Temporal adjustInto(Temporal temporal) {
    return temporal.with(NANO_OF_DAY, toNanoOfDay());
}
 
Example 20
Source File: ChronoLocalDate.java    From JDKSourceCode1.8 with MIT License 2 votes vote down vote up
/**
 * Adjusts the specified temporal object to have the same date as this object.
 * <p>
 * This returns a temporal object of the same observable type as the input
 * with the date changed to be the same as this.
 * <p>
 * The adjustment is equivalent to using {@link Temporal#with(TemporalField, long)}
 * passing {@link ChronoField#EPOCH_DAY} as the field.
 * <p>
 * In most cases, it is clearer to reverse the calling pattern by using
 * {@link Temporal#with(TemporalAdjuster)}:
 * <pre>
 *   // these two lines are equivalent, but the second approach is recommended
 *   temporal = thisLocalDate.adjustInto(temporal);
 *   temporal = temporal.with(thisLocalDate);
 * </pre>
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param temporal  the target object to be adjusted, not null
 * @return the adjusted object, not null
 * @throws DateTimeException if unable to make the adjustment
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
default Temporal adjustInto(Temporal temporal) {
    return temporal.with(EPOCH_DAY, toEpochDay());
}