@Override
 public Temporal adjustInto(Temporal temporal) {
   DayOfWeek dow = DayOfWeek.of(temporal.get(ChronoField.DAY_OF_WEEK));
   int dayToAdd = 1;
   if (dow == DayOfWeek.FRIDAY) dayToAdd = 3;
   if (dow == DayOfWeek.SATURDAY) dayToAdd = 2;
   return temporal.plus(dayToAdd, ChronoUnit.DAYS);
 }
Exemple #2
0
 /**
  * Adds this period to the specified temporal object.
  *
  * <p>This returns a temporal object of the same observable type as the input with this period
  * added.
  *
  * <p>In most cases, it is clearer to reverse the calling pattern by using {@link
  * Temporal#plus(TemporalAmount)}.
  *
  * <pre>
  *   // these two lines are equivalent, but the second approach is recommended
  *   dateTime = thisPeriod.addTo(dateTime);
  *   dateTime = dateTime.plus(thisPeriod);
  * </pre>
  *
  * <p>The calculation will add the years, then months, then days. Only non-zero amounts will be
  * added. If the date-time has a calendar system with a fixed number of months in a year, then the
  * years and months will be combined before being added.
  *
  * <p>This instance is immutable and unaffected by this method call.
  *
  * @param temporal the temporal object to adjust, not null
  * @return an object of the same type with the adjustment made, not null
  * @throws DateTimeException if unable to add
  * @throws ArithmeticException if numeric overflow occurs
  */
 @Override
 public Temporal addTo(Temporal temporal) {
   Objects.requireNonNull(temporal, "temporal");
   if ((years | months) != 0) {
     long monthRange = monthRange(temporal);
     if (monthRange >= 0) {
       temporal = temporal.plus(years * monthRange + months, MONTHS);
     } else {
       if (years != 0) {
         temporal = temporal.plus(years, YEARS);
       }
       if (months != 0) {
         temporal = temporal.plus(months, MONTHS);
       }
     }
   }
   if (days != 0) {
     temporal = temporal.plus(days, DAYS);
   }
   return temporal;
 }