/** * Returns a copy of this datetime with the specified period added. * <p> * This method will add each element of the period one by one, from largest * to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, adding a period of one month and one day to 2007-03-31 will * work as follows: * First add one month and adjust, resulting in 2007-04-30 * Then add one day and adjust, resulting in 2007-05-01. * <p> * This method is typically used to add complex period instances. * Adding one field is best achieved using methods * like {@link #plusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the duration to add to this one, null means zero * @return a copy of this datetime with the period added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime plus(ReadablePeriod period) { return withPeriodAdded(period, 1); }
/** * Returns a copy of this datetime with the specified period taken away. * <p> * This method will subtract each element of the period one by one, from * largest to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, subtracting a period of one month and one day from 2007-05-31 will * work as follows: * First subtract one month and adjust, resulting in 2007-04-30 * Then subtract one day and adjust, resulting in 2007-04-29. * Note that the day has been adjusted by two. * <p> * This method is typically used to subtract complex period instances. * Subtracting one field is best achieved using methods * like {@link #minusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the period to reduce this instant by * @return a copy of this datetime with the period taken away * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime minus(ReadablePeriod period) { return withPeriodAdded(period, -1); }
/** * Returns a copy of this datetime with the specified period added. * <p> * This method will add each element of the period one by one, from largest * to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, adding a period of one month and one day to 2007-03-31 will * work as follows: * First add one month and adjust, resulting in 2007-04-30 * Then add one day and adjust, resulting in 2007-05-01. * <p> * This method is typically used to add complex period instances. * Adding one field is best achieved using methods * like {@link #plusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the duration to add to this one, null means zero * @return a copy of this datetime with the period added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime plus(ReadablePeriod period) { return withPeriodAdded(period, 1); }
/** * Returns a copy of this datetime with the specified period taken away. * <p> * This method will subtract each element of the period one by one, from * largest to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, subtracting a period of one month and one day from 2007-05-31 will * work as follows: * First subtract one month and adjust, resulting in 2007-04-30 * Then subtract one day and adjust, resulting in 2007-04-29. * Note that the day has been adjusted by two. * <p> * This method is typically used to subtract complex period instances. * Subtracting one field is best achieved using methods * like {@link #minusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the period to reduce this instant by * @return a copy of this datetime with the period taken away * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime minus(ReadablePeriod period) { return withPeriodAdded(period, -1); }
int multiplicator = 0; do { tmpAnchor = currentAnchor.withPeriodAdded(rotationPeriod, ++multiplicator); } while (tmpAnchor.isBefore(now)); final DateTime nextAnchor = currentAnchor.withPeriodAdded(rotationPeriod, multiplicator - 1); anchor.put(indexSetId, nextAnchor); lastRotation.put(indexSetId, now);
/** * Returns a copy of this datetime with the specified period added. * <p> * This method will add each element of the period one by one, from largest * to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, adding a period of one month and one day to 2007-03-31 will * work as follows: * First add one month and adjust, resulting in 2007-04-30 * Then add one day and adjust, resulting in 2007-05-01. * <p> * This method is typically used to add complex period instances. * Adding one field is best achieved using methods * like {@link #plusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the duration to add to this one, null means zero * @return a copy of this datetime with the period added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime plus(ReadablePeriod period) { return withPeriodAdded(period, 1); }
/** * Returns a copy of this datetime with the specified period taken away. * <p> * This method will subtract each element of the period one by one, from * largest to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, subtracting a period of one month and one day from 2007-05-31 will * work as follows: * First subtract one month and adjust, resulting in 2007-04-30 * Then subtract one day and adjust, resulting in 2007-04-29. * Note that the day has been adjusted by two. * <p> * This method is typically used to subtract complex period instances. * Subtracting one field is best achieved using methods * like {@link #minusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the period to reduce this instant by * @return a copy of this datetime with the period taken away * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime minus(ReadablePeriod period) { return withPeriodAdded(period, -1); }
/** * Returns a copy of this datetime with the specified period added. * <p> * This method will add each element of the period one by one, from largest * to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, adding a period of one month and one day to 2007-03-31 will * work as follows: * First add one month and adjust, resulting in 2007-04-30 * Then add one day and adjust, resulting in 2007-05-01. * <p> * This method is typically used to add complex period instances. * Adding one field is best achieved using methods * like {@link #plusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the duration to add to this one, null means zero * @return a copy of this datetime with the period added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime plus(ReadablePeriod period) { return withPeriodAdded(period, 1); }
/** * Returns a copy of this datetime with the specified period added. * <p> * This method will add each element of the period one by one, from largest * to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, adding a period of one month and one day to 2007-03-31 will * work as follows: * First add one month and adjust, resulting in 2007-04-30 * Then add one day and adjust, resulting in 2007-05-01. * <p> * This method is typically used to add complex period instances. * Adding one field is best achieved using methods * like {@link #plusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the duration to add to this one, null means zero * @return a copy of this datetime with the period added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime plus(ReadablePeriod period) { return withPeriodAdded(period, 1); }
/** * Returns a copy of this datetime with the specified period added. * <p> * This method will add each element of the period one by one, from largest * to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, adding a period of one month and one day to 2007-03-31 will * work as follows: * First add one month and adjust, resulting in 2007-04-30 * Then add one day and adjust, resulting in 2007-05-01. * <p> * This method is typically used to add complex period instances. * Adding one field is best achieved using methods * like {@link #plusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the duration to add to this one, null means zero * @return a copy of this datetime with the period added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime plus(ReadablePeriod period) { return withPeriodAdded(period, 1); }
/** * Returns a copy of this datetime with the specified period added. * <p> * This method will add each element of the period one by one, from largest * to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, adding a period of one month and one day to 2007-03-31 will * work as follows: * First add one month and adjust, resulting in 2007-04-30 * Then add one day and adjust, resulting in 2007-05-01. * <p> * This method is typically used to add complex period instances. * Adding one field is best achieved using methods * like {@link #plusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the duration to add to this one, null means zero * @return a copy of this datetime with the period added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime plus(ReadablePeriod period) { return withPeriodAdded(period, 1); }
/** * Returns a copy of this datetime with the specified period taken away. * <p> * This method will subtract each element of the period one by one, from * largest to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, subtracting a period of one month and one day from 2007-05-31 will * work as follows: * First subtract one month and adjust, resulting in 2007-04-30 * Then subtract one day and adjust, resulting in 2007-04-29. * Note that the day has been adjusted by two. * <p> * This method is typically used to subtract complex period instances. * Subtracting one field is best achieved using methods * like {@link #minusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the period to reduce this instant by * @return a copy of this datetime with the period taken away * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime minus(ReadablePeriod period) { return withPeriodAdded(period, -1); }
/** * Returns a copy of this datetime with the specified period taken away. * <p> * This method will subtract each element of the period one by one, from * largest to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, subtracting a period of one month and one day from 2007-05-31 will * work as follows: * First subtract one month and adjust, resulting in 2007-04-30 * Then subtract one day and adjust, resulting in 2007-04-29. * Note that the day has been adjusted by two. * <p> * This method is typically used to subtract complex period instances. * Subtracting one field is best achieved using methods * like {@link #minusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the period to reduce this instant by * @return a copy of this datetime with the period taken away * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime minus(ReadablePeriod period) { return withPeriodAdded(period, -1); }
/** * Returns a copy of this datetime with the specified period taken away. * <p> * This method will subtract each element of the period one by one, from * largest to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, subtracting a period of one month and one day from 2007-05-31 will * work as follows: * First subtract one month and adjust, resulting in 2007-04-30 * Then subtract one day and adjust, resulting in 2007-04-29. * Note that the day has been adjusted by two. * <p> * This method is typically used to subtract complex period instances. * Subtracting one field is best achieved using methods * like {@link #minusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the period to reduce this instant by * @return a copy of this datetime with the period taken away * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime minus(ReadablePeriod period) { return withPeriodAdded(period, -1); }
/** * Returns a copy of this datetime with the specified period taken away. * <p> * This method will subtract each element of the period one by one, from * largest to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, subtracting a period of one month and one day from 2007-05-31 will * work as follows: * First subtract one month and adjust, resulting in 2007-04-30 * Then subtract one day and adjust, resulting in 2007-04-29. * Note that the day has been adjusted by two. * <p> * This method is typically used to subtract complex period instances. * Subtracting one field is best achieved using methods * like {@link #minusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the period to reduce this instant by * @return a copy of this datetime with the period taken away * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime minus(ReadablePeriod period) { return withPeriodAdded(period, -1); }
/** * Returns a copy of this datetime with the specified period taken away. * <p> * This method will subtract each element of the period one by one, from * largest to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, subtracting a period of one month and one day from 2007-05-31 will * work as follows: * First subtract one month and adjust, resulting in 2007-04-30 * Then subtract one day and adjust, resulting in 2007-04-29. * Note that the day has been adjusted by two. * <p> * This method is typically used to subtract complex period instances. * Subtracting one field is best achieved using methods * like {@link #minusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the period to reduce this instant by * @return a copy of this datetime with the period taken away * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime minus(ReadablePeriod period) { return withPeriodAdded(period, -1); }
/** * Returns a copy of this datetime with the specified period added. * <p> * This method will add each element of the period one by one, from largest * to smallest, adjusting the datetime to be accurate between each. * <p> * Thus, adding a period of one month and one day to 2007-03-31 will * work as follows: * First add one month and adjust, resulting in 2007-04-30 * Then add one day and adjust, resulting in 2007-05-01. * <p> * This method is typically used to add complex period instances. * Adding one field is best achieved using methods * like {@link #plusYears(int)}. * <p> * If the amount is zero or null, then <code>this</code> is returned. * This datetime instance is immutable and unaffected by this method call. * * @param period the duration to add to this one, null means zero * @return a copy of this datetime with the period added * @throws ArithmeticException if the new datetime exceeds the capacity of a long */ public DateTime plus(ReadablePeriod period) { return withPeriodAdded(period, 1); }
private Boolean isLicenseThisOld(final LicenseDetails input, final Period period) { Date licensePurchaseDate = input.getJiraLicense().getPurchaseDate(); return new DateTime(licensePurchaseDate).withPeriodAdded(period, 1).isBefore(new DateTime(clock.getCurrentDate())); } }
/** * Given an interval and a lookbackOffset, calculate the cohortInterval. * * @param interval The measurement interval to which the offset is added * @param lookbackOffset The offset to be added to the given interval * * @return Cohort interval calculated using the given interval and lookbackOffset */ private Interval getCohortInterval(Interval interval, Period lookbackOffset) { return new Interval( interval.getStart().withPeriodAdded(lookbackOffset, 1), interval.getEnd().withPeriodAdded(lookbackOffset, 1) ); } }
@Override public void assess(WithinSchedule metric, MetricAssessmentBuilder<Serializable> builder) { DateTime start = new DateTime(CronExpressionUtil.getPreviousFireTime(metric.getCronExpression())); DateTime end = start.withPeriodAdded(metric.getPeriod(), 1); builder.metric(metric); if (start.isBeforeNow() && end.isAfterNow()) { builder .result(AssessmentResult.SUCCESS) .message("Current time falls between the schedule " + start + " - " + end); } else { builder .result(AssessmentResult.FAILURE) .message("Current time does not falls between the schedule " + start + " - " + end); } } }