Adds the period to the instant, specifying the number of times to add.

@param period  the period to add, null means add nothing
@param instant  the instant to add to
@param scalar  the number of times to add
@return the updated instant
348872
public long add(ReadablePeriod period, long instant, int scalar) {
        if (scalar != 0 && period != null) {
            for (int i = 0, isize = period.size(); i < isize; i++) {
                long value = period.getValue(i); // use long to allow for multiplication (fits OK)
                if (value != 0) {
                    instant = period.getFieldType(i).getField(this).add(instant, value * scalar);
                }
            }
        }
        return instant;
    }
1304253
private List<PeriodAssociative<T>> _Merge( List<PeriodAssociative<T>> periods, AddFunction<T> addFunction )
	{
		int count = periods.size();
		if( count == 0 )
			return new ArrayList<PeriodAssociative<T>>();
		if( count == 1 )
			return periods;

		List<PeriodAssociative<T>> result = new ArrayList<PeriodAssociative<T>>();

		while( periods.size() > 1 )
		{
			if( periods.get( 1 ).getFrom().compareTo( periods.get( 0 ).getTo() ) > 0 )
			{
				// period is disjointed, so forget the first period, add it
				// directly into the results
				result.add( periods.remove( 0 ) );
			}
			else
			{
				List<PeriodAssociative<T>> toAdd = new ArrayList<PeriodAssociative<T>>();

				if( periods.get( 0 ).getFrom().compareTo( periods.get( 1 ).getFrom() ) < 0 )
				{
					PeriodAssociative<T> created = new PeriodAssociative<T>( periods.get( 0 ).getFrom(), CalendarFunctions.date_add_day( periods.get( 1 ).getFrom(), -1 ), periods.get( 0 ).getValue() );
					toAdd.add( created );
				}

				if( periods.get( 1 ).getTo().compareTo( periods.get( 0 ).getTo() ) < 0 )
				{
					T r = addFunction.function( periods.get( 0 ).getValue(), periods.get( 1 ).getValue() );
					if( r == null )
						return null;

					toAdd.add( new PeriodAssociative<T>( periods.get( 1 ).getFrom(), periods.get( 1 ).getTo(), r ) );
					toAdd.add( new PeriodAssociative<T>( CalendarFunctions.date_add_day( periods.get( 1 ).getTo(), 1 ), periods.get( 0 ).getTo(), periods.get( 0 ).getValue() ) );
				}
				else if( periods.get( 1 ).getTo().equals( periods.get( 0 ).getTo() ) )
				{
					T r = addFunction.function( periods.get( 0 ).getValue(), periods.get( 1 ).getValue() );
					if( r == null )
						return null;

					toAdd.add( new PeriodAssociative<T>( periods.get( 1 ).getFrom(), periods.get( 1 ).getTo(), r ) );
				}
				else
				// $periods[1][1] > $periods[0][1]
				{
					T r = addFunction.function( periods.get( 0 ).getValue(), periods.get( 1 ).getValue() );
					if( r == null )
						return null;

					toAdd.add( new PeriodAssociative<T>( periods.get( 1 ).getFrom(), periods.get( 0 ).getTo(), r ) );
					toAdd.add( new PeriodAssociative<T>( CalendarFunctions.date_add_day( periods.get( 0 ).getTo(), 1 ), periods.get( 1 ).getTo(), periods.get( 1 ).getValue() ) );
				}

				// periods 0 and 1 should be replaced by the newly calculated
				// $toAdd periods

				// remove periods 0 and 1
				periods.remove( 0 );
				periods.remove( 0 );

				periods = _Combine( periods, toAdd );
			}
		}

		if( periods.size() > 0 )
			result.add( periods.remove( 0 ) );

		return result;
	}
492806
@Override
    public void setUpdatePeriod(final String updatePeriod) {
        if (!PERIODS.contains(updatePeriod)) {
            throw new IllegalArgumentException("Invalid period [" + updatePeriod + "]");
        }
        this.updatePeriod = updatePeriod;
    }
1229558
public PeriodList calculateRecurrenceSet(final Period period) {
        PeriodList periods = new PeriodList();

        for (Component component : getRevisions()) {
            periods = periods.add(component.calculateRecurrenceSet(period));
        }

        return periods;
    }
356710
def initialize_period(self, period=None):
        
        if not period:
            self.current_period = dt.datetime.now()
        else:
            self.current_period = period
        self.current_period = dt.datetime(self.current_period.year, self.current_period.month, self.current_period.day)
        self.date = self.current_period.strftime("%Y-%m-%d")
219130
public void add(ReadableDuration duration) {
        if (duration != null) {
            add(new Period(duration.getMillis(), getPeriodType()));
        }
    }
1061595
public static Period moreThan(float count, TimeUnit unit) {
    checkCount(count);
    return new Period(ETimeLimit.MT, false, count, unit);
  }
