类org.joda.time.IllegalInstantException源码实例Demo

下面列出了怎么用org.joda.time.IllegalInstantException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: dhis2-core   文件: DateUtils.java
/**
 * Parses the given string into a Date object. In case the date parsed falls in a
 * daylight savings transition, the date is parsed via a local date and converted to the
 * first valid time after the DST gap. When the fallback is used, any timezone offset in the given
 * format would be ignored.
 *
 * @param dateString The string to parse
 * @param formatter The formatter to use for parsing
 * @return Parsed Date object. Null if the supplied dateString is empty.
 */
private static Date safeParseDateTime( final String dateString, final DateTimeFormatter formatter )
{
    if ( StringUtils.isEmpty( dateString ) )
    {
        return null;
    }

    try
    {
        return formatter.parseDateTime( dateString ).toDate();
    }
    catch( IllegalInstantException e )
    {
        return formatter.parseLocalDateTime( dateString ).toDate();
    }
}
 
源代码2 项目: dhis2-core   文件: DateTimeUnit.java
/**
 * Converts dateUnit to Joda-Time DateTime with a specific chronology.
 *
 * @param chronology Chronology to use
 * @return Populated DateTime object
 */
public DateTime toJodaDateTime( Chronology chronology )
{
    try
    {
        return new DateTime( year, month, day, hour, minute, second, millis, chronology.withZone( DateTimeZone.forTimeZone( timeZone ) ) );
    }
    catch ( IllegalInstantException ex )
    {
        LocalDateTime localDateTime = new LocalDateTime( year, month, day, hour, minute, second, millis,
            chronology.withZone( DateTimeZone.forTimeZone( timeZone ) ) );

        return localDateTime.toLocalDate().toDateTimeAtStartOfDay();
    }
}
 
源代码3 项目: astor   文件: ZonedChronology.java
/**
 * @param localInstant  the instant from 1970-01-01T00:00:00 local time
 * @return the instant from 1970-01-01T00:00:00Z
 */
private long localToUTC(long localInstant) {
    DateTimeZone zone = getZone();
    int offset = zone.getOffsetFromLocal(localInstant);
    localInstant -= offset;
    if (offset != zone.getOffset(localInstant)) {
        throw new IllegalInstantException(localInstant, zone.getID());
    }
    return localInstant;
}
 
源代码4 项目: astor   文件: ZonedChronology.java
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;
}
 
源代码5 项目: astor   文件: ZonedChronology.java
/**
 * @param localInstant  the instant from 1970-01-01T00:00:00 local time
 * @return the instant from 1970-01-01T00:00:00Z
 */
private long localToUTC(long localInstant) {
    DateTimeZone zone = getZone();
    int offset = zone.getOffsetFromLocal(localInstant);
    localInstant -= offset;
    if (offset != zone.getOffset(localInstant)) {
        throw new IllegalInstantException(localInstant, zone.getID());
    }
    return localInstant;
}
 
源代码6 项目: astor   文件: ZonedChronology.java
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;
}
 
源代码7 项目: coming   文件: Nopol2017_0091_t.java
/**
 * Computes the parsed datetime by setting the saved fields.
 * This method is idempotent, but it is not thread-safe.
 *
 * @param resetFields false by default, but when true, unsaved field values are cleared
 * @param text optional text being parsed, to be included in any error message
 * @return milliseconds since 1970-01-01T00:00:00Z
 * @throws IllegalArgumentException if any field is out of range
 * @since 1.3
 */
