public class IllegalInstantException
extends java.lang.IllegalArgumentException
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.
Modifier and Type | Field and Description |
---|---|
private static long |
serialVersionUID
Serialization lock.
|
Constructor and Description |
---|
IllegalInstantException(long instantLocal,
java.lang.String zoneId)
Constructor.
|
IllegalInstantException(java.lang.String message)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
private static java.lang.String |
createMessage(long instantLocal,
java.lang.String zoneId) |
static boolean |
isIllegalInstant(java.lang.Throwable ex)
Checks if the exception is, or has a cause, of
IllegalInstantException . |
private static final long serialVersionUID
public IllegalInstantException(java.lang.String message)
message
- the messagepublic IllegalInstantException(long instantLocal, java.lang.String zoneId)
instantLocal
- the local instantzoneId
- the time-zone ID, may be nullprivate static java.lang.String createMessage(long instantLocal, java.lang.String zoneId)
public static boolean isIllegalInstant(java.lang.Throwable ex)
IllegalInstantException
.ex
- the exception to checkIllegalInstantException