Search in sources :

Example 41 with DateTimeParseException

use of java.time.format.DateTimeParseException in project fess by codelibs.

the class UserInfoBhv method toLocalDateTime.

@Override
protected LocalDateTime toLocalDateTime(final Object value) {
    if (value != null) {
        try {
            final Instant instant = Instant.from(DateTimeFormatter.ISO_INSTANT.parse(value.toString()));
            final LocalDateTime date = LocalDateTime.ofInstant(instant, ZoneId.systemDefault());
            return date;
        } catch (final DateTimeParseException e) {
            logger.debug("Invalid date format: " + value, e);
        }
    }
    return DfTypeUtil.toLocalDateTime(value);
}
Also used : LocalDateTime(java.time.LocalDateTime) DateTimeParseException(java.time.format.DateTimeParseException) Instant(java.time.Instant)

Example 42 with DateTimeParseException

use of java.time.format.DateTimeParseException in project hive by apache.

the class TimestampTZUtil method parse.

public static TimestampTZ parse(String s, ZoneId defaultTimeZone) {
    // need to handle offset with single digital hour, see JDK-8066806
    s = handleSingleDigitHourOffset(s);
    ZonedDateTime zonedDateTime;
    try {
        zonedDateTime = ZonedDateTime.parse(s, FORMATTER);
    } catch (DateTimeParseException e) {
        // try to be more tolerant
        // if the input is invalid instead of incomplete, we'll hit exception here again
        TemporalAccessor accessor = FORMATTER.parse(s);
        // LocalDate must be present
        LocalDate localDate = LocalDate.from(accessor);
        LocalTime localTime;
        ZoneId zoneId;
        try {
            localTime = LocalTime.from(accessor);
        } catch (DateTimeException e1) {
            localTime = DEFAULT_LOCAL_TIME;
        }
        try {
            zoneId = ZoneId.from(accessor);
        } catch (DateTimeException e2) {
            if (defaultTimeZone == null) {
                throw new DateTimeException("Time Zone not available");
            }
            zoneId = defaultTimeZone;
        }
        zonedDateTime = ZonedDateTime.of(localDate, localTime, zoneId);
    }
    if (defaultTimeZone == null) {
        return new TimestampTZ(zonedDateTime);
    }
    return new TimestampTZ(zonedDateTime.withZoneSameInstant(defaultTimeZone));
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) TemporalAccessor(java.time.temporal.TemporalAccessor) DateTimeException(java.time.DateTimeException) LocalTime(java.time.LocalTime) ZoneId(java.time.ZoneId) ZonedDateTime(java.time.ZonedDateTime) LocalDate(java.time.LocalDate)

Example 43 with DateTimeParseException

use of java.time.format.DateTimeParseException in project textdb by TextDB.

the class ComparableMatcher method compareDate.

