Example usage for org.joda.time ReadableInstant isBefore

List of usage examples for org.joda.time ReadableInstant isBefore

Introduction

In this page you can find the example usage for org.joda.time ReadableInstant isBefore.

Prototype

boolean isBefore(ReadableInstant instant);

Source Link

Document

Is this instant before the instant passed in comparing solely by millisecond.

Usage

From source file:com.alliander.osgp.domain.core.validation.joda.PastValidator.java

License:Open Source License

@Override
public boolean isValid(final ReadableInstant value, final ConstraintValidatorContext context) {
    if (value == null) {
        return true;
    }/*from  ww  w .  j  a  v  a2s  . c om*/

    final DateMidnight checkDate = new DateMidnight(DateTimeZone.UTC);

    return value.isEqual(checkDate) || value.isBefore(checkDate);
}

From source file:com.robwilliamson.healthyesther.util.time.Range.java

License:Open Source License

@Override
public boolean contains(ReadableInstant instant, Comparison comparison) {
    if (instant.isAfter(from) && instant.isBefore(to)) {
        return true;
    }//w w  w. j  ava 2s  . c  o  m

    if (comparison == Comparison.EXCLUSIVE) {
        return false;
    }

    return instant.isEqual(from) || instant.isEqual(to);
}

From source file:de.gmorling.moapa.joda_bv_integration.PastValidatorForReadableInstant.java

License:Apache License

public boolean isValid(ReadableInstant value, ConstraintValidatorContext constraintValidatorContext) {

    if (value == null) {
        return true;
    }//w ww .ja  v  a 2s  .c  om

    return value.isBefore(new DateTime());
}

From source file:name.martingeisse.common.security.SecurityTokenUtil.java

License:Open Source License

/**
 * Validates the specified security token. Returns the subject if the token is valid.
 * Throws an {@link IllegalArgumentException} if invalid. This exception contains
 * an error message about the problem.//from   w  w  w . ja v  a  2  s  . c  om
 * 
 * @param token the token
 * @param minTimestamp the maximum allowed value for the token's timestamp
 * @param secret the secret used to generate the HMAC
 * @return the token's subject
 */
public static String validateToken(String token, ReadableInstant minTimestamp, String secret) {

    // split the token into segments
    String[] tokenSegments = StringUtils.split(token, '|');
    if (tokenSegments.length != 3) {
        throw new IllegalArgumentException("malformed token (has " + tokenSegments.length + " segments)");
    }

    // validate the signature
    String payload = (tokenSegments[0] + '|' + tokenSegments[1]);
    String expectedSignatureBase64 = HmacUtil.generateHmacBase64(payload, secret, HmacUtil.ALGORITHM_SHA256);
    if (!expectedSignatureBase64.equals(tokenSegments[2])) {
        throw new IllegalArgumentException("invalid token signature");
    }

    // validate the timestamp
    ReadableInstant timestamp;
    try {
        timestamp = dateTimeFormatter.parseDateTime(tokenSegments[1]);
    } catch (IllegalArgumentException e) {
        throw new IllegalArgumentException("malformed timestamp: " + e.getMessage());
    }
    if (timestamp.isBefore(minTimestamp)) {
        throw new IllegalArgumentException("token has expired");
    }

    // return the subject
    return tokenSegments[0];

}

From source file:net.ripe.rpki.commons.crypto.ValidityPeriod.java

License:BSD License

public boolean isValidAt(ReadableInstant instant) {
    if (instant == null) {
        return !isClosed();
    } else {/*from  w  w w.  j  av  a2s.  com*/
        return (notValidBefore == null || !instant.isBefore(getNotValidBefore()))
                && (notValidAfter == null || !instant.isAfter(getNotValidAfter()));
    }
}

From source file:org.apereo.portal.events.aggr.EventDateTimeUtils.java

License:Apache License

/**
 * Determines if an instant is between a start (inclusive) and end (exclusive).
 *
 * @param start start of range (inclusive)
 * @param end end of range (exclusive)/*w  w  w. j av  a  2s.c om*/
 * @param instant instant
 * @return Returns 0 if the instant is contained in the range: (getStart() <= instant <
 *     getEnd()) Returns -1 if the range comes before the instant: (getEnd() <= instant) Returns
 *     1 if the range comes after the instant (instant < getStart())
 * @see Comparable#compareTo(Object)
 */
public static int compareTo(ReadableInstant start, ReadableInstant end, ReadableInstant instant) {
    if (instant.isBefore(start)) {
        return 1;
    }

    if (end.isAfter(instant)) {
        return 0;
    }

    return -1;
}

From source file:org.hibernate.validator.constraints.impl.PastValidatorForReadableInstant.java

License:Apache License

public boolean isValid(ReadableInstant value, ConstraintValidatorContext context) {
    //null values are valid
    if (value == null) {
        return true;
    }/*w  w  w  .  j ava 2  s .  c om*/

    return value.isBefore(null);
}

From source file:org.springmodules.validation.util.condition.date.jodatime.IsInThePastInstantCondition.java

License:Apache License

/**
 * Checks whether the given instant is in the past.
 *
 * @param instant The instant to be checked.
 * @return <code>true</code> if the given instant is in the past, <code>false</code> otehrwise.
 *///w  w  w  .  j av a2  s  .c  o m
protected boolean checkInstant(ReadableInstant instant) {
    return instant.isBefore(new DateTime());
}