Java Code Examples for java.time.temporal.TemporalAdjuster#adjustInto()

The following examples show how to use java.time.temporal.TemporalAdjuster#adjustInto() . 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: ZonedDateTime.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns a {@code ZonedDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = zonedDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
 * thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = zonedDateTime.with(date);
 *  result = zonedDateTime.with(time);
 * </pre>
 * <p>
 * {@link ZoneOffset} also implements {@code TemporalAdjuster} however using it
 * as an argument typically has no effect. The offset of a {@code ZonedDateTime} is
 * controlled primarily by the time-zone. As such, changing the offset does not generally
 * make sense, because there is only one valid offset for the local date-time and zone.
 * If the zoned date-time is in a daylight savings overlap, then the offset is used
 * to switch between the two valid offsets. In all other cases, the offset is ignored.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code ZonedDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public ZonedDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return resolveLocal(LocalDateTime.of((LocalDate) adjuster, dateTime.toLocalTime()));
    } else if (adjuster instanceof LocalTime) {
        return resolveLocal(LocalDateTime.of(dateTime.toLocalDate(), (LocalTime) adjuster));
    } else if (adjuster instanceof LocalDateTime) {
        return resolveLocal((LocalDateTime) adjuster);
    } else if (adjuster instanceof OffsetDateTime) {
        OffsetDateTime odt = (OffsetDateTime) adjuster;
        return ofLocal(odt.toLocalDateTime(), zone, odt.getOffset());
    } else if (adjuster instanceof Instant) {
        Instant instant = (Instant) adjuster;
        return create(instant.getEpochSecond(), instant.getNano(), zone);
    } else if (adjuster instanceof ZoneOffset) {
        return resolveOffset((ZoneOffset) adjuster);
    }
    return (ZonedDateTime) adjuster.adjustInto(this);
}
 
Example 2
Source File: ZonedDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns a {@code ZonedDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = zonedDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
 * thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = zonedDateTime.with(date);
 *  result = zonedDateTime.with(time);
 * </pre>
 * <p>
 * {@link ZoneOffset} also implements {@code TemporalAdjuster} however using it
 * as an argument typically has no effect. The offset of a {@code ZonedDateTime} is
 * controlled primarily by the time-zone. As such, changing the offset does not generally
 * make sense, because there is only one valid offset for the local date-time and zone.
 * If the zoned date-time is in a daylight savings overlap, then the offset is used
 * to switch between the two valid offsets. In all other cases, the offset is ignored.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code ZonedDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public ZonedDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return resolveLocal(LocalDateTime.of((LocalDate) adjuster, dateTime.toLocalTime()));
    } else if (adjuster instanceof LocalTime) {
        return resolveLocal(LocalDateTime.of(dateTime.toLocalDate(), (LocalTime) adjuster));
    } else if (adjuster instanceof LocalDateTime) {
        return resolveLocal((LocalDateTime) adjuster);
    } else if (adjuster instanceof OffsetDateTime) {
        OffsetDateTime odt = (OffsetDateTime) adjuster;
        return ofLocal(odt.toLocalDateTime(), zone, odt.getOffset());
    } else if (adjuster instanceof Instant) {
        Instant instant = (Instant) adjuster;
        return create(instant.getEpochSecond(), instant.getNano(), zone);
    } else if (adjuster instanceof ZoneOffset) {
        return resolveOffset((ZoneOffset) adjuster);
    }
    return (ZonedDateTime) adjuster.adjustInto(this);
}
 
Example 3
Source File: LocalDate.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns an adjusted copy of this date.
 * <p>
 * This returns a {@code LocalDate}, based on this one, with the date adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * <p>
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = localDate.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code LocalDate} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public LocalDate with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return (LocalDate) adjuster;
    }
    return (LocalDate) adjuster.adjustInto(this);
}
 
Example 4
Source File: OffsetTime.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an adjusted copy of this time.
 * <p>
 * This returns an {@code OffsetTime}, based on this one, with the time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the hour field.
 * A more complex adjuster might set the time to the last hour of the day.
 * <p>
 * The classes {@link LocalTime} and {@link ZoneOffset} implement {@code TemporalAdjuster},
 * thus this method can be used to change the time or offset:
 * <pre>
 *  result = offsetTime.with(time);
 *  result = offsetTime.with(offset);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code OffsetTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public OffsetTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalTime) {
        return with((LocalTime) adjuster, offset);
    } else if (adjuster instanceof ZoneOffset) {
        return with(time, (ZoneOffset) adjuster);
    } else if (adjuster instanceof OffsetTime) {
        return (OffsetTime) adjuster;
    }
    return (OffsetTime) adjuster.adjustInto(this);
}
 