1206316
public long add(long instant, long months) {
        int i_months = (int)months;
        if (i_months == months) {
            return add(instant, i_months);
        }

        // Copied from add(long, int) and modified slightly:

        long timePart = iChronology.getMillisOfDay(instant);

        int thisYear = iChronology.getYear(instant);
        int thisMonth = iChronology.getMonthOfYear(instant, thisYear);

        long yearToUse;
        long monthToUse = thisMonth - 1 + months;
        if (monthToUse >= 0) {
            yearToUse = thisYear + (monthToUse / iMax);
            monthToUse = (monthToUse % iMax) + 1;
        } else {
            yearToUse = thisYear + (monthToUse / iMax) - 1;
            monthToUse = Math.abs(monthToUse);
            int remMonthToUse = (int)(monthToUse % iMax);
            if (remMonthToUse == 0) {
                remMonthToUse = iMax;
            }
            monthToUse = iMax - remMonthToUse + 1;
            if (monthToUse == 1) {
                yearToUse += 1;
            }
        }

        if (yearToUse < iChronology.getMinYear() ||
            yearToUse > iChronology.getMaxYear()) {

            throw new IllegalArgumentException
                ("Magnitude of add amount is too large: " + months);
        }

        int i_yearToUse = (int)yearToUse;
        int i_monthToUse = (int)monthToUse;

        int dayToUse = iChronology.getDayOfMonth(instant, thisYear, thisMonth);
        int maxDay = iChronology.getDaysInYearMonth(i_yearToUse, i_monthToUse);
        if (dayToUse > maxDay) {
            dayToUse = maxDay;
        }

        long datePart =
            iChronology.getYearMonthDayMillis(i_yearToUse, i_monthToUse, dayToUse);
        return datePart + timePart;
    }
1164576
public long subtract(long instant, int value) {
        if (value == Integer.MIN_VALUE) {
            return subtract(instant, (long) value);
        }
        return add(instant, -value);
    }
1139867
public static Interval minus(final Interval interval, final Period period) {
    return new Interval(interval.getStart().minus(period),
        interval.getEnd().minus(period));
  }
142731
@Override
  public DurationFormatterFactory setPeriodBuilder(PeriodBuilder builder) {
    if (builder != this.builder) {
      this.builder = builder;
      reset();
    }
    return this;
  }
1071343
public long set(long instant, int value) {
        FieldUtils.verifyValueBounds
            (this, value, getMinimumValue(instant), getMaximumValue(instant));
        return super.set(instant, value);
    }
602616
@Override
  public DurationFormatterFactory setPeriodFormatter(
      PeriodFormatter formatter) {
    if (formatter != this.formatter) {
      this.formatter = formatter;
      reset();
    }
    return this;
  }
708630
static public DateTimePeriod create(DateTimeDuration duration, DateTime start) {
        if (duration == DateTimeDuration.YEAR) {
            return createYear(start);
        } else if (duration == DateTimeDuration.MONTH) {
            return createMonth(start);
        } else if (duration == DateTimeDuration.DAY) {
            return createDay(start);
        } else if (duration == DateTimeDuration.HOUR) {
            return createHour(start);
        } else if (duration == DateTimeDuration.FIVE_MINUTES) {
            return createFiveMinutes(start);
        } else {
            throw new UnsupportedOperationException("Duration " + duration + " not yet supported");
        }
    }
614878
public long set(long instant, int era) {
        FieldUtils.verifyValueBounds(this, era, DateTimeConstants.BCE, DateTimeConstants.CE);
            
        int oldEra = get(instant);
        if (oldEra != era) {
            int year = iChronology.getYear(instant);
            return iChronology.setYear(instant, -year);
        } else {
            return instant;
        }
    }
538644
public RandomVariableInterface accrue(RandomVariableInterface rate, double periodLength) {
		// Set time of this random variable to maximum of time with respect to which measurability is known.
		double newTime = Math.max(time, rate.getFiltrationTime());

		if(isDeterministic() && rate.isDeterministic()) {
			double newValueIfNonStochastic = valueIfNonStochastic * (1 + rate.get(0) * periodLength);
			return new RandomVariableLowMemory(newTime, newValueIfNonStochastic);
		}
		else if(isDeterministic() && !rate.isDeterministic()) {
			double[] rateRealizations = rate.getRealizations();
			double[] newRealizations = new double[Math.max(size(), rate.size())];
			for(int i=0; i<newRealizations.length; i++) {
				newRealizations[i]		 = valueIfNonStochastic * (1 + rateRealizations[i] * periodLength);
			}
			return new RandomVariableLowMemory(newTime, newRealizations);
		}
		else if(!isDeterministic() && rate.isDeterministic()) {
			double rateValue = rate.get(0);
			double[] newRealizations = new double[Math.max(size(), rate.size())];
			for(int i=0; i<newRealizations.length; i++) {
				newRealizations[i]		 = realizations[i] * (1 + rateValue * periodLength);
			}
			return new RandomVariableLowMemory(newTime, newRealizations);
		}
		else {
			double[] rateRealizations = rate.getRealizations();
			double[] newRealizations = new double[Math.max(size(), rate.size())];
			for(int i=0; i<newRealizations.length; i++) {
				newRealizations[i]		 = realizations[i] * (1 + rateRealizations[i] * periodLength);
			}
			return new RandomVariableLowMemory(newTime, newRealizations);
		}
	}
626319
public function plus(Duration $duration) : Instant
    {
        if ($duration->isZero()) {
            return $this;
        }

        $seconds = $this->epochSecond + $duration->getSeconds();
        $nanos = $this->nano + $duration->getNanos();

        return Instant::of($seconds, $nanos);
    }