本文整理汇总了Java中org.joda.time.IllegalInstantException类的典型用法代码示例。如果您正苦于以下问题:Java IllegalInstantException类的具体用法?Java IllegalInstantException怎么用?Java IllegalInstantException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IllegalInstantException类属于org.joda.time包,在下文中一共展示了IllegalInstantException类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getInterval
import org.joda.time.IllegalInstantException; //导入依赖的package包/类
/**
* 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);
}
示例2: toJodaDateTime
import org.joda.time.IllegalInstantException; //导入依赖的package包/类
/**
* 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: localToUTC
import org.joda.time.IllegalInstantException; //导入依赖的package包/类
/**
* @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: set
import org.joda.time.IllegalInstantException; //导入依赖的package包/类
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: updateEndTimeAsia
import org.joda.time.IllegalInstantException; //导入依赖的package包/类
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);
}
示例6: computeMillis
import org.joda.time.IllegalInstantException; //导入依赖的package包/类
/**
* 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;
}