org.joda.time
Class IllegalInstantException

java.lang.Object
  extended by java.lang.Throwable
      extended by java.lang.Exception
          extended by java.lang.RuntimeException
              extended by java.lang.IllegalArgumentException
                  extended by org.joda.time.IllegalInstantException
All Implemented Interfaces:
Serializable

public class IllegalInstantException
extends IllegalArgumentException

Exception thrown when attempting to create an instant or date-time that cannot exist.

Classes like DateTime only store valid date-times. One of the cases where validity is important is handling daylight savings time (DST). In many places DST is used, where the local clock moves forward by an hour in spring and back by an hour in autumn/fall. This means that in spring, there is a "gap" where a local time does not exist.

This exception refers to this gap, and it means that your application tried to create a date-time inside the gap - a time that did not exist. Since Joda-Time objects must be valid, this is not allowed.

Possible solutions may be as follows:
Use LocalDateTime, as all local date-times are valid.
When converting a LocalDate to a DateTime, then use toDateTimeAsStartOfDay() as this handles and manages any gaps.
When parsing, use parseLocalDateTime() if the string being parsed has no time-zone.

Since:
2.2
Author:
Stephen Colebourne
See Also:
Serialized Form

Constructor Summary
IllegalInstantException(long instantLocal, String zoneId)
          Constructor.
IllegalInstantException(String message)
          Constructor.
 
Method Summary
static boolean isIllegalInstant(Throwable ex)
          Checks if the exception is, or has a cause, of IllegalInstantException.
 
Methods inherited from class java.lang.Throwable
fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

IllegalInstantException

public IllegalInstantException(String message)
Constructor.

Parameters:
message - the message

IllegalInstantException

public IllegalInstantException(long instantLocal,
                               String zoneId)
Constructor.

Parameters:
instantLocal - the local instant
zoneId - the time-zone ID, may be null
Method Detail

isIllegalInstant

public static boolean isIllegalInstant(Throwable ex)
Checks if the exception is, or has a cause, of IllegalInstantException.

Parameters:
ex - the exception to check
Returns:
true if an IllegalInstantException


Copyright © 2002-2013 Joda.org. All Rights Reserved.