public long computeMillis(boolean resetFields, String text) {
    SavedField[] savedFields = iSavedFields;
    int count = iSavedFieldsCount;
    if (iSavedFieldsShared) {
        iSavedFields = savedFields = (SavedField[])iSavedFields.clone();
        iSavedFieldsShared = false;
    }
    sort(savedFields, count);
    if (count > 0) {
        // alter base year for parsing if first field is month or day
        DurationField months = DurationFieldType.months().getField(iChrono);
        DurationField days = DurationFieldType.days().getField(iChrono);
        DurationField first = savedFields[0].iField.getDurationField();
        if (compareReverse(first, months) >= 0 && compareReverse(first, days) <= 0) {
            saveField(DateTimeFieldType.year(), iDefaultYear);
            if (resetFields) {
                return computeMillis(resetFields, text);
            }
        }
    }

    long millis = iMillis;
    try {
        for (int i = 0; i < count; i++) {
            millis = savedFields[i].set(millis, resetFields);
        }
        if (resetFields) {
            for (int i = 0; i < count; i++) {
                millis = savedFields[i].set(millis, i == (count - 1));
            }
        }
    } catch (IllegalFieldValueException e) {
        if (text != null) {
            e.prependMessage("Cannot parse \"" + text + '"');
        }
        throw e;
    }
    
    if (iOffset != null) {
        millis -= iOffset;
    } else if (iZone != null) {
        int offset = iZone.getOffsetFromLocal(millis);
        millis -= offset;
        if (offset != iZone.getOffset(millis)) {
            String message = "Illegal instant due to time zone offset transition (" + iZone + ')';
            if (text != null) {
                message = "Cannot parse \"" + text + "\": " + message;
            }
            throw new IllegalInstantException(message);
        }
    }
    
    return millis;
}
 
源代码8 项目: coming   文件: Nopol2017_0091_s.java
/**
 * Computes the parsed datetime by setting the saved fields.
 * This method is idempotent, but it is not thread-safe.
 *
 * @param resetFields false by default, but when true, unsaved field values are cleared
 * @param text optional text being parsed, to be included in any error message
 * @return milliseconds since 1970-01-01T00:00:00Z
 * @throws IllegalArgumentException if any field is out of range
 * @since 1.3
 */
public long computeMillis(boolean resetFields, String text) {
    SavedField[] savedFields = iSavedFields;
    int count = iSavedFieldsCount;
    if (iSavedFieldsShared) {
        iSavedFields = savedFields = (SavedField[])iSavedFields.clone();
        iSavedFieldsShared = false;
    }
    sort(savedFields, count);
    if (count > 0) {
        // alter base year for parsing if first field is month or day
        DurationField months = DurationFieldType.months().getField(iChrono);
        DurationField days = DurationFieldType.days().getField(iChrono);
        DurationField first = savedFields[0].iField.getDurationField();
        if (compareReverse(first, months) >= 0 && compareReverse(first, days) <= 0) {
            saveField(DateTimeFieldType.year(), iDefaultYear);
            return computeMillis(resetFields, text);
        }
    }

    long millis = iMillis;
    try {
        for (int i = 0; i < count; i++) {
            millis = savedFields[i].set(millis, resetFields);
        }
        if (resetFields) {
            for (int i = 0; i < count; i++) {
                millis = savedFields[i].set(millis, i == (count - 1));
            }
        }
    } catch (IllegalFieldValueException e) {
        if (text != null) {
            e.prependMessage("Cannot parse \"" + text + '"');
        }
        throw e;
    }
    
    if (iOffset != null) {
        millis -= iOffset;
    } else if (iZone != null) {
        int offset = iZone.getOffsetFromLocal(millis);
        millis -= offset;
        if (offset != iZone.getOffset(millis)) {
            String message = "Illegal instant due to time zone offset transition (" + iZone + ')';
            if (text != null) {
                message = "Cannot parse \"" + text + "\": " + message;
            }
            throw new IllegalInstantException(message);
        }
    }
    
    return millis;
}
 
源代码9 项目: astor   文件: DateTimeParserBucket.java
/**
 * Computes the parsed datetime by setting the saved fields.
 * This method is idempotent, but it is not thread-safe.
 *
 * @param resetFields false by default, but when true, unsaved field values are cleared
 * @param text optional text being parsed, to be included in any error message
 * @return milliseconds since 1970-01-01T00:00:00Z
 * @throws IllegalArgumentException if any field is out of range
 * @since 1.3
 */