private boolean compareDate(Tuple inputTuple) throws DataflowException {
    LocalDate date = inputTuple.getField(predicate.getAttributeName(), DateField.class).getValue();
    String compareToString = predicate.getCompareToValue().toString();
    // try to parse the input as date string first
    try {
        LocalDate compareToDate = LocalDate.parse(compareToString);
        return compareValues(date, compareToDate, predicate.getComparisonType());
    } catch (DateTimeParseException e) {
        // if it fails, then try to parse as date time string
        try {
            LocalDateTime compareToDateTime = LocalDateTime.parse(compareToString);
            return compareValues(date, compareToDateTime.toLocalDate(), predicate.getComparisonType());
        } catch (DateTimeParseException e2) {
            throw new DataflowException("Unable to parse date or time: " + compareToString);
        }
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) DateTimeParseException(java.time.format.DateTimeParseException) DataflowException(edu.uci.ics.texera.api.exception.DataflowException) DateField(edu.uci.ics.texera.api.field.DateField) LocalDate(java.time.LocalDate)

Example 44 with DateTimeParseException

use of java.time.format.DateTimeParseException in project cayenne by apache.

the class Artist method setDateOfBirthString.

/**
 * Sets date of birth using a string in format yyyyMMdd.
 */
public void setDateOfBirthString(String yearMonthDay) {
    if (yearMonthDay == null) {
        setDateOfBirth(null);
        return;
    }
    LocalDate date;
    try {
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DEFAULT_DATE_FORMAT);
        date = LocalDate.parse(yearMonthDay, formatter);
    } catch (DateTimeParseException e) {
        throw new IllegalArgumentException("A date argument must be in format '" + DEFAULT_DATE_FORMAT + "': " + yearMonthDay);
    }
    setDateOfBirth(date);
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 45 with DateTimeParseException

use of java.time.format.DateTimeParseException in project cxf by apache.

the class DefaultJWTClaimsProvider method handleConditions.

protected void handleConditions(JWTClaimsProviderParameters jwtClaimsProviderParameters, JwtClaims claims) {
    TokenProviderParameters providerParameters = jwtClaimsProviderParameters.getProviderParameters();
    Instant currentDate = Instant.now();
    long currentTime = currentDate.getEpochSecond();
    // Set the defaults first
    claims.setIssuedAt(currentTime);
    claims.setNotBefore(currentTime);
    claims.setExpiryTime(currentTime + lifetime);
    Lifetime tokenLifetime = providerParameters.getTokenRequirements().getLifetime();
    if (lifetime > 0 && acceptClientLifetime && tokenLifetime != null && tokenLifetime.getCreated() != null && tokenLifetime.getExpires() != null) {
        Instant creationTime = null;
        Instant expirationTime = null;
        try {
            creationTime = ZonedDateTime.parse(tokenLifetime.getCreated()).toInstant();
            expirationTime = ZonedDateTime.parse(tokenLifetime.getExpires()).toInstant();
        } catch (DateTimeParseException ex) {
            LOG.fine("Error in parsing Timestamp Created or Expiration Strings");
            throw new STSException("Error in parsing Timestamp Created or Expiration Strings", STSException.INVALID_TIME);
        }
        // Check to see if the created time is in the future
        Instant validCreation = Instant.now();
        if (futureTimeToLive > 0) {
            validCreation = validCreation.plusSeconds(futureTimeToLive);
        }
        if (creationTime.isAfter(validCreation)) {
            LOG.fine("The Created Time is too far in the future");
            throw new STSException("The Created Time is too far in the future", STSException.INVALID_TIME);
        }
        long requestedLifetime = Duration.between(creationTime, expirationTime).getSeconds();
        if (requestedLifetime > getMaxLifetime()) {
            StringBuilder sb = new StringBuilder();
            sb.append("Requested lifetime [").append(requestedLifetime);
            sb.append(" sec] exceed configured maximum lifetime [").append(getMaxLifetime());
            sb.append(" sec]");
            LOG.warning(sb.toString());
            if (isFailLifetimeExceedance()) {
                throw new STSException("Requested lifetime exceeds maximum lifetime", STSException.INVALID_TIME);
            }
            expirationTime = creationTime.plusSeconds(getMaxLifetime());
        }
        long creationTimeInSeconds = creationTime.getEpochSecond();
        claims.setIssuedAt(creationTimeInSeconds);
        claims.setNotBefore(creationTimeInSeconds);
        claims.setExpiryTime(expirationTime.getEpochSecond());
    }
}
Also used : DateTimeParseException(java.time.format.DateTimeParseException) Lifetime(org.apache.cxf.sts.request.Lifetime) Instant(java.time.Instant) STSException(org.apache.cxf.ws.security.sts.provider.STSException) TokenProviderParameters(org.apache.cxf.sts.token.provider.TokenProviderParameters)

Aggregations

DateTimeParseException (java.time.format.DateTimeParseException)51 DateTimeFormatter (java.time.format.DateTimeFormatter)17 LocalDate (java.time.LocalDate)15 Test (org.testng.annotations.Test)14 TemporalAccessor (java.time.temporal.TemporalAccessor)13 LocalDateTime (java.time.LocalDateTime)11 DateTimeFormatterBuilder (java.time.format.DateTimeFormatterBuilder)10 Instant (java.time.Instant)7 Duration (java.time.Duration)5 ZonedDateTime (java.time.ZonedDateTime)5 SettingsModelString (org.knime.core.node.defaultnodesettings.SettingsModelString)5 Period (java.time.Period)4 LocalTime (java.time.LocalTime)3 InvalidSettingsException (org.knime.core.node.InvalidSettingsException)3 DataflowException (edu.uci.ics.texera.api.exception.DataflowException)2 ParseException (java.text.ParseException)2 DateTimeException (java.time.DateTimeException)2 ZoneId (java.time.ZoneId)2 ResolverStyle (java.time.format.ResolverStyle)2 Temporal (java.time.temporal.Temporal)2