Example 5
Source File: OffsetDateTime.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns an {@code OffsetDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = offsetDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate}, {@link LocalTime} and {@link ZoneOffset} implement
 * {@code TemporalAdjuster}, thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = offsetDateTime.with(date);
 *  result = offsetDateTime.with(time);
 *  result = offsetDateTime.with(offset);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code OffsetDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public OffsetDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate || adjuster instanceof LocalTime || adjuster instanceof LocalDateTime) {
        return with(dateTime.with(adjuster), offset);
    } else if (adjuster instanceof Instant) {
        return ofInstant((Instant) adjuster, offset);
    } else if (adjuster instanceof ZoneOffset) {
        return with(dateTime, (ZoneOffset) adjuster);
    } else if (adjuster instanceof OffsetDateTime) {
        return (OffsetDateTime) adjuster;
    }
    return (OffsetDateTime) adjuster.adjustInto(this);
}
 
Example 6
Source File: LocalTime.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an adjusted copy of this time.
 * <p>
 * This returns a {@code LocalTime}, based on this one, with the time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the hour field.
 * A more complex adjuster might set the time to the last hour of the day.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code LocalTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public LocalTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalTime) {
        return (LocalTime) adjuster;
    }
    return (LocalTime) adjuster.adjustInto(this);
}
 
Example 7
Source File: LocalDate.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an adjusted copy of this date.
 * <p>
 * This returns a {@code LocalDate}, based on this one, with the date adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * <p>
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = localDate.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code LocalDate} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public LocalDate with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return (LocalDate) adjuster;
    }
    return (LocalDate) adjuster.adjustInto(this);
}
 
Example 8
Source File: LocalDateTime.java    From jdk1.8-source-analysis with Apache License 2.0 3 votes vote down vote up
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns a {@code LocalDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * <p>
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = localDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
 * thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = localDateTime.with(date);
 *  result = localDateTime.with(time);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code LocalDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public LocalDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return with((LocalDate) adjuster, time);
    } else if (adjuster instanceof LocalTime) {
        return with(date, (LocalTime) adjuster);
    } else if (adjuster instanceof LocalDateTime) {
        return (LocalDateTime) adjuster;
    }
    return (LocalDateTime) adjuster.adjustInto(this);
}
 
Example 9
Source File: LocalDateTime.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns a {@code LocalDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * <p>
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = localDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
 * thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = localDateTime.with(date);
 *  result = localDateTime.with(time);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code LocalDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public LocalDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return with((LocalDate) adjuster, time);
    } else if (adjuster instanceof LocalTime) {
        return with(date, (LocalTime) adjuster);
    } else if (adjuster instanceof LocalDateTime) {
        return (LocalDateTime) adjuster;
    }
    return (LocalDateTime) adjuster.adjustInto(this);
}
 
Example 10
Source File: OffsetTime.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns an adjusted copy of this time.
 * <p>
 * This returns an {@code OffsetTime}, based on this one, with the time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the hour field.
 * A more complex adjuster might set the time to the last hour of the day.
 * <p>
 * The classes {@link LocalTime} and {@link ZoneOffset} implement {@code TemporalAdjuster},
 * thus this method can be used to change the time or offset:
 * <pre>
 *  result = offsetTime.with(time);
 *  result = offsetTime.with(offset);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code OffsetTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public OffsetTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalTime) {
        return with((LocalTime) adjuster, offset);
    } else if (adjuster instanceof ZoneOffset) {
        return with(time, (ZoneOffset) adjuster);
    } else if (adjuster instanceof OffsetTime) {
        return (OffsetTime) adjuster;
    }
    return (OffsetTime) adjuster.adjustInto(this);
}
 
Example 11
Source File: OffsetDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns an {@code OffsetDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = offsetDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate}, {@link LocalTime} and {@link ZoneOffset} implement
 * {@code TemporalAdjuster}, thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = offsetDateTime.with(date);
 *  result = offsetDateTime.with(time);
 *  result = offsetDateTime.with(offset);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code OffsetDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public OffsetDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate || adjuster instanceof LocalTime || adjuster instanceof LocalDateTime) {
        return with(dateTime.with(adjuster), offset);
    } else if (adjuster instanceof Instant) {
        return ofInstant((Instant) adjuster, offset);
    } else if (adjuster instanceof ZoneOffset) {
        return with(dateTime, (ZoneOffset) adjuster);
    } else if (adjuster instanceof OffsetDateTime) {
        return (OffsetDateTime) adjuster;
    }
    return (OffsetDateTime) adjuster.adjustInto(this);
}
 
Example 12
Source File: OffsetDateTime.java    From TencentKona-8 with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns an {@code OffsetDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = offsetDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate}, {@link LocalTime} and {@link ZoneOffset} implement
 * {@code TemporalAdjuster}, thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = offsetDateTime.with(date);
 *  result = offsetDateTime.with(time);
 *  result = offsetDateTime.with(offset);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code OffsetDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public OffsetDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate || adjuster instanceof LocalTime || adjuster instanceof LocalDateTime) {
        return with(dateTime.with(adjuster), offset);
    } else if (adjuster instanceof Instant) {
        return ofInstant((Instant) adjuster, offset);
    } else if (adjuster instanceof ZoneOffset) {
        return with(dateTime, (ZoneOffset) adjuster);
    } else if (adjuster instanceof OffsetDateTime) {
        return (OffsetDateTime) adjuster;
    }
    return (OffsetDateTime) adjuster.adjustInto(this);
}
 
