use of java.time.format.DateTimeParseException in project knime-core by knime.
the class DialogComponentDateTimeSelection method updateSpinnerFormat.
/**
* Allows the user to determine by himself whether milliseconds shall be used or not. Checks if the text in the text
* field of the time spinner contains milliseconds or not and updates the format of the spinner editor accordingly.
*/
private void updateSpinnerFormat() {
final JFormattedTextField field = (JFormattedTextField) m_editor.getComponent(0);
try {
DateTimeFormatter.ofPattern(TIME_FORMAT_WITH_MS).parse(field.getText());
if (!m_useMillis) {
setUseMillis(true);
((DateFormatter) m_editor.getTextField().getFormatter()).setFormat(new SimpleDateFormat(TIME_FORMAT_WITH_MS, Locale.getDefault()));
updateModel();
}
} catch (final DateTimeParseException iae) {
try {
DateTimeFormatter.ofPattern(TIME_FORMAT_WITHOUT_MS).parse(field.getText());
if (m_useMillis) {
setUseMillis(false);
((DateFormatter) m_editor.getTextField().getFormatter()).setFormat(new SimpleDateFormat(TIME_FORMAT_WITHOUT_MS, Locale.getDefault()));
updateModel();
}
} catch (final DateTimeParseException iae2) {
}
}
}
use of java.time.format.DateTimeParseException in project grakn by graknlabs.
the class DateMacro method convertDateFormat.
private String convertDateFormat(String originalDate, String originalFormat) {
originalFormat = removeQuotes(originalFormat);
try {
DateTimeFormatter formatter = DateTimeFormatter.ofPattern(originalFormat);
TemporalAccessor parsedDate = formatter.parseBest(originalDate, LocalDateTime::from, LocalDate::from, LocalTime::from);
return extractLocalDateTime(parsedDate).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
} catch (IllegalArgumentException e) {
throw GraqlQueryException.cannotParseDateFormat(originalFormat);
} catch (DateTimeParseException e) {
throw GraqlQueryException.cannotParseDateString(originalDate, originalFormat, e);
}
}
use of java.time.format.DateTimeParseException in project cxf by apache.
the class DefaultConditionsProvider method getConditions.
/**
* Get a ConditionsBean object.
*/
public ConditionsBean getConditions(TokenProviderParameters providerParameters) {
ConditionsBean conditions = new ConditionsBean();
Lifetime tokenLifetime = providerParameters.getTokenRequirements().getLifetime();
if (lifetime > 0) {
if (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());
}
conditions.setNotAfter(expirationTime);
conditions.setNotBefore(creationTime);
} else {
conditions.setTokenPeriodSeconds(lifetime);
}
} else {
conditions.setTokenPeriodMinutes(5);
}
List<AudienceRestrictionBean> audienceRestrictions = createAudienceRestrictions(providerParameters);
if (audienceRestrictions != null && !audienceRestrictions.isEmpty()) {
conditions.setAudienceRestrictions(audienceRestrictions);
}
return conditions;
}
use of java.time.format.DateTimeParseException in project cxf by apache.
the class SecurityToken method processLifeTime.
/**
* @param lifetimeElem
* @throws TrustException
*/
private void processLifeTime(Element lifetimeElem) {
try {
Element createdElem = DOMUtils.getFirstChildWithName(lifetimeElem, WSS4JConstants.WSU_NS, WSS4JConstants.CREATED_LN);
this.created = ZonedDateTime.parse(DOMUtils.getContent(createdElem)).toInstant();
Element expiresElem = DOMUtils.getFirstChildWithName(lifetimeElem, WSS4JConstants.WSU_NS, WSS4JConstants.EXPIRES_LN);
this.expires = ZonedDateTime.parse(DOMUtils.getContent(expiresElem)).toInstant();
} catch (DateTimeParseException e) {
// shouldn't happen
}
}
use of java.time.format.DateTimeParseException in project quickstart by wildfly.
the class DateService method showDaysUntil.
@GET
@Path("daysuntil/{targetdate}")
@Produces(MediaType.TEXT_PLAIN)
public long showDaysUntil(@PathParam("targetdate") String targetDate) {
DateLogger.LOGGER.logDaysUntilRequest(targetDate);
final long days;
try {
final LocalDate date = LocalDate.parse(targetDate, DateTimeFormatter.ISO_DATE);
days = ChronoUnit.DAYS.between(LocalDate.now(), date);
} catch (DateTimeParseException ex) {
// ** DISCLAIMER **
// This example is contrived and overly verbose for the purposes of showing the
// different logging methods. It's generally not recommended to recreate exceptions
// or log exceptions that are being thrown.
// create localized ParseException using method from bundle with details from ex
DateTimeParseException nex = DateExceptionsBundle.EXCEPTIONS.targetDateStringDidntParse(targetDate, ex.getParsedString(), ex.getErrorIndex());
// log a message using nex as the cause
DateLogger.LOGGER.logStringCouldntParseAsDate(targetDate, nex);
// throw a WebApplicationException (400) with the localized message from nex
throw new WebApplicationException(Response.status(400).entity(nex.getLocalizedMessage()).type(MediaType.TEXT_PLAIN).build());
}
return days;
}
Aggregations