public long computeMillis(boolean resetFields, String text) {
    SavedField[] savedFields = iSavedFields;
    int count = iSavedFieldsCount;
    if (iSavedFieldsShared) {
        iSavedFields = savedFields = (SavedField[])iSavedFields.clone();
        iSavedFieldsShared = false;
    }
    sort(savedFields, count);
    if (count > 0) {
        // alter base year for parsing if first field is month or day
        DurationField months = DurationFieldType.months().getField(iChrono);
        DurationField days = DurationFieldType.days().getField(iChrono);
        DurationField first = savedFields[0].iField.getDurationField();
        if (compareReverse(first, months) >= 0 && compareReverse(first, days) <= 0) {
            saveField(DateTimeFieldType.year(), iDefaultYear);
            return computeMillis(resetFields, text);
        }
    }

    long millis = iMillis;
    try {
        for (int i = 0; i < count; i++) {
            millis = savedFields[i].set(millis, resetFields);
        }
        if (resetFields) {
            for (int i = 0; i < count; i++) {
                millis = savedFields[i].set(millis, i == (count - 1));
            }
        }
    } catch (IllegalFieldValueException e) {
        if (text != null) {
            e.prependMessage("Cannot parse \"" + text + '"');
        }
        throw e;
    }
    
    if (iOffset != null) {
        millis -= iOffset;
    } else if (iZone != null) {
        int offset = iZone.getOffsetFromLocal(millis);
        millis -= offset;
        if (offset != iZone.getOffset(millis)) {
            String message = "Illegal instant due to time zone offset transition (" + iZone + ')';
            if (text != null) {
                message = "Cannot parse \"" + text + "\": " + message;
            }
            throw new IllegalInstantException(message);
        }
    }
    
    return millis;
}
 
源代码10 项目: astor   文件: DateTimeParserBucket.java
/**
 * Computes the parsed datetime by setting the saved fields.
 * This method is idempotent, but it is not thread-safe.
 *
 * @param resetFields false by default, but when true, unsaved field values are cleared
 * @param text optional text being parsed, to be included in any error message
 * @return milliseconds since 1970-01-01T00:00:00Z
 * @throws IllegalArgumentException if any field is out of range
 * @since 1.3
 */
public long computeMillis(boolean resetFields, String text) {
    SavedField[] savedFields = iSavedFields;
    int count = iSavedFieldsCount;
    if (iSavedFieldsShared) {
        iSavedFields = savedFields = (SavedField[])iSavedFields.clone();
        iSavedFieldsShared = false;
    }
    sort(savedFields, count);
    if (count > 0) {
        // alter base year for parsing if first field is month or day
        DurationField months = DurationFieldType.months().getField(iChrono);
        DurationField days = DurationFieldType.days().getField(iChrono);
        DurationField first = savedFields[0].iField.getDurationField();
        if (compareReverse(first, months) >= 0 && compareReverse(first, days) <= 0) {
            saveField(DateTimeFieldType.year(), iDefaultYear);
            return computeMillis(resetFields, text);
        }
    }

    long millis = iMillis;
    try {
        for (int i = 0; i < count; i++) {
            millis = savedFields[i].set(millis, resetFields);
        }
        if (resetFields) {
            for (int i = 0; i < count; i++) {
                millis = savedFields[i].set(millis, i == (count - 1));
            }
        }
    } catch (IllegalFieldValueException e) {
        if (text != null) {
            e.prependMessage("Cannot parse \"" + text + '"');
        }
        throw e;
    }
    
    if (iOffset != null) {
        millis -= iOffset;
    } else if (iZone != null) {
        int offset = iZone.getOffsetFromLocal(millis);
        millis -= offset;
        if (offset != iZone.getOffset(millis)) {
            String message = "Illegal instant due to time zone offset transition (" + iZone + ')';
            if (text != null) {
                message = "Cannot parse \"" + text + "\": " + message;
            }
            throw new IllegalInstantException(message);
        }
    }
    
    return millis;
}
 
 类所在包
 类方法
 同包方法