public long add(long instant, int years) {
   if (years == 0) {
     return instant;
   }
   int thisYear = get(instant);
   int newYear = FieldUtils.safeAdd(thisYear, years);
   return set(instant, newYear);
 }
Пример #2
0
 /**
  * Adds to the indexed field part of the period.
  *
  * @param period the period to query
  * @param index the index to use
  * @param values the array to populate
  * @param valueToAdd the value to add
  * @return true if the array is updated
  * @throws UnsupportedOperationException if not supported
  */
 boolean addIndexedField(ReadablePeriod period, int index, int[] values, int valueToAdd) {
   if (valueToAdd == 0) {
     return false;
   }
   int realIndex = iIndices[index];
   if (realIndex == -1) {
     throw new UnsupportedOperationException("Field is not supported");
   }
   values[realIndex] = FieldUtils.safeAdd(values[realIndex], valueToAdd);
   return true;
 }
 public long addWrapField(long instant, int years) {
   if (years == 0) {
     return instant;
   }
   // Return newly calculated millis value
   int thisYear = iChronology.getYear(instant);
   int wrappedYear =
       FieldUtils.getWrappedValue(
           thisYear, years, iChronology.getMinYear(), iChronology.getMaxYear());
   return set(instant, wrappedYear);
 }
Пример #4
0
 /**
  * Compares this object with the specified object for equality based on start and end millis plus
  * the chronology. All ReadableInterval instances are accepted.
  *
  * <p>To compare the duration of two time intervals, use {@link #toDuration()} to get the
  * durations and compare those.
  *
  * @param readableInterval a readable interval to check against
  * @return true if the start and end millis are equal
  */
 public boolean equals(Object readableInterval) {
   if (this == readableInterval) {
     return true;
   }
   if (readableInterval instanceof ReadableInterval == false) {
     return false;
   }
   ReadableInterval other = (ReadableInterval) readableInterval;
   return getStartMillis() == other.getStartMillis()
       && getEndMillis() == other.getEndMillis()
       && FieldUtils.equals(getChronology(), other.getChronology());
 }
 /**
  * Set the Month component of the specified time instant.
  *
  * <p>If the new month has less total days than the specified day of the month, this value is
  * coerced to the nearest sane value. e.g.
  *
  * <p>07-31 to month 6 = 06-30
  *
  * <p>03-31 to month 2 = 02-28 or 02-29 depending
  *
  * <p>
  *
  * @param instant the time instant in millis to update.
  * @param month the month (1,12) to update the time to.
  * @return the updated time instant.
  * @throws IllegalArgumentException if month is invalid
  */
 public long set(long instant, int month) {
   FieldUtils.verifyValueBounds(this, month, MIN, iMax);
   //
   int thisYear = iChronology.getYear(instant);
   //
   int thisDom = iChronology.getDayOfMonth(instant, thisYear);
   int maxDom = iChronology.getDaysInYearMonth(thisYear, month);
   if (thisDom > maxDom) {
     // Quietly force DOM to nearest sane value.
     thisDom = maxDom;
   }
   // Return newly calculated millis value
   return iChronology.getYearMonthDayMillis(thisYear, month, thisDom)
       + iChronology.getMillisOfDay(instant);
 }
 /**
  * Add to the Month component of the specified time instant wrapping around within that component
  * if necessary.
  *
  * @see org.joda.time.DateTimeField#addWrapField
  * @param instant the time instant in millis to update.
  * @param months the months to add (can be negative).
  * @return the updated time instant.
  */
 public long addWrapField(long instant, int months) {
   return set(instant, FieldUtils.getWrappedValue(get(instant), months, MIN, iMax));
 }
Пример #7
0
 /**
  * Gets the duration of this time interval in milliseconds.
  *
  * <p>The duration is equal to the end millis minus the start millis.
  *
  * @return the duration of the time interval in milliseconds
  * @throws ArithmeticException if the duration exceeds the capacity of a long
  */
 public long toDurationMillis() {
   return FieldUtils.safeAdd(getEndMillis(), -getStartMillis());
 }
 public long set(long instant, int year) {
   FieldUtils.verifyValueBounds(this, year, iChronology.getMinYear(), iChronology.getMaxYear());
   return iChronology.setYear(instant, year);
 }
 public long add(long instant, long years) {
   return add(instant, FieldUtils.safeToInt(years));
 }