org.joda.time.IllegalFieldValueException Java Examples

The following examples show how to use org.joda.time.IllegalFieldValueException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: 1_SkipDateTimeField.java    From SimFix with GNU General Public License v2.0 6 votes vote down vote up
public long set(long millis, int value) {
        FieldUtils.verifyValueBounds(this, value, iMinValue, getMaximumValue());
// start of generated patch
if(value<=iSkip){
if(value==iSkip){
throw new IllegalFieldValueException(DateTimeFieldType.year(),Integer.valueOf(value),null,null);
}
getMaximumValue();
}
// end of generated patch
/* start of original code
        if (value <= iSkip) {
            if (value == iSkip) {
                throw new IllegalFieldValueException
                    (DateTimeFieldType.year(), Integer.valueOf(value), null, null);
            }
            value++;
        }
 end of original code*/
        return super.set(millis, value);
    }
 
Example #2
Source File: MedtronicConverter.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
private LocalDateTime decodeTime(byte[] rawContent) {

        int hours = ByteUtil.asUINT8(rawContent[0]);
        int minutes = ByteUtil.asUINT8(rawContent[1]);
        int seconds = ByteUtil.asUINT8(rawContent[2]);
        int year = (ByteUtil.asUINT8(rawContent[4]) & 0x3f) + 1984;
        int month = ByteUtil.asUINT8(rawContent[5]);
        int day = ByteUtil.asUINT8(rawContent[6]);
        try {
            LocalDateTime pumpTime = new LocalDateTime(year, month, day, hours, minutes, seconds);
            return pumpTime;
        } catch (IllegalFieldValueException e) {
            LOG.error(
                    "decodeTime: Failed to parse pump time value: year=%d, month=%d, hours=%d, minutes=%d, seconds=%d",
                    year, month, day, hours, minutes, seconds);
            return null;
        }

    }
 
Example #3
Source File: JulianChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
static int adjustYearForSet(int year) {
    if (year <= 0) {
        if (year == 0) {
            throw new IllegalFieldValueException
                (DateTimeFieldType.year(), Integer.valueOf(year), null, null);
        }
        year++;
    }
    return year;
}
 
Example #4
Source File: Time_15_FieldUtils_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Verify that input values are within specified bounds.
 * 
 * @param value  the value to check
 * @param lowerBound  the lower bound allowed for value
 * @param upperBound  the upper bound allowed for value
 * @throws IllegalFieldValueException if value is not in the specified bounds
 */
