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; }
/** * Constructor. * * @param instantLocal the local instant * @param zoneId the time-zone ID, may be null */ public IllegalInstantException(long instantLocal, String zoneId) { super(createMessage(instantLocal, zoneId)); }
/** * Checks if the exception is, or has a cause, of {@code IllegalInstantException}. * * @param ex the exception to check * @return true if an {@code IllegalInstantException} */ public static boolean isIllegalInstant(Throwable ex) { if (ex instanceof IllegalInstantException) { return true; } while (ex.getCause() != null && ex.getCause() != ex) { return isIllegalInstant(ex.getCause()); } return false; }
/** * @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) { if (localInstant == Long.MAX_VALUE) { return Long.MAX_VALUE; } else if (localInstant == Long.MIN_VALUE) { return Long.MIN_VALUE; } DateTimeZone zone = getZone(); int offset = zone.getOffsetFromLocal(localInstant); long utcInstant = localInstant - offset; if (localInstant > NEAR_ZERO && utcInstant < 0) { return Long.MAX_VALUE; } else if (localInstant < -NEAR_ZERO && utcInstant > 0) { return Long.MIN_VALUE; } int offsetBasedOnUtc = zone.getOffset(utcInstant); if (offset != offsetBasedOnUtc) { throw new IllegalInstantException(localInstant, zone.getID()); } return utcInstant; }
/** * @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) { if (localInstant == Long.MAX_VALUE) { return Long.MAX_VALUE; } else if (localInstant == Long.MIN_VALUE) { return Long.MIN_VALUE; } DateTimeZone zone = getZone(); int offset = zone.getOffsetFromLocal(localInstant); long utcInstant = localInstant - offset; if (localInstant > NEAR_ZERO && utcInstant < 0) { return Long.MAX_VALUE; } else if (localInstant < -NEAR_ZERO && utcInstant > 0) { return Long.MIN_VALUE; } int offsetBasedOnUtc = zone.getOffset(utcInstant); if (offset != offsetBasedOnUtc) { throw new IllegalInstantException(localInstant, zone.getID()); } return utcInstant; }
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; }
throw new IllegalInstantException(instantLocal, getID()); } else {
/** * Checks if the exception is, or has a cause, of {@code IllegalInstantException}. * * @param ex the exception to check * @return true if an {@code IllegalInstantException} */ public static boolean isIllegalInstant(Throwable ex) { if (ex instanceof IllegalInstantException) { return true; } while (ex.getCause() != null && ex.getCause() != ex) { return isIllegalInstant(ex.getCause()); } return false; }
/** * Constructor. * * @param instantLocal the local instant * @param zoneId the time-zone ID, may be null */ public IllegalInstantException(long instantLocal, String zoneId) { super(createMessage(instantLocal, zoneId)); }
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; }
throw new IllegalInstantException(instantLocal, getID()); } else {
/** * Returns a new DateTime with this field set to the minimum value * for this field. * <p> * Where possible, the offset from UTC will be retained, thus applications * may need to call {@link DateTime#withEarlierOffsetAtOverlap()} on the result * to force the earlier time during a DST overlap if desired. * <p> * From v2.2, this method handles a daylight savings time gap, setting the * time to the first instant after the gap. * <p> * The DateTime attached to this property is unchanged by this call. * * @return a copy of the DateTime with this field set to its minimum * @since 1.2 */ public DateTime withMinimumValue() { try { return setCopy(getMinimumValue()); } catch (RuntimeException ex) { if (IllegalInstantException.isIllegalInstant(ex)) { // subtracting MILLIS_PER_DAY is not perfect, but will work in almost all situations long afterGap = getChronology().getZone().nextTransition(getMillis() - DateTimeConstants.MILLIS_PER_DAY); return new DateTime(afterGap, getChronology()); } throw ex; } }
/** * Constructor. * * @param instantLocal the local instant * @param zoneId the time-zone ID, may be null */ public IllegalInstantException(long instantLocal, String zoneId) { super(createMessage(instantLocal, zoneId)); }
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; }
message = "Cannot parse \"" + text + "\": " + message; throw new IllegalInstantException(message);
return setCopy(getMaximumValue()); } catch (RuntimeException ex) { if (IllegalInstantException.isIllegalInstant(ex)) {
/** * Constructor. * * @param instantLocal the local instant * @param zoneId the time-zone ID, may be null */ public IllegalInstantException(long instantLocal, String zoneId) { super(createMessage(instantLocal, zoneId)); }
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; }
message = "Cannot parse \"" + text + "\": " + message; throw new IllegalInstantException(message);
/** * Returns a new DateTime with this field set to the minimum value * for this field. * <p> * Where possible, the offset from UTC will be retained, thus applications * may need to call {@link DateTime#withEarlierOffsetAtOverlap()} on the result * to force the earlier time during a DST overlap if desired. * <p> * From v2.2, this method handles a daylight savings time gap, setting the * time to the first instant after the gap. * <p> * The DateTime attached to this property is unchanged by this call. * * @return a copy of the DateTime with this field set to its minimum * @since 1.2 */ public DateTime withMinimumValue() { try { return setCopy(getMinimumValue()); } catch (RuntimeException ex) { if (IllegalInstantException.isIllegalInstant(ex)) { // subtracting MILLIS_PER_DAY is not perfect, but will work in almost all situations long afterGap = getChronology().getZone().nextTransition(getMillis() - DateTimeConstants.MILLIS_PER_DAY); return new DateTime(afterGap, getChronology()); } throw ex; } }