Example 13
Source File: LocalDateTime.java    From dragonwell8_jdk with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Returns an adjusted copy of this date-time.
 * <p>
 * This returns a {@code LocalDateTime}, based on this one, with the date-time adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the date to the last day of the month.
 * <p>
 * A selection of common adjustments is provided in
 * {@link java.time.temporal.TemporalAdjusters TemporalAdjusters}.
 * These include finding the "last day of the month" and "next Wednesday".
 * Key date-time classes also implement the {@code TemporalAdjuster} interface,
 * such as {@link Month} and {@link java.time.MonthDay MonthDay}.
 * The adjuster is responsible for handling special cases, such as the varying
 * lengths of month and leap years.
 * <p>
 * For example this code returns a date on the last day of July:
 * <pre>
 *  import static java.time.Month.*;
 *  import static java.time.temporal.TemporalAdjusters.*;
 *
 *  result = localDateTime.with(JULY).with(lastDayOfMonth());
 * </pre>
 * <p>
 * The classes {@link LocalDate} and {@link LocalTime} implement {@code TemporalAdjuster},
 * thus this method can be used to change the date, time or offset:
 * <pre>
 *  result = localDateTime.with(date);
 *  result = localDateTime.with(time);
 * </pre>
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code LocalDateTime} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public LocalDateTime with(TemporalAdjuster adjuster) {
    // optimizations
    if (adjuster instanceof LocalDate) {
        return with((LocalDate) adjuster, time);
    } else if (adjuster instanceof LocalTime) {
        return with(date, (LocalTime) adjuster);
    } else if (adjuster instanceof LocalDateTime) {
        return (LocalDateTime) adjuster;
    }
    return (LocalDateTime) adjuster.adjustInto(this);
}
 
Example 14
Source File: YearMonth.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an adjusted copy of this year-month.
 * <p>
 * This returns a {@code YearMonth}, based on this one, with the year-month adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the year-month to the next month that
 * Halley's comet will pass the Earth.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code YearMonth} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public YearMonth with(TemporalAdjuster adjuster) {
    return (YearMonth) adjuster.adjustInto(this);
}
 
Example 15
Source File: Year.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an adjusted copy of this year.
 * <p>
 * This returns a {@code Year}, based on this one, with the year adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code Year} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalAdjuster adjuster) {
    return (Year) adjuster.adjustInto(this);
}
 
Example 16
Source File: Instant.java    From TencentKona-8 with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an adjusted copy of this instant.
 * <p>
 * This returns an {@code Instant}, based on this one, with the instant adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code Instant} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Instant with(TemporalAdjuster adjuster) {
    return (Instant) adjuster.adjustInto(this);
}
 
Example 17
Source File: Instant.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an adjusted copy of this instant.
 * <p>
 * This returns an {@code Instant}, based on this one, with the instant adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code Instant} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Instant with(TemporalAdjuster adjuster) {
    return (Instant) adjuster.adjustInto(this);
}
 
Example 18
Source File: YearMonth.java    From dragonwell8_jdk with GNU General Public License v2.0 2 votes vote down vote up
/**
 * Returns an adjusted copy of this year-month.
 * <p>
 * This returns a {@code YearMonth}, based on this one, with the year-month adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * A simple adjuster might simply set the one of the fields, such as the year field.
 * A more complex adjuster might set the year-month to the next month that
 * Halley's comet will pass the Earth.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code YearMonth} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public YearMonth with(TemporalAdjuster adjuster) {
    return (YearMonth) adjuster.adjustInto(this);
}
 
Example 19
Source File: Year.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an adjusted copy of this year.
 * <p>
 * This returns a {@code Year}, based on this one, with the year adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return a {@code Year} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Year with(TemporalAdjuster adjuster) {
    return (Year) adjuster.adjustInto(this);
}
 
Example 20
Source File: Instant.java    From jdk1.8-source-analysis with Apache License 2.0 2 votes vote down vote up
/**
 * Returns an adjusted copy of this instant.
 * <p>
 * This returns an {@code Instant}, based on this one, with the instant adjusted.
 * The adjustment takes place using the specified adjuster strategy object.
 * Read the documentation of the adjuster to understand what adjustment will be made.
 * <p>
 * The result of this method is obtained by invoking the
 * {@link TemporalAdjuster#adjustInto(Temporal)} method on the
 * specified adjuster passing {@code this} as the argument.
 * <p>
 * This instance is immutable and unaffected by this method call.
 *
 * @param adjuster the adjuster to use, not null
 * @return an {@code Instant} based on {@code this} with the adjustment made, not null
 * @throws DateTimeException if the adjustment cannot be made
 * @throws ArithmeticException if numeric overflow occurs
 */
@Override
public Instant with(TemporalAdjuster adjuster) {
    return (Instant) adjuster.adjustInto(this);
}