Example usage for java.time.temporal Temporal with

List of usage examples for java.time.temporal Temporal with

Introduction

In this page you can find the example usage for java.time.temporal Temporal with.

Prototype

Temporal with(TemporalField field, long newValue);

Source Link

Document

Returns an object of the same type as this object with the specified field altered.

Usage

From source file:org.silverpeas.core.calendar.Recurrence.java

private Temporal computeDateForMonthlyFrequencyFrom(final Temporal source, DayOfWeekOccurrence dayOfWeek) {
    Temporal current = source;
    if (dayOfWeek.nth() > 1) {
        current = current.with(ChronoField.ALIGNED_WEEK_OF_MONTH, dayOfWeek.nth());
    } else if (dayOfWeek.nth() < 0) {
        current = current.with(ChronoField.DAY_OF_MONTH, 1).plus(1, ChronoUnit.MONTHS).minus(1, ChronoUnit.DAYS)
                .plus(dayOfWeek.nth(), ChronoUnit.WEEKS).with(dayOfWeek.dayOfWeek());
    }/*from   w  ww  .java 2s.  c o m*/
    return current;
}

From source file:org.silverpeas.core.calendar.Recurrence.java

private Temporal computeDateForYearlyFrequencyFrom(final Temporal source, DayOfWeekOccurrence dayOfWeek) {
    final int lastDayOfYear = 31;
    Temporal current = source;
    if (dayOfWeek.nth() > 1) {
        current = current.with(ChronoField.ALIGNED_WEEK_OF_YEAR, dayOfWeek.nth());
    } else if (dayOfWeek.nth() < 0) {
        current = current.with(MonthDay.of(Month.DECEMBER, lastDayOfYear))
                .plus(dayOfWeek.nth(), ChronoUnit.WEEKS).with(dayOfWeek.dayOfWeek());
    }//from   w ww  .j  a v a 2  s . co m
    return current;
}