// -----------------------------------------------------------------------
 public int[] add(ReadablePartial partial, int fieldIndex, int[] values, int valueToAdd) {
   // overridden as superclass algorithm can't handle
   // 2004-02-29 + 48 months -> 2008-02-29 type dates
   if (valueToAdd == 0) {
     return values;
   }
   if (partial.size() > 0
       && partial.getFieldType(0).equals(DateTimeFieldType.monthOfYear())
       && fieldIndex == 0) {
     // month is largest field and being added to, such as month-day
     int curMonth0 = partial.getValue(0) - 1;
     int newMonth = ((curMonth0 + (valueToAdd % 12) + 12) % 12) + 1;
     return set(partial, 0, values, newMonth);
   }
   if (DateTimeUtils.isContiguous(partial)) {
     long instant = 0L;
     for (int i = 0, isize = partial.size(); i < isize; i++) {
       instant = partial.getFieldType(i).getField(iChronology).set(instant, values[i]);
     }
     instant = add(instant, valueToAdd);
     return iChronology.get(partial, instant);
   } else {
     return super.add(partial, fieldIndex, values, valueToAdd);
   }
 }
示例#2
0
 /**
  * Gets the values of a partial from an instant.
  *
  * @param partial the partial instant to use
  * @param instant the instant to query
  * @return the values of the partial extracted from the instant
  */
 public int[] get(ReadablePartial partial, long instant) {
   int size = partial.size();
   int[] values = new int[size];
   for (int i = 0; i < size; i++) {
     values[i] = partial.getFieldType(i).getField(this).get(instant);
   }
   return values;
 }
 public int getMaximumValue(ReadablePartial partial) {
   if (partial.isSupported(DateTimeFieldType.monthOfYear())) {
     int month = partial.get(DateTimeFieldType.monthOfYear());
     if (partial.isSupported(DateTimeFieldType.year())) {
       int year = partial.get(DateTimeFieldType.year());
       return iChronology.getDaysInYearMonth(year, month);
     }
     return iChronology.getDaysInMonthMax(month);
   }
   return getMaximumValue();
 }
 public int getMaximumValue(ReadablePartial partial, int[] values) {
   int size = partial.size();
   for (int i = 0; i < size; i++) {
     if (partial.getFieldType(i) == DateTimeFieldType.monthOfYear()) {
       int month = values[i];
       for (int j = 0; j < size; j++) {
         if (partial.getFieldType(j) == DateTimeFieldType.year()) {
           int year = values[j];
           return iChronology.getDaysInYearMonth(year, month);
         }
       }
       return iChronology.getDaysInMonthMax(month);
     }
   }
   return getMaximumValue();
 }
示例#5
0
 /**
  * Validates whether the fields stored in a partial instant are valid.
  *
  * <p>This implementation uses {@link DateTimeField#getMinimumValue(ReadablePartial, int[])} and
  * {@link DateTimeField#getMaximumValue(ReadablePartial, int[])}.
  *
  * @param partial the partial instant to validate
  * @param values the values to validate, not null
  * @throws IllegalArgumentException if the instant is invalid
  */
 public void validate(ReadablePartial partial, int[] values) {
   // check values in standard range, catching really stupid cases like -1
   // this means that the second check will not hit trouble
   int size = partial.size();
   for (int i = 0; i < size; i++) {
     int value = values[i];
     DateTimeField field = partial.getField(i);
     if (value < field.getMinimumValue()) {
       throw new IllegalFieldValueException(
           field.getType(), new Integer(value), new Integer(field.getMinimumValue()), null);
     }
     if (value > field.getMaximumValue()) {
       throw new IllegalFieldValueException(
           field.getType(), new Integer(value), null, new Integer(field.getMaximumValue()));
     }
   }
   // check values in specific range, catching really odd cases like 30th Feb
   for (int i = 0; i < size; i++) {
     int value = values[i];
     DateTimeField field = partial.getField(i);
     if (value < field.getMinimumValue(partial, values)) {
       throw new IllegalFieldValueException(
           field.getType(),
           new Integer(value),
           new Integer(field.getMinimumValue(partial, values)),
           null);
     }
     if (value > field.getMaximumValue(partial, values)) {
       throw new IllegalFieldValueException(
           field.getType(),
           new Integer(value),
           null,
           new Integer(field.getMaximumValue(partial, values)));
     }
   }
 }
示例#6
0
 /**
  * Sets the partial into the instant.
  *
  * @param partial the partial instant to use
  * @param instant the instant to update
  * @return the updated instant
  */
 public long set(ReadablePartial partial, long instant) {
   for (int i = 0, isize = partial.size(); i < isize; i++) {
     instant = partial.getFieldType(i).getField(this).set(instant, partial.getValue(i));
   }
   return instant;
 }