public static void verifyValueBounds(String fieldName,
                                     int value, int lowerBound, int upperBound) {
    if ((value < lowerBound) || (value > upperBound)) {
        throw new IllegalFieldValueException
            (fieldName, Integer.valueOf(value),
             Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
    }
}
 
Example #5
Source File: FieldUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verify that input values are within specified bounds.
 * 
 * @param value  the value to check
 * @param lowerBound  the lower bound allowed for value
 * @param upperBound  the upper bound allowed for value
 * @throws IllegalFieldValueException if value is not in the specified bounds
 */
public static void verifyValueBounds(DateTimeField field, 
                                     int value, int lowerBound, int upperBound) {
    if ((value < lowerBound) || (value > upperBound)) {
        throw new IllegalFieldValueException
            (field.getType(), Integer.valueOf(value),
             Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
    }
}
 
Example #6
Source File: TestGJChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testLeapYearRulesConstructionInvalid() {
    // 1500 not leap in Gregorian, but is leap in Julian
    try {
        new DateMidnight(1500, 2, 30, GJChronology.getInstanceUTC());
        fail();
    } catch (IllegalFieldValueException ex) {
        // good
    }
}
 
Example #7
Source File: GJChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public long set(long instant, int value) {
    if (instant >= iCutover) {
        instant = iGregorianField.set(instant, value);
        if (instant < iCutover) {
            // Only adjust if gap fully crossed.
            if (instant + iGapDuration < iCutover) {
                instant = gregorianToJulian(instant);
            }
            // Verify that new value stuck.
            if (get(instant) != value) {
                throw new IllegalFieldValueException
                    (iGregorianField.getType(), Integer.valueOf(value), null, null);
            }
        }
    } else {
        instant = iJulianField.set(instant, value);
        if (instant >= iCutover) {
            // Only adjust if gap fully crossed.
            if (instant - iGapDuration >= iCutover) {
                instant = julianToGregorian(instant);
            }
            // Verify that new value stuck.
            if (get(instant) != value) {
               throw new IllegalFieldValueException
                    (iJulianField.getType(), Integer.valueOf(value), null, null);
            }
        }
    }
    return instant;
}
 
Example #8
Source File: JulianChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
static int adjustYearForSet(int year) {
    if (year <= 0) {
        if (year == 0) {
            throw new IllegalFieldValueException
                (DateTimeFieldType.year(), Integer.valueOf(year), null, null);
        }
        year++;
    }
    return year;
}
 
Example #9
Source File: GJLocaleSymbols.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int eraTextToValue(String text) {
    Integer era = iParseEras.get(text);
    if (era != null) {
        return era.intValue();
    }
    throw new IllegalFieldValueException(DateTimeFieldType.era(), text);
}
 
Example #10
Source File: GJLocaleSymbols.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int monthOfYearTextToValue(String text) {
    Integer month = iParseMonths.get(text);
    if (month != null) {
        return month.intValue();
    }
    throw new IllegalFieldValueException(DateTimeFieldType.monthOfYear(), text);
}
 
Example #11
Source File: GJLocaleSymbols.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int dayOfWeekTextToValue(String text) {
    Integer day = iParseDaysOfWeek.get(text);
    if (day != null) {
        return day.intValue();
    }
    throw new IllegalFieldValueException(DateTimeFieldType.dayOfWeek(), text);
}
 
Example #12
Source File: GJLocaleSymbols.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int halfdayTextToValue(String text) {
    String[] halfday = iHalfday;
    for (int i = halfday.length; --i>=0; ) {
        if (halfday[i].equalsIgnoreCase(text)) {
            return i;
        }
    }
    throw new IllegalFieldValueException(DateTimeFieldType.halfdayOfDay(), text);
}
 
Example #13
Source File: GJChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public long set(long instant, int value) {
    if (instant >= iCutover) {
        instant = iGregorianField.set(instant, value);
        if (instant < iCutover) {
            // Only adjust if gap fully crossed.
            if (instant + iGapDuration < iCutover) {
                instant = gregorianToJulian(instant);
            }
            // Verify that new value stuck.
            if (get(instant) != value) {
                throw new IllegalFieldValueException
                    (iGregorianField.getType(), Integer.valueOf(value), null, null);
            }
        }
    } else {
        instant = iJulianField.set(instant, value);
        if (instant >= iCutover) {
            // Only adjust if gap fully crossed.
            if (instant - iGapDuration >= iCutover) {
                instant = julianToGregorian(instant);
            }
            // Verify that new value stuck.
            if (get(instant) != value) {
               throw new IllegalFieldValueException
                    (iJulianField.getType(), Integer.valueOf(value), null, null);
            }
        }
    }
    return instant;
}
 
Example #14
Source File: TestGJChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public void testLeapYearRulesConstructionInvalid() {
    // 1500 not leap in Gregorian, but is leap in Julian
    try {
        new DateMidnight(1500, 2, 30, GJChronology.getInstanceUTC());
        fail();
    } catch (IllegalFieldValueException ex) {
        // good
    }
}
 
Example #15
Source File: ZonedChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public long set(long instant, int value) {
    long localInstant = iZone.convertUTCToLocal(instant);
    localInstant = iField.set(localInstant, value);
    long result = iZone.convertLocalToUTC(localInstant, false, instant);
    if (get(result) != value) {
        IllegalInstantException cause = new IllegalInstantException(localInstant,  iZone.getID());
        IllegalFieldValueException ex = new IllegalFieldValueException(iField.getType(), Integer.valueOf(value), cause.getMessage());
        ex.initCause(cause);
        throw ex;
    }
    return result;
}
 
Example #16
Source File: GJLocaleSymbols.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int monthOfYearTextToValue(String text) {
    Integer month = iParseMonths.get(text);
    if (month != null) {
        return month.intValue();
    }
    throw new IllegalFieldValueException(DateTimeFieldType.monthOfYear(), text);
}
 
Example #17
Source File: GJLocaleSymbols.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int eraTextToValue(String text) {
    Integer era = iParseEras.get(text);
    if (era != null) {
        return era.intValue();
    }
    throw new IllegalFieldValueException(DateTimeFieldType.era(), text);
}
 
Example #18
Source File: GJLocaleSymbols.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public int halfdayTextToValue(String text) {
    String[] halfday = iHalfday;
    for (int i = halfday.length; --i>=0; ) {
        if (halfday[i].equalsIgnoreCase(text)) {
            return i;
        }
    }
    throw new IllegalFieldValueException(DateTimeFieldType.halfdayOfDay(), text);
}
 
Example #19
Source File: ZonedChronology.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public long set(long instant, int value) {
    long localInstant = iZone.convertUTCToLocal(instant);
    localInstant = iField.set(localInstant, value);
    long result = iZone.convertLocalToUTC(localInstant, false, instant);
    if (get(result) != value) {
        IllegalInstantException cause = new IllegalInstantException(localInstant,  iZone.getID());
        IllegalFieldValueException ex = new IllegalFieldValueException(iField.getType(), Integer.valueOf(value), cause.getMessage());
        ex.initCause(cause);
        throw ex;
    }
    return result;
}
 
Example #20
Source File: BasicSingleEraDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/** @inheritDoc */
public long set(long instant, String text, Locale locale) {
    if (iEraText.equals(text) == false && "1".equals(text) == false) {
        throw new IllegalFieldValueException(DateTimeFieldType.era(), text);
    }
    return instant;
}
 
Example #21
Source File: SkipDateTimeField.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
public long set(long millis, int value) {
    FieldUtils.verifyValueBounds(this, value, iMinValue, getMaximumValue());
    if (value <= iSkip) {
        if (value == iSkip) {
            throw new IllegalFieldValueException
                (DateTimeFieldType.year(), Integer.valueOf(value), null, null);
        }
        value++;
    }
    return super.set(millis, value);
}
 
Example #22
Source File: FieldUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verify that input values are within specified bounds.
 * 
 * @param value  the value to check
 * @param lowerBound  the lower bound allowed for value
 * @param upperBound  the upper bound allowed for value
 * @throws IllegalFieldValueException if value is not in the specified bounds
 */
public static void verifyValueBounds(String fieldName,
                                     int value, int lowerBound, int upperBound) {
    if ((value < lowerBound) || (value > upperBound)) {
        throw new IllegalFieldValueException
            (fieldName, Integer.valueOf(value),
             Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
    }
}
 
Example #23
Source File: FieldUtils.java    From astor with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Verify that input values are within specified bounds.
 * 
 * @param value  the value to check
 * @param lowerBound  the lower bound allowed for value
 * @param upperBound  the upper bound allowed for value
 * @throws IllegalFieldValueException if value is not in the specified bounds
 */
public static void verifyValueBounds(DateTimeField field, 
                                     int value, int lowerBound, int upperBound) {
    if ((value < lowerBound) || (value > upperBound)) {
        throw new IllegalFieldValueException
            (field.getType(), Integer.valueOf(value),
             Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
    }
}
 
Example #24
Source File: Time_26_ZonedChronology_s.java    From coming with MIT License 5 votes vote down vote up
public long set(long instant, int value) {
    long localInstant = iZone.convertUTCToLocal(instant);
    localInstant = iField.set(localInstant, value);
    long result = iZone.convertLocalToUTC(localInstant, false);
    if (get(result) != value) {
        throw new IllegalFieldValueException(iField.getType(), new Integer(value),
            "Illegal instant due to time zone offset transition: " +
            DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS").print(new Instant(localInstant)) +
            " (" + iZone.getID() + ")");
    }
    return result;
}
 
Example #25
Source File: Time_26_ZonedChronology_t.java    From coming with MIT License 5 votes vote down vote up
public long set(long instant, int value) {
    long localInstant = iZone.convertUTCToLocal(instant);
    localInstant = iField.set(localInstant, value);
    long result = iZone.convertLocalToUTC(localInstant, false, instant);
    if (get(result) != value) {
        throw new IllegalFieldValueException(iField.getType(), new Integer(value),
            "Illegal instant due to time zone offset transition: " +
            DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSS").print(new Instant(localInstant)) +
            " (" + iZone.getID() + ")");
    }
    return result;
}
 
Example #26
Source File: Time_6_GJChronology_t.java    From coming with MIT License 5 votes vote down vote up
public long set(long instant, int value) {
    if (instant >= iCutover) {
        instant = iGregorianField.set(instant, value);
        if (instant < iCutover) {
            // Only adjust if gap fully crossed.
            if (instant + iGapDuration < iCutover) {
                instant = gregorianToJulian(instant);
            }
            // Verify that new value stuck.
            if (get(instant) != value) {
                throw new IllegalFieldValueException
                    (iGregorianField.getType(), Integer.valueOf(value), null, null);
            }
        }
    } else {
        instant = iJulianField.set(instant, value);
        if (instant >= iCutover) {
            // Only adjust if gap fully crossed.
            if (instant - iGapDuration >= iCutover) {
                instant = julianToGregorian(instant);
            }
            // Verify that new value stuck.
            if (get(instant) != value) {
               throw new IllegalFieldValueException
                    (iJulianField.getType(), Integer.valueOf(value), null, null);
            }
        }
    }
    return instant;
}
 
Example #27
Source File: Time_6_GJChronology_s.java    From coming with MIT License 5 votes vote down vote up
public long set(long instant, int value) {
    if (instant >= iCutover) {
        instant = iGregorianField.set(instant, value);
        if (instant < iCutover) {
            // Only adjust if gap fully crossed.
            if (instant + iGapDuration < iCutover) {
                instant = gregorianToJulian(instant);
            }
            // Verify that new value stuck.
            if (get(instant) != value) {
                throw new IllegalFieldValueException
                    (iGregorianField.getType(), Integer.valueOf(value), null, null);
            }
        }
    } else {
        instant = iJulianField.set(instant, value);
        if (instant >= iCutover) {
            // Only adjust if gap fully crossed.
            if (instant - iGapDuration >= iCutover) {
                instant = julianToGregorian(instant);
            }
            // Verify that new value stuck.
            if (get(instant) != value) {
               throw new IllegalFieldValueException
                    (iJulianField.getType(), Integer.valueOf(value), null, null);
            }
        }
    }
    return instant;
}
 
Example #28
Source File: MonthOfFixedYearDateTimeField.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public long set(long instant, int value) {
  // Check for illegal values: this is not a lenient field
  if (value < 1 || value > this.numMonthsInYear) {
    throw new IllegalFieldValueException(this.getType(), value, 1, this.numMonthsInYear);
  }
  // What is the current month?
  int monthOfYear = this.get(instant);
  // How many months do we have to add to arrive at the new value
  int monthsToAdd = value - monthOfYear;
  // Now add the required number of months
  return this.add(instant, monthsToAdd);
}
 
Example #29
Source File: Time_15_FieldUtils_t.java    From coming with MIT License 5 votes vote down vote up
/**
 * Verify that input values are within specified bounds.
 * 
 * @param value  the value to check
 * @param lowerBound  the lower bound allowed for value
 * @param upperBound  the upper bound allowed for value
 * @throws IllegalFieldValueException if value is not in the specified bounds
 */
public static void verifyValueBounds(DateTimeField field, 
                                     int value, int lowerBound, int upperBound) {
    if ((value < lowerBound) || (value > upperBound)) {
        throw new IllegalFieldValueException
            (field.getType(), Integer.valueOf(value),
             Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
    }
}
 
Example #30
Source File: Time_15_FieldUtils_s.java    From coming with MIT License 5 votes vote down vote up
/**
 * Verify that input values are within specified bounds.
 * 
 * @param value  the value to check
 * @param lowerBound  the lower bound allowed for value
 * @param upperBound  the upper bound allowed for value
 * @throws IllegalFieldValueException if value is not in the specified bounds
 */
public static void verifyValueBounds(String fieldName,
                                     int value, int lowerBound, int upperBound) {
    if ((value < lowerBound) || (value > upperBound)) {
        throw new IllegalFieldValueException
            (fieldName, Integer.valueOf(value),
             Integer.valueOf(lowerBound), Integer.valueOf(upperBound));
    }
}