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);
}
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));
}
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);
}
}
}
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);
}
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());
}
}
Aggregations