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

项目:penn-mobile-android    文件:VenueInterval.java   
/**
 * Put together the date given with the hours to create a POJO for the time interval in
 * which the dining hall is open.
 * Any time before 6:00am is assumed to be from the next day rather than the given date.
 * @param date Date string in yyyy-MM-dd format
 * @return Time interval in which meal is open represented as a Joda Interval
 */
public Interval getInterval(String date) {
    String openTime = date + " " + open;
    String closeTime = date + " " + close;
    // Avoid midnight hour confusion as API returns both 00:00 and 24:00
    // Switch it to more comprehensible 23:59 / 11:59PM
    if (close.equals("00:00:00") || close.equals("24:00:00")) {
        closeTime = date + " " + "23:59:59";
    }
    DateTime openInstant = DateTime.parse(openTime, DATEFORMAT);
    DateTime closeInstant;
    try {
        closeInstant = DateTime.parse(closeTime, DATEFORMAT);
    } catch (IllegalInstantException e) {
        closeTime = date + " " + "01:00:00";
        closeInstant = DateTime.parse(closeTime, DATEFORMAT);
    }

    // Close hours sometimes given in AM hours of next day
    // Cutoff for "early morning" hours was decided to be 6AM
    if (closeInstant.getHourOfDay() < 6) {
        closeInstant = closeInstant.plusDays(1);
    }

    return new Interval(openInstant, closeInstant);
}
项目: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();
    }
}
项目:AgileAlligators    文件: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();
    }
}
项目: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;
}
项目: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;
}
项目: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;
}
项目: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;
}
项目:idylfin    文件: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;
}
项目:idylfin    文件: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;
}
项目:versemem-android    文件: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;
}
项目:versemem-android    文件: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;
}
项目:iMetrica    文件:MDFAStrategyEvolution.java   
public void updateEndTimeAsia(String time, int start_hour, int close_hour, int liquide_hour, int liquide_min)
{
    String date_delims = "[ ]+";
    String ddelims = "[-]"; 

    String[] date_tokens = time.split(date_delims); 
    String[] intdates = date_tokens[0].split(ddelims);     

    int signal_min = liquide_min;

    try
    {
        startTimeDT = new DateTime((new Integer(intdates[0])).intValue(), (new Integer(intdates[1])).intValue(), (new Integer(intdates[2])).intValue(),start_hour,signal_min);
    }
    catch(IllegalInstantException ie)
    {
        startTimeDT = new DateTime((new Integer(intdates[0])).intValue(), (new Integer(intdates[1])).intValue(), (new Integer(intdates[2])).intValue(),start_hour+1,signal_min);
    }

    endTimeDT = new DateTime((new Integer(intdates[0])).intValue(), (new Integer(intdates[1])).intValue(), (new Integer(intdates[2])).intValue(),close_hour,signal_min);
    liquidateTimeDT = new DateTime((new Integer(intdates[0])).intValue(), (new Integer(intdates[1])).intValue(), (new Integer(intdates[2])).intValue(), liquide_hour, liquide_min);

    if(liquide_hour > start_hour && liquidateTimeDT.dayOfWeek().getAsText().equals("Friday"))
    {liquidateTimeDT = liquidateTimeDT.plusDays(2);}

    //--- assume starting after 10am HST (16.00 EST or 4pm EST) produces new system setup for next day
    //System.out.println(cur_hour);

     if(close_hour < start_hour)
     {
         endTimeDT = endTimeDT.plusDays(1); 

         if(endTimeDT.dayOfWeek().getAsText().equals("Saturday"))
         {
             endTimeDT = endTimeDT.plusDays(2);
         }   
     }
     else if(endTimeDT.dayOfWeek().getAsText().equals("Friday"))
     {
         endTimeDT = endTimeDT.plusDays(2);
     }

     if(liquide_hour < start_hour)
     {liquidateTimeDT = liquidateTimeDT.plusDays(1);} 

     if(liquidateTimeDT.dayOfWeek().getAsText().equals("Saturday"))
     {liquidateTimeDT = liquidateTimeDT.plusDays(2);}

     //System.out.println("Updated start/close at " + startTimeDT + " " + endTimeDT + " " + liquidateTimeDT);


}
项目: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;
}
项目: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;
}
项目:idylfin    文件: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;
}
项目:versemem-android    文件